From 35ebf57060ba0fdd732a74226f2e9e73824f0c04 Mon Sep 17 00:00:00 2001 From: Martijn Voncken Date: Tue, 25 Nov 2008 19:28:25 +0000 Subject: [PATCH] get_stats+overhead --- deluge/core/core.py | 26 ++++++------------- deluge/tests/test_stats.py | 12 +++++++-- deluge/tests/test_statusbar.py | 17 ------------ deluge/ui/webui/render.py | 6 ++--- .../webui/templates/classic/part_stats.html | 7 ++--- .../ui/webui/templates/white/part_stats.html | 21 --------------- deluge/ui/webui/utils.py | 18 ------------- 7 files changed, 25 insertions(+), 82 deletions(-) delete mode 100644 deluge/tests/test_statusbar.py delete mode 100644 deluge/ui/webui/templates/white/part_stats.html diff --git a/deluge/core/core.py b/deluge/core/core.py index b838bd73f..73faac6aa 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -360,32 +360,22 @@ class Core( def export_get_stats(self): """ - returns: { - 'download_rate':float(), - 'upload_rate':float(), - 'num_connections':int(), - 'dht_nodes',int(), - 'free_space':long(), - 'has_incoming_connections':bool(), - 'max_num_connections':int(), - 'max_download':float(), - 'max_upload':float() - } + document me!!! """ - #todo: perf enhancedment:shortcut self.session.status() to a local var. - return { + stats = self.export_get_session_status(["payload_download_rate", "payload_upload_rate", + "dht_nodes", "has_incoming_connections", "download_rate", "upload_rate"]) + + stats.update({ #dynamic stats: - "download_rate":self.session.status().payload_download_rate, - "upload_rate":self.session.status().payload_upload_rate, "num_connections":self.session.num_connections(), - "dht_nodes":self.session.status().dht_nodes, "free_space":deluge.common.free_space(self.config["download_location"]), - "has_incoming_connections":self.session.status().has_incoming_connections, #max config values: "max_download":self.config["max_download_speed"], "max_upload":self.config["max_upload_speed"], "max_num_connections":self.config["max_connections_global"], - } + }) + + return stats def export_get_session_status(self, keys): diff --git a/deluge/tests/test_stats.py b/deluge/tests/test_stats.py index 97cb7fc64..cbb432b26 100644 --- a/deluge/tests/test_stats.py +++ b/deluge/tests/test_stats.py @@ -1,5 +1,13 @@ +# +# testing 123.. +# + from deluge.ui.client import sclient sclient.set_core_uri() +#/init + +print "no-args:" +stats = sclient.get_stats() +for key in sorted(stats.keys()): + print key, ":", stats[key] -for key, val in sclient.get_stats().iteritems(): - print "%s:%s" % (key,val) \ No newline at end of file diff --git a/deluge/tests/test_statusbar.py b/deluge/tests/test_statusbar.py deleted file mode 100644 index 02ce638f8..000000000 --- a/deluge/tests/test_statusbar.py +++ /dev/null @@ -1,17 +0,0 @@ -# -# moving and refactoring torrent-filtering from labels-plugin to core. -# - -from deluge.ui.client import sclient -sclient.set_core_uri() -#/init - -print "no-args:" -print sclient.get_statusbar() - -print "include-defaults:" -print sclient.get_statusbar(True) - -print "no-defaults:" -print sclient.get_statusbar(False) - diff --git a/deluge/ui/webui/render.py b/deluge/ui/webui/render.py index 784806918..ae7922dd8 100644 --- a/deluge/ui/webui/render.py +++ b/deluge/ui/webui/render.py @@ -150,9 +150,9 @@ def template_sort_head(id,name): def template_part_stats(): try: - return render.part_stats(get_stats()) - except Exception: - return '[not connected]' + return render.part_stats(Storage(sclient.get_stats())) + except Exception, e: + return str(e) def get_config(var): return config[var] diff --git a/deluge/ui/webui/templates/classic/part_stats.html b/deluge/ui/webui/templates/classic/part_stats.html index 5e1c40eff..65af97a2f 100644 --- a/deluge/ui/webui/templates/classic/part_stats.html +++ b/deluge/ui/webui/templates/classic/part_stats.html @@ -2,12 +2,13 @@ $def with (stats)
- $stats.num_connections ($deluge_int(stats.max_num_connections)) -$stats.download_rate ($deluge_int(stats.max_download)) +$fspeed(stats.payload_download_rate) ($deluge_int(stats.max_download)) -$stats.upload_rate ($deluge_int(stats.max_upload)) +$fspeed(stats.payload_upload_rate) ($deluge_int(stats.max_upload)) + +$fspeed(stats.download_rate - stats.payload_download_rate),$fspeed(stats.upload_rate - stats.payload_upload_rate) $stats.dht_nodes diff --git a/deluge/ui/webui/templates/white/part_stats.html b/deluge/ui/webui/templates/white/part_stats.html deleted file mode 100644 index 8cab5f7db..000000000 --- a/deluge/ui/webui/templates/white/part_stats.html +++ /dev/null @@ -1,21 +0,0 @@ -$def with (stats) - -
- - -$stats.num_connections ($deluge_int(stats.max_num_connections)) - -$stats.download_rate ($deluge_int(stats.max_download)) - -$stats.upload_rate ($deluge_int(stats.max_upload)) - -$stats.dht_nodes - -$fsize(stats.free_space) - -$if stats.has_incoming_connections: -$else: - - - -
diff --git a/deluge/ui/webui/utils.py b/deluge/ui/webui/utils.py index f93e4f800..ce754289c 100644 --- a/deluge/ui/webui/utils.py +++ b/deluge/ui/webui/utils.py @@ -107,24 +107,6 @@ def getcookie(key, default = None): ck = cookies() return ck.get(key, default) -def get_stats(): - stats = Storage(sclient.get_stats()) - - stats.download_rate = fspeed(stats.download_rate) - stats.upload_rate = fspeed(stats.upload_rate) - - if stats.max_upload < 0: - stats.max_upload = _("∞") - else: - stats.max_upload = "%s KiB/s" % stats.max_upload - - if stats.max_download < 0: - stats.max_download = _("∞") - else: - stats.max_download = "%s KiB/s" % stats.max_download - - return stats - def enhance_torrent_status(torrent_id, status): """ in: raw torrent_status