remove extra stats as its causing too many errors

This commit is contained in:
Marcos Pinto 2008-01-22 00:53:20 +00:00
parent 74a1f60e42
commit 3946b03b83
2 changed files with 0 additions and 354 deletions

View File

@ -1,222 +0,0 @@
# Copyright (C) 2007 - Micah Bucy <eternalsword@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, 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 "Found ExtraStats plugin..."
self.manager = core
# Create an options file and try to load existing Values
self.config_file = os.path.join(deluge.common.CONFIG_DIR, "extra_stats.conf")
self.config = deluge.pref.Preferences(self.config_file, False,
{'enable_downloaded': True,
'enable_uploaded': True,
'enable_ratio': True,
'enable_finished': True,
'enable_running_time': True,
})
try:
self.config.load()
except IOError:
# File does not exist
pass
self.glade = gtk.glade.XML(os.path.join(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, 'extra_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()
def configure(self, window):
self.glade.get_widget("chk_downloaded").set_active(self.config.get("enable_downloaded"))
self.glade.get_widget("chk_uploaded").set_active(self.config.get("enable_uploaded"))
self.glade.get_widget("chk_ratio").set_active(self.config.get("enable_ratio"))
self.glade.get_widget("chk_finished").set_active(self.config.get("enable_finished"))
self.glade.get_widget("chk_running_time").set_active(self.config.get("enable_running_time"))
self.dialog.set_transient_for(window)
self.dialog.show()
def get_tray_message(self):
return self.tray_message
def unload(self):
self.save_stats_state(self.get_stats())
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 get_stats(self):
state = self.manager.get_state()
ses_downloaded = long(state['total_downloaded'])
ses_uploaded = long(state['total_uploaded'])
ses_running_time = long(time.time()) - self.start_time
all_downloaded = ses_downloaded + self.all_downloaded
all_uploaded = ses_uploaded + self.all_uploaded
all_running_time = ses_running_time + self.all_running_time
return (ses_downloaded, ses_uploaded, ses_running_time,
all_downloaded, all_uploaded, all_running_time)
def save_stats_state(self, stats_array):
all_downloaded, all_uploaded, all_running_time = stats_array[3:]
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()
def update(self):
stats_array = self.get_stats()
ses_downloaded, ses_uploaded, ses_running_time, \
all_downloaded, all_uploaded, all_running_time = stats_array
if ses_running_time%100 == 0:
# Store state approximately every 100 updates.
self.save_stats_state(stats_array)
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(ses_uploaded)/float(ses_downloaded))
if all_downloaded == 0:
all_ratio = _("Undefined")
else:
all_ratio = "%.3f" % (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"):
running_time = "%s: %s (%s)\n" % (
_("Running Time"), common.ftime(all_running_time),
common.ftime(ses_running_time))
# Copy to self.tray_message without last new line char
self.tray_message = (downloaded + uploaded + overall_ratio + \
finished + running_time)[:-1]
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()

View File

@ -1,132 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--*- mode: xml -*-->
<glade-interface>
<widget class="GtkDialog" id="dialog">
<property name="border_width">5</property>
<property name="title" translatable="yes">Extra Stats Preferences</property>
<property name="default_width">400</property>
<property name="default_height">150</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
<property name="destroy_with_parent">True</property>
<property name="skip_taskbar_hint">True</property>
<property name="skip_pager_hint">True</property>
<property name="has_separator">False</property>
<child internal-child="vbox">
<widget class="GtkVBox" id="dialog-vbox1">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK</property>
<property name="spacing">2</property>
<child>
<widget class="GtkTable" id="table1">
<property name="visible">True</property>
<property name="n_rows">5</property>
<child>
<widget class="GtkCheckButton" id="chk_downloaded">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Total Downloaded</property>
<property name="use_underline">True</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
</child>
<child>
<widget class="GtkCheckButton" id="chk_uploaded">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Total Uploaded</property>
<property name="use_underline">True</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="chk_ratio">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Overall Ratio</property>
<property name="use_underline">True</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="chk_finished">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Torrents Completed</property>
<property name="use_underline">True</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="chk_running_time">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Running Time</property>
<property name="use_underline">True</property>
<property name="response_id">0</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child internal-child="action_area">
<widget class="GtkHButtonBox" id="dialog-action_area1">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<child>
<widget class="GtkButton" id="button_cancel">
<property name="visible">True</property>
<property name="label">gtk-cancel</property>
<property name="use_stock">True</property>
<property name="response_id">0</property>
<signal name="clicked" handler="on_button_cancel_clicked"/>
</widget>
</child>
<child>
<widget class="GtkButton" id="button_ok">
<property name="visible">True</property>
<property name="label">gtk-ok</property>
<property name="use_stock">True</property>
<property name="response_id">1</property>
<signal name="clicked" handler="on_button_ok_clicked"/>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>