summaryrefslogtreecommitdiff
path: root/rapid/copyfiles.py
diff options
context:
space:
mode:
authorJulien Valroff <julien@kirya.net>2011-04-23 08:23:19 +0200
committerJulien Valroff <julien@kirya.net>2011-04-23 08:23:19 +0200
commit47f84e1a3d14ea9cab37d495b699d60ceed398f4 (patch)
tree2a928db277282ab55cb8e10935fe4691e3f16c05 /rapid/copyfiles.py
parent75b28642dd41fb4a7925b42cb24274de90a4f52c (diff)
Imported Upstream version 0.4.0~rc1upstream/0.4.0_rc1
Diffstat (limited to 'rapid/copyfiles.py')
-rw-r--r--rapid/copyfiles.py38
1 files changed, 20 insertions, 18 deletions
diff --git a/rapid/copyfiles.py b/rapid/copyfiles.py
index 08daafe..65a6c6d 100644
--- a/rapid/copyfiles.py
+++ b/rapid/copyfiles.py
@@ -38,7 +38,7 @@ from gettext import gettext as _
class CopyFiles(multiprocessing.Process):
def __init__(self, photo_download_folder, video_download_folder, files,
- generate_thumbnails, scan_pid,
+ scan_pid,
batch_size_MB, results_pipe, terminate_queue,
run_event):
multiprocessing.Process.__init__(self)
@@ -48,7 +48,6 @@ class CopyFiles(multiprocessing.Process):
self.photo_download_folder = photo_download_folder
self.video_download_folder = video_download_folder
self.files = files
- self.generate_thumbnails = generate_thumbnails
self.scan_pid = scan_pid
self.no_files= len(self.files)
self.run_event = run_event
@@ -71,15 +70,17 @@ class CopyFiles(multiprocessing.Process):
# it is - cancel the current copy
self.cancel_copy.cancel()
else:
- chunk_downloaded = amount_downloaded - self.bytes_downloaded
- if (chunk_downloaded > self.batch_size_bytes) or (amount_downloaded == total):
- self.bytes_downloaded = amount_downloaded
- if amount_downloaded == total:
- # this function is called a couple of times when total is reached
- chunk_downloaded = 0
- self.results_pipe.send((rpdmp.CONN_PARTIAL, (rpdmp.MSG_BYTES, (self.scan_pid, self.total_downloaded + amount_downloaded, chunk_downloaded))))
- if amount_downloaded == total:
- self.bytes_downloaded = 0
+ if not self.total_reached:
+ chunk_downloaded = amount_downloaded - self.bytes_downloaded
+ if (chunk_downloaded > self.batch_size_bytes) or (amount_downloaded == total):
+ self.bytes_downloaded = amount_downloaded
+ if amount_downloaded == total:
+ # this function is called a couple of times when total is reached
+ self.total_reached = True
+
+ self.results_pipe.send((rpdmp.CONN_PARTIAL, (rpdmp.MSG_BYTES, (self.scan_pid, self.total_downloaded + amount_downloaded, chunk_downloaded))))
+ if amount_downloaded == total:
+ self.bytes_downloaded = 0
def progress_callback(self, amount_downloaded, total):
self.update_progress(amount_downloaded, total)
@@ -105,11 +106,11 @@ class CopyFiles(multiprocessing.Process):
if self.photo_temp_dir or self.video_temp_dir:
- if self.generate_thumbnails:
- self.thumbnail_maker = tn.Thumbnail()
+ self.thumbnail_maker = tn.Thumbnail()
for i in range(len(self.files)):
rpd_file = self.files[i]
+ self.total_reached = False
# pause if instructed by the caller
self.run_event.wait()
@@ -151,20 +152,21 @@ class CopyFiles(multiprocessing.Process):
# succeeded or not. It's neccessary to keep the user informed.
self.total_downloaded += rpd_file.size
- if copy_succeeded and self.generate_thumbnails:
+ if copy_succeeded and rpd_file.generate_thumbnail:
thumbnail, thumbnail_icon = self.thumbnail_maker.get_thumbnail(
temp_full_file_name,
rpd_file.file_type,
(160, 120), (100,100))
- self.results_pipe.send((rpdmp.CONN_PARTIAL,
- (rpdmp.MSG_THUMB, (rpd_file.unique_id,
- thumbnail_icon, thumbnail))))
+ else:
+ thumbnail = None
+ thumbnail_icon = None
if rpd_file.metadata is not None:
rpd_file.metadata = None
self.results_pipe.send((rpdmp.CONN_PARTIAL, (rpdmp.MSG_FILE,
- (copy_succeeded, rpd_file, i + 1, temp_full_file_name))))
+ (copy_succeeded, rpd_file, i + 1, temp_full_file_name,
+ thumbnail_icon, thumbnail))))
self.results_pipe.send((rpdmp.CONN_COMPLETE, None))