diff --git a/plugins/AlltimeStats/__init__.py b/plugins/AlltimeStats/__init__.py deleted file mode 100644 index 5228880ef..000000000 --- a/plugins/AlltimeStats/__init__.py +++ /dev/null @@ -1,140 +0,0 @@ -# Copyright (C) 2007 - Micah Bucy -# -# 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, 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - -### Initialization ### - -plugin_name = _("Alltime Stats") -plugin_author = "Micah Bucy" -plugin_version = "0.1" -plugin_description = _(""" -Shows alltime stats in the tray tooltip. -Tracks transfer amounts, ratio, number of torrents finished, and uptime. -Also show session uptime -""") - -def deluge_init(deluge_path): - global path - path = deluge_path - -def enable(core, interface): - global path - return AlltimeStats(path, core, interface) - -### The Plugin ### -import gtk -import os -import time - -import deluge -from deluge import common - -class AlltimeStats: - - def __init__(self, path, core, interface): - print "Loading AlltimeStats plugin..." - self.manager = core - self.statsdir = os.path.join(common.CONFIG_DIR, 'alltime_stats') - self.tray_message = "" - self.downloaded = None - self.uploaded = None - self.ratio = None - self.finished = None - self.uptime = None - self.start_time = long(time.time()) - self.prepare_stats() - self.manager.connect_event(self.manager.constants['EVENT_FINISHED'], self.handle_event) - - def stats_clicked(self, src): - self.window.show_all() - - def close(self, widget, event): - self.window.hide() - - def prepare_stats(self): - if not os.path.isdir(self.statsdir): - os.mkdir(self.statsdir) - if not os.path.isdir(self.statsdir): - os.mkdir(self.statsdir) - stats_state = os.path.join(self.statsdir, "stats.state") - try: - stats_file = open(stats_state, "r") - except: - self.downloaded = 0 - self.uploaded = 0 - self.finished = 0 - for unique_id in self.manager.unique_IDs.keys(): - self.uploaded += long(self.manager.unique_IDs[unique_id].uploaded_memory) - state = self.manager.get_torrent_state(unique_id) - self.downloaded += long(state["total_done"]) - if state['is_seed']: - self.finished += 1 - self.uptime = 0 - else: - readlines = stats_file.readlines() - self.downloaded = long(readlines[0]) - self.uploaded = long(readlines[1]) - self.finished = int(readlines[2]) - self.uptime = long(readlines[3]) - stats_file.close() - if self.downloaded == 0: - ratio = _("Undefined") - else: - ratio = "%.3f" % float(float(self.uploaded)/float(self.downloaded)) - self.tray_message = '%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s' % ( - _("Uptime"), common.ftime(0), - _("All-time Downloaded"), common.fsize(self.downloaded), - _("All-time Uploaded"), common.fsize(self.uploaded), - _("All-time Ratio"), ratio, - _("Torrents completed"), str(self.finished), - _("All-time Uptime"), common.ftime(self.uptime)) - - def get_tray_message(self): - return self.tray_message - - def unload(self): - state = self.manager.get_state() - downloaded = long(state['total_downloaded']) + self.downloaded - uploaded = long(state['total_uploaded']) + self.uploaded - uptime = long(time.time()) - self.start_time + self.uptime - stats_state = os.path.join(self.statsdir, "stats.state") - stats_file = open(stats_state, "w") - stats_file.writelines([str(downloaded)+'\n',\ - str(uploaded)+'\n', str(self.finished)+'\n', str(uptime)+'\n']) - stats_file.close() - self.manager.disconnect_event(self.manager.constants['EVENT_FINISHED'], self.handle_event) - - def handle_event(self, event): - if event['message'] == "torrent has finished downloading": - self.finished += 1 - self.update() - - def update(self): - state = self.manager.get_state() - downloaded = long(state['total_downloaded']) + self.downloaded - uploaded = long(state['total_uploaded']) + self.uploaded - ses_uptime = long(time.time()) - self.start_time - uptime = ses_uptime + self.uptime - if downloaded == 0: - ratio = _("Undefined") - else: - ratio = "%.3f" % float(float(uploaded)/float(downloaded)) - self.tray_message = '%s: %s\n\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s' % ( - _("Uptime"), common.ftime(ses_uptime), - _("All-time Downloaded"), common.fsize(downloaded), - _("All-time Uploaded"), common.fsize(uploaded), - _("All-time Ratio"), ratio, - _("Torrents completed"), str(self.finished), - _("All-time Uptime"), common.ftime(uptime)) diff --git a/plugins/ExtraStats/__init__.py b/plugins/ExtraStats/__init__.py new file mode 100644 index 000000000..ae6829ea0 --- /dev/null +++ b/plugins/ExtraStats/__init__.py @@ -0,0 +1,321 @@ +# Copyright (C) 2007 - Micah Bucy +# +# 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, 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + +### Initialization ### + +plugin_name = _("Extra Stats") +plugin_author = "Micah Bucy" +plugin_version = "0.1" +plugin_description = _(""" +Adds info to tray tooltip. +Adds these stats. +total bytes downloaded +total bytes uploaded +overall ratio +torrents completed + +All of these stats come in pairs: +across sessions stat and within session stat. +By default, all pairs enabled, but can be disabled in plugin preferences. + +session data always shows up within parenthesis +eg. Total Downloaded: 5 GiB (4 MiB) +would be 5 GiB across sessions and 4 MiB within session +""") + +def deluge_init(deluge_path): + global path + path = deluge_path + +def enable(core, interface): + global path + return ExtraStats(path, core, interface) + +### The Plugin ### +import gtk +import os +import time + +import deluge +from deluge import common + +class ExtraStats: + + def __init__(self, path, core, interface): + print "Loading ExtraStats plugin..." + self.manager = core + # Create an options file and try to load existing Values + self.config_file = deluge.common.CONFIG_DIR + "/extra_stats.conf" + self.config = deluge.pref.Preferences(self.config_file, False) + try: + self.config.load() + except IOError: + # File does not exist + pass + self.glade = gtk.glade.XML(path + "/stats_preferences.glade") + self.dialog = self.glade.get_widget("dialog") + self.dialog.set_position(gtk.WIN_POS_CENTER) + self.glade.signal_autoconnect({ + 'on_button_cancel_clicked': self.cancel_clicked, + 'on_button_ok_clicked': self.ok_clicked + }) + self.statsdir = os.path.join(common.CONFIG_DIR, 'alltime_stats') + self.tray_message = "" + self.all_downloaded = None + self.all_uploaded = None + self.all_finished = None + self.all_running_time = None + self.finished = 0 + self.start_time = long(time.time()) + self.prepare_stats() + self.manager.connect_event(self.manager.constants['EVENT_FINISHED'], self.handle_event) + + def prepare_stats(self): + if not os.path.isdir(self.statsdir): + os.mkdir(self.statsdir) + if not os.path.isdir(self.statsdir): + os.mkdir(self.statsdir) + stats_state = os.path.join(self.statsdir, "stats.state") + try: + stats_file = open(stats_state, "r") + except: + self.all_downloaded = 0 + self.all_uploaded = 0 + self.all_finished = 0 + for unique_id in self.manager.unique_IDs.keys(): + self.all_uploaded += long(self.manager.unique_IDs[unique_id].uploaded_memory) + state = self.manager.get_torrent_state(unique_id) + self.all_downloaded += long(state["total_done"]) + if state['is_seed']: + self.all_finished += 1 + self.all_running_time = 0 + else: + readlines = stats_file.readlines() + self.all_downloaded = long(readlines[0]) + self.all_uploaded = long(readlines[1]) + self.all_finished = int(readlines[2]) + self.all_running_time = long(readlines[3]) + stats_file.close() + + downloaded = "" + config = self.config.get("enable_downloaded") + if config is None: + self.config.set("enable_downloaded", True) + config = True + downloaded = "%s: %s (%s)\n" % ( + _("Total Downloaded"), + common.fsize(self.all_downloaded), + common.fsize(0)) + else: + if config : + downloaded = "%s: %s (%s)\n" % ( + _("Total Downloaded"), + common.fsize(self.all_downloaded), + common.fsize(0)) + + uploaded = "" + config = self.config.get("enable_uploaded") + if config is None: + config = True + self.config.set("enable_uploaded", True) + uploaded = "%s: %s (%s)\n" % ( + _("Total Uploaded"), + common.fsize(self.all_uploaded), + common.fsize(0)) + else: + if config: + uploaded = "%s: %s (%s)\n" % ( + _("Total Uploaded"), + common.fsize(self.all_uploaded), + common.fsize(0)) + + overall_ratio = "" + config = self.config.get("enable_ratio") + if config is None: + config = True + self.config.set("enable_ratio", True) + ratio = _("Undefined") + if self.all_downloaded == 0: + all_ratio = _("Undefined") + else: + all_ratio = "%.3f" % float(float(self.all_uploaded)/float(self.all_downloaded)) + overall_ratio = "%s: %s (%s)\n" % ( + _("Overall Ratio"), + all_ratio, + ratio) + else: + if config: + ratio = _("Undefined") + if self.all_downloaded == 0: + all_ratio = _("Undefined") + else: + all_ratio = "%.3f" % float(float(self.all_uploaded)/float(self.all_downloaded)) + overall_ratio = "%s: %s (%s)\n" % ( + _("Overall Ratio"), + all_ratio, + ratio) + + finished = "" + config = self.config.get("enable_finished") + if config is None: + config = True + self.config.set("enable_finished", True) + finished = "%s: %s (%s)\n" % ( + _("Torrents Completed"), + str(self.all_finished), + str(0)) + else: + if config: + finished = "%s: %s (%s)\n" % ( + _("Torrents Completed"), + str(self.all_finished), + str(0)) + + running_time = "" + config = self.config.get("enable_running_time") + if config is None: + config = True + self.config.set("enable_running_time", True) + running_time = "%s: %s (%s)\n" % ( + _("Running Time"), + common.ftime(self.all_running_time), + common.ftime(0)) + else: + if config: + running_time = "%s: %s (%s)\n" % ( + _("Running Time"), + common.ftime(self.all_running_time), + common.ftime(0)) + self.tray_message = downloaded + uploaded + overall_ratio + finished + running_time + + def configure(self, window): + try: + self.glade.get_widget("chk_downloaded").set_active(self.config.get("enable_downloaded")) + except: + self.glade.get_widget("chk_downloaded").set_active(True) + try: + self.glade.get_widget("chk_uploaded").set_active(self.config.get("enable_uploaded")) + except: + self.glade.get_widget("chk_uploaded").set_active(True) + try: + self.glade.get_widget("chk_ratio").set_active(self.config.get("enable_ratio")) + except: + self.glade.get_widget("chk_ratio").set_active(True) + try: + self.glade.get_widget("chk_finished").set_active(self.config.get("enable_finished")) + except: + self.glade.get_widget("chk_finished").set_active(True) + try: + self.glade.get_widget("chk_running_time").set_active(self.config.get("enable_running_time")) + except: + self.glade.get_widget("chk_running_time").set_active(True) + self.dialog.set_transient_for(window) + self.dialog.show() + + def get_tray_message(self): + return self.tray_message + + def unload(self): + state = self.manager.get_state() + downloaded = long(state['total_downloaded']) + self.all_downloaded + uploaded = long(state['total_uploaded']) + self.all_uploaded + running_time = long(time.time()) - self.start_time + self.all_running_time + stats_state = os.path.join(self.statsdir, "stats.state") + stats_file = open(stats_state, "w") + stats_file.writelines([str(downloaded)+'\n',\ + str(uploaded)+'\n', str(self.all_finished)+'\n', str(running_time)+'\n']) + stats_file.close() + self.manager.disconnect_event(self.manager.constants['EVENT_FINISHED'], self.handle_event) + self.config.save(self.config_file) + + def handle_event(self, event): + if event['message'] == "torrent has finished downloading": + self.finished += 1 + self.all_finished += 1 + self.update() + + def update(self): + state = self.manager.get_state() + ses_downloaded = long(state['total_downloaded']) + all_downloaded = ses_downloaded + self.all_downloaded + ses_uploaded = long(state['total_uploaded']) + all_uploaded = ses_uploaded + self.all_uploaded + ses_running_time = long(time.time()) - self.start_time + all_running_time = ses_running_time + self.all_running_time + + if ses_running_time%100 == 0: + # Store state approximately every 100 updates. + stats_state = os.path.join(self.statsdir, "stats.state") + stats_file = open(stats_state, "w") + stats_file.writelines([str(all_downloaded)+'\n',\ + str(all_uploaded)+'\n', str(self.all_finished)+'\n', str(all_running_time)+'\n']) + stats_file.close() + + downloaded = "" + if self.config.get("enable_downloaded"): + downloaded = "%s: %s (%s)\n" % ( + _("Total Downloaded"), + common.fsize(all_downloaded), + common.fsize(ses_downloaded)) + + uploaded = "" + if self.config.get("enable_uploaded"): + uploaded = "%s: %s (%s)\n" % ( + _("Total Uploaded"), + common.fsize(all_uploaded), + common.fsize(ses_uploaded)) + + overall_ratio = "" + if self.config.get("enable_ratio"): + if ses_downloaded == 0: + ses_ratio = _("Undefined") + else: + ses_ratio = "%.3f" % float(float(ses_uploaded)/float(ses_downloaded)) + if all_downloaded == 0: + all_ratio = _("Undefined") + else: + all_ratio = "%.3f" % float(float(all_uploaded)/float(all_downloaded)) + overall_ratio = "%s: %s (%s)\n" % ( + _("Overall Ratio"), + all_ratio, + ses_ratio) + + finished = "" + if self.config.get("enable_finished"): + finished = "%s: %s (%s)\n" % ( + _("Torrents Completed"), + str(self.all_finished), + str(self.finished)) + + running_time = "" + if self.config.get("enable_running_time"): + finished = "%s: %s (%s)\n" % ( + _("Running Time"), + common.ftime(all_running_time), + common.ftime(ses_running_time)) + + self.tray_message = downloaded + uploaded + overall_ratio + finished + running_time + + def ok_clicked(self, src): + self.dialog.hide() + self.config.set("enable_downloaded", self.glade.get_widget("chk_downloaded").get_active()) + self.config.set("enable_uploaded", self.glade.get_widget("chk_uploaded").get_active()) + self.config.set("enable_ratio", self.glade.get_widget("chk_ratio").get_active()) + self.config.set("enable_finished", self.glade.get_widget("chk_finished").get_active()) + self.config.set("enable_running_time", self.glade.get_widget("chk_running_time").get_active()) + + def cancel_clicked(self, src): + self.dialog.hide() diff --git a/plugins/ExtraStats/stats_preferences.glade b/plugins/ExtraStats/stats_preferences.glade new file mode 100644 index 000000000..91493f2c0 --- /dev/null +++ b/plugins/ExtraStats/stats_preferences.glade @@ -0,0 +1,132 @@ + + + + + + 5 + Extra Stats Preferences + 400 + 150 + GDK_WINDOW_TYPE_HINT_NORMAL + True + True + True + False + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK + 2 + + + True + 5 + + + True + True + Total Downloaded + True + 0 + True + + + + + True + True + Total Uploaded + True + 0 + True + + + 1 + 2 + + + + + True + True + Overall Ratio + True + 0 + True + + + 2 + 3 + + + + + True + True + Torrents Completed + True + 0 + True + + + 3 + 4 + + + + + True + True + Running Time + True + 0 + True + + + 4 + 5 + + + + + False + False + 1 + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK + GTK_BUTTONBOX_END + + + True + gtk-cancel + True + 0 + + + + + + True + gtk-ok + True + 1 + + + + 1 + + + + + False + GTK_PACK_END + + + + + + diff --git a/src/interface.py b/src/interface.py index f4ba7cd50..d5ccba718 100644 --- a/src/interface.py +++ b/src/interface.py @@ -973,8 +973,6 @@ class DelugeGTK: max_connections = int(self.config.get("max_connections_global")) dlspeed = common.fspeed(core_state['download_rate']) ulspeed = common.fspeed(core_state['upload_rate']) - dltotal = common.fsize(core_state['total_downloaded']) - ultotal = common.fsize(core_state['total_uploaded']) if self.config.get("max_download_speed") < 0: dlspeed_max = _("Unlimited") @@ -999,10 +997,9 @@ class DelugeGTK: self.statusbar_temp_msg = self.statusbar_temp_msg + \ ' [' + _("DHT") + ': %s]'%(dht_peers) - msg = '%s\n%s: %s (%s)\n%s: %s (%s)\n%s: %s\n%s: %s %s' % ( + msg = '%s\n%s: %s (%s)\n%s: %s (%s)%s' % ( _("Deluge Bittorrent Client"), _("Down Speed"), dlspeed, dlspeed_max, - _("Up Speed"), ulspeed, ulspeed_max, _("Total Downloaded"), dltotal, - _("Total Uploaded"), ultotal, plugin_messages) + _("Up Speed"), ulspeed, ulspeed_max, plugin_messages) self.tray_icon.set_tooltip(msg)