diff options
Diffstat (limited to 'rapid/downloadtracker.py')
-rw-r--r-- | rapid/downloadtracker.py | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/rapid/downloadtracker.py b/rapid/downloadtracker.py index 75c9c9d..824a812 100644 --- a/rapid/downloadtracker.py +++ b/rapid/downloadtracker.py @@ -18,6 +18,11 @@ ### Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import time + +import multiprocessing +import logging +logger = multiprocessing.get_logger() + from rpdfile import FILE_TYPE_PHOTO, FILE_TYPE_VIDEO from config import STATUS_DOWNLOAD_FAILED, STATUS_DOWNLOADED_WITH_WARNING, \ STATUS_DOWNLOAD_AND_BACKUP_FAILED, STATUS_BACKUP_PROBLEM @@ -59,6 +64,7 @@ class DownloadTracker: self.total_warnings = 0 self.total_bytes_to_download = 0 self.backups_performed_by_unique_id = dict() + self.auto_delete = dict() def set_no_backup_devices(self, no_backup_devices): self.no_backup_devices = no_backup_devices @@ -95,14 +101,31 @@ class DownloadTracker: def get_no_warnings(self, scan_pid): return self.warnings.get(scan_pid, 0) + + def add_to_auto_delete(self, rpd_file): + if rpd_file.scan_pid in self.auto_delete: + self.auto_delete[rpd_file.scan_pid].append(rpd_file.full_file_name) + else: + self.auto_delete[rpd_file.scan_pid] = [rpd_file.full_file_name,] + + def get_files_to_auto_delete(self, scan_pid): + return self.auto_delete[scan_pid] + + def clear_auto_delete(self, scan_pid): + if scan_pid in self.auto_delete: + del self.auto_delete[scan_pid] def file_backed_up(self, unique_id): self.backups_performed_by_unique_id[unique_id] = \ self.backups_performed_by_unique_id.get(unique_id, 0) + 1 def all_files_backed_up(self, unique_id): - v = self.backups_performed_by_unique_id[unique_id] == self.no_backup_devices - return v + if unique_id in self.backups_performed_by_unique_id: + return self.backups_performed_by_unique_id[unique_id] == self.no_backup_devices + else: + logger.critical("Unexpected unique_id in self.backups_performed_by_unique_id") + return True + def file_downloaded_increment(self, scan_pid, file_type, status): self.files_downloaded[scan_pid] += 1 @@ -125,8 +148,7 @@ class DownloadTracker: else: self.video_failures[scan_pid] += 1 self.total_video_failures += 1 - - + def get_percent_complete(self, scan_pid): """ Returns a float representing how much of the download |