Merge lp:~fresh13/dockmanager/deluge_helper into lp:dockmanager

Proposed by Igor Gevka
Status: Merged
Merged at revision: 94
Proposed branch: lp:~fresh13/dockmanager/deluge_helper
Merge into: lp:dockmanager
Diff against target: 164 lines (+77/-28)
2 files modified
metadata/deluge_badge.py.info (+1/-1)
scripts/deluge_badge.py (+76/-27)
To merge this branch: bzr merge lp:~fresh13/dockmanager/deluge_helper
Reviewer Review Type Date Requested Status
Dockers Pending
Review via email: mp+51229@code.launchpad.net

Commit message

Updated deluge helper to work with new deluge api (1.2+), added Pause All/Resume All helper context menu items and made helper display only bandwiths over 5kbps (so when deluge runs with no active downloads, overhead bandwidths of 1-2kbps do not pop up on the badge.

Description of the change

Updated deluge helper to work with new deluge api (1.2+), added Pause All/Resume All helper context menu items and made helper display only bandwiths over 5kbps (so when deluge runs with no active downloads, overhead bandwidths of 1-2kbps do not pop up on the badge.

Deluge version 1.2 (from jan 10, 2010) changed deluge API considerably, and deluge helper stopped working (bug#507184 https://bugs.launchpad.net/docky/+bug/507184). Based on the work of launchpad user Cas, I have released a patch that later got featured on OMGUbuntu: http://www.omgubuntu.co.uk/2010/10/deluge-docky-helper-fix-working/

Somebody in the comments suggested that the patch gets proposed into dockmanager trunk, so (after 4 months) I finally got my hands into this issue, patched the original helper (before it was a standalone helper called deluge 1.2) and am now committing it to launchpad.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'metadata/deluge_badge.py.info'
--- metadata/deluge_badge.py.info 2010-06-05 13:03:27 +0000
+++ metadata/deluge_badge.py.info 2011-02-24 23:12:49 +0000
@@ -1,5 +1,5 @@
1[DockmanagerHelper]1[DockmanagerHelper]
2Name=Deluge2Name=Deluge
3Description=Show transfer rates3Description=Show transfer rates and Pause All/Resume All buttons. You have to run deluge daemonized: sudo apt-get install deluged && deluged
4Icon=deluge4Icon=deluge
5AppName=deluge5AppName=deluge
66
=== modified file 'scripts/deluge_badge.py'
--- scripts/deluge_badge.py 2010-08-06 23:14:20 +0000
+++ scripts/deluge_badge.py 2011-02-24 23:12:49 +0000
@@ -1,7 +1,7 @@
1#!/usr/bin/env python1#!/usr/bin/env python
22
3# 3#
4# Copyright (C) 2010 Rico Tzschichholz, Robert Dyer4# Copyright (C) 2010 Rico Tzschichholz, Robert Dyer, Igor Gevka
5# 5#
6# This program is free software: you can redistribute it and/or modify6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by7# it under the terms of the GNU General Public License as published by
@@ -18,24 +18,59 @@
18#18#
1919
20import atexit20import atexit
21import gobject21
22import dbus22from twisted.internet import glib2reactor # for gtk-2.0
23import dbus.glib23glib2reactor.install()
24import glib
25import sys
26import os
27import math
2824
29try:25try:
30 from deluge.ui.client import sclient26 from deluge.ui.client import client
27 from twisted.internet import reactor
31 from dockmanager.dockmanager import DockManagerItem, DockManagerSink, DOCKITEM_IFACE28 from dockmanager.dockmanager import DockManagerItem, DockManagerSink, DOCKITEM_IFACE
32 from signal import signal, SIGTERM29 from signal import signal, SIGTERM
33 from sys import exit30 from sys import exit
31 from gobject import timeout_add
34except ImportError, e:32except ImportError, e:
35 print e33 print e
36 exit()34 exit()
3735
38ShowUploadRate = False36debugConnections = False
37showRateOver = 5000
38rate = 0
39
40delugeDaemon = None
41
42def daemon_disconnect_callback():
43 if debugConnections:
44 print "Disconnected from deluge daemon. Will try to reconnect."
45 ConnectToDaemon()
46
47def ConnectToDaemon():
48 global delugeDaemon
49 host="localhost"
50 port=58846
51 user=""
52 password=""
53 client.set_disconnect_callback(daemon_disconnect_callback)
54 if debugConnections:
55 print "Connecting to deluge daemon..."
56 delugeDaemon = client.connect(host, port, user, password)
57
58ConnectToDaemon()
59
60def on_connect_success(result):
61 def on_get_config_value(value, key):
62 global rate
63 rate=value[key]
64 client.core.get_session_status(["download_rate"]).addCallback(on_get_config_value,"download_rate")
65
66def on_connect_fail(result):
67 if debugConnections:
68 print "Connection failed with result ", result, ", reconnecting."
69 global rate
70 rate = 0
71 ConnectToDaemon()
72 return False
73
3974
4075
41def bytes2ratestr(bytes):76def bytes2ratestr(bytes):
@@ -57,30 +92,46 @@
57 DockManagerItem.__init__(self, sink, path)92 DockManagerItem.__init__(self, sink, path)
58 93
59 self.timer = 094 self.timer = 0
60 95
61 sclient.set_core_uri()
62
63 if not self.timer > 0:96 if not self.timer > 0:
64 self.timer = gobject.timeout_add (2000, self.update_badge)97 self.timer = timeout_add (2000, self.update_badge)
98
99 self.set_menu_buttons()
65100
66 def update_badge(self):101 def update_badge(self):
67 rate = 0102 global delugeDaemon
103 global rate
68 try:104 try:
69 if ShowUploadRate:105 delugeDaemon.addCallback(on_connect_success)
70 rate = round(sclient.get_upload_rate())106 delugeDaemon.addErrback(on_connect_fail)
71 else: 107
72 rate = round(sclient.get_download_rate())108 if rate > showRateOver:
73 109 self.set_badge("%s" % bytes2ratestr(round(rate)))
74 if rate > 0:
75 self.set_badge("%s" % bytes2ratestr(rate))
76 else:110 else:
77 self.reset_badge()111 self.reset_badge()
78 return True112 return True
79 except Exception, e:113 except Exception, e:
80 print e114 print "Deluge badge exception:", e
81 self.reset_badge()115 self.reset_badge()
82 return False116 return False
83 117
118 def clear_menu_buttons(self):
119 for k in self.id_map.keys():
120 self.remove_menu_item(k)
121
122 def set_menu_buttons(self):
123 self.clear_menu_buttons()
124
125 self.add_menu_item("Pause All", "media-playback-pause")
126 self.add_menu_item("Resume All", "media-playback-start")
127
128 def menu_pressed(self, menu_id):
129
130 if self.id_map[menu_id] == "Pause All":
131 client.core.pause_all_torrents()
132 elif self.id_map[menu_id] == "Resume All":
133 client.core.resume_all_torrents()
134
84135
85class DelugeSink(DockManagerSink):136class DelugeSink(DockManagerSink):
86 def item_path_found(self, pathtoitem, item):137 def item_path_found(self, pathtoitem, item):
@@ -93,9 +144,7 @@
93 delugesink.dispose ()144 delugesink.dispose ()
94145
95if __name__ == "__main__":146if __name__ == "__main__":
96 mainloop = gobject.MainLoop(is_running=True)
97
98 atexit.register (cleanup)147 atexit.register (cleanup)
99 signal(SIGTERM, lambda signum, stack_frame: exit(1))148 signal(SIGTERM, lambda signum, stack_frame: exit(1))
100149 reactor.run()
101 mainloop.run()150

Subscribers

People subscribed via source and target branches

to status/vote changes: