diff options
author | Julien Valroff <julien@kirya.net> | 2011-04-23 08:23:36 +0200 |
---|---|---|
committer | Julien Valroff <julien@kirya.net> | 2011-04-23 08:23:36 +0200 |
commit | d91bcffa7fd45c9c7ac28ba971c7cd831400ba99 (patch) | |
tree | d6aaaf1b57746d89835f256c64078749b3a13ef2 /rapid/copyfiles.py | |
parent | 09f315ca8b3bde0e17fc2bba88989e8929c0745c (diff) | |
parent | 47f84e1a3d14ea9cab37d495b699d60ceed398f4 (diff) |
Merge branch 'upstream' into experimental
Diffstat (limited to 'rapid/copyfiles.py')
-rw-r--r-- | rapid/copyfiles.py | 38 |
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)) |