diff options
author | Julien Valroff <julien@kirya.net> | 2011-04-08 07:09:54 +0200 |
---|---|---|
committer | Julien Valroff <julien@kirya.net> | 2011-04-08 07:09:54 +0200 |
commit | eb4c5cc4472b16ce10401611140381e5ba5b6aca (patch) | |
tree | 6e52c0a981186a09ab8161a6bc99a999f32ac408 /rapid/downloadtracker.py | |
parent | 6866d4a5b74779f087b8e44148a49163d8b7327b (diff) |
Imported Upstream version 0.4.0~alpha4upstream/0.4.0_alpha4
Diffstat (limited to 'rapid/downloadtracker.py')
-rw-r--r-- | rapid/downloadtracker.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/rapid/downloadtracker.py b/rapid/downloadtracker.py new file mode 100644 index 0000000..f2c80e2 --- /dev/null +++ b/rapid/downloadtracker.py @@ -0,0 +1,78 @@ +#!/usr/bin/python +# -*- coding: latin1 -*- + +### Copyright (C) 2011 Damon Lynch <damonlynch@gmail.com> + +### This program is free software; you can redistribute it and/or modify +### it under the terms of the GNU General Public License as published by +### the Free Software Foundation; either version 2 of the License, or +### (at your option) any later version. + +### This program is distributed in the hope that it will be useful, +### but WITHOUT ANY WARRANTY; without even the implied warranty of +### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +### GNU General Public License for more details. + +### You should have received a copy of the GNU General Public License +### along with this program; if not, write to the Free Software +### Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +class DownloadTracker: + def __init__(self): + self.size_of_download_in_bytes_by_scan_pid = dict() + self.total_bytes_copied_in_bytes_by_scan_pid = dict() + self.no_files_in_download_by_scan_pid = dict() + self.file_types_present_by_scan_pid = dict() + self.download_count_for_file_by_unique_id = dict() + self.download_count_by_scan_pid = dict() + self.rename_chunk = dict() + self.files_downloaded = dict() + + def init_stats(self, scan_pid, bytes, no_files): + self.no_files_in_download_by_scan_pid[scan_pid] = no_files + self.rename_chunk[scan_pid] = bytes / 10 / no_files + self.size_of_download_in_bytes_by_scan_pid[scan_pid] = bytes + self.rename_chunk[scan_pid] * no_files + self.files_downloaded[scan_pid] = 0 + + def get_no_files_in_download(self, scan_pid): + return self.no_files_in_download_by_scan_pid[scan_pid] + + def file_downloaded_increment(self, scan_pid): + self.files_downloaded[scan_pid] += 1 + + + def get_percent_complete(self, scan_pid): + """ + Returns a float representing how much of the download + has been completed + """ + + # three components: copy (download), rename, and backup + percent_complete = ((float( + self.total_bytes_copied_in_bytes_by_scan_pid[scan_pid]) + + self.rename_chunk[scan_pid] * self.files_downloaded[scan_pid]) + / self.size_of_download_in_bytes_by_scan_pid[scan_pid]) * 100 + return percent_complete + + def set_total_bytes_copied(self, scan_pid, total_bytes): + self.total_bytes_copied_in_bytes_by_scan_pid[scan_pid] = total_bytes + + def set_download_count_for_file(self, unique_id, download_count): + self.download_count_for_file_by_unique_id[unique_id] = download_count + + def get_download_count_for_file(self, unique_id): + return self.download_count_for_file_by_unique_id[unique_id] + + def set_download_count(self, scan_pid, download_count): + self.download_count_by_scan_pid[scan_pid] = download_count + + def get_file_types_present(self, scan_pid): + return self.file_types_present_by_scan_pid[scan_pid] + + def set_file_types_present(self, scan_pid, file_types_present): + self.file_types_present_by_scan_pid[scan_pid] = file_types_present + + def purge(self, scan_pid): + del self.no_files_in_download_by_scan_pid[scan_pid] + del self.size_of_download_in_bytes_by_scan_pid[scan_pid] + |