Deluge handle network down (#701)
* return something useful if network is offline * handle cases where connection is lost after being created
This commit is contained in:
parent
a4ecdd6566
commit
78aa40c98c
@ -1,6 +1,6 @@
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
from deluge_client import DelugeRPCClient
|
from deluge_client import DelugeRPCClient, FailedToReconnectException
|
||||||
|
|
||||||
from i3pystatus import IntervalModule, logger
|
from i3pystatus import IntervalModule, logger
|
||||||
from i3pystatus.core.util import bytes_info_dict
|
from i3pystatus.core.util import bytes_info_dict
|
||||||
@ -31,6 +31,7 @@ class Deluge(IntervalModule):
|
|||||||
('username', 'username to authenticate with deluge'),
|
('username', 'username to authenticate with deluge'),
|
||||||
('password', 'password to authenticate to deluge'),
|
('password', 'password to authenticate to deluge'),
|
||||||
('path', 'override "download path" server-side when checking space used/free'),
|
('path', 'override "download path" server-side when checking space used/free'),
|
||||||
|
('offline_string', 'string to output while unable to connect to deluge daemon')
|
||||||
)
|
)
|
||||||
required = ('username', 'password')
|
required = ('username', 'password')
|
||||||
|
|
||||||
@ -39,6 +40,7 @@ class Deluge(IntervalModule):
|
|||||||
path = None
|
path = None
|
||||||
libtorrent_stats = False
|
libtorrent_stats = False
|
||||||
rounding = 2
|
rounding = 2
|
||||||
|
offline_string = 'offline'
|
||||||
|
|
||||||
format = '⛆{num_torrents} ✇{free_space_bytes}'
|
format = '⛆{num_torrents} ✇{free_space_bytes}'
|
||||||
|
|
||||||
@ -50,18 +52,27 @@ class Deluge(IntervalModule):
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
if not self.client.connected:
|
if not self.client.connected:
|
||||||
self.client.connect()
|
try:
|
||||||
|
self.client.connect()
|
||||||
|
except OSError:
|
||||||
|
self.output = {
|
||||||
|
'full_text': self.offline_string
|
||||||
|
}
|
||||||
|
return
|
||||||
|
|
||||||
self.data = self.get_session_statistics()
|
try:
|
||||||
|
self.data = self.get_session_statistics()
|
||||||
|
|
||||||
torrents = self.get_torrents_status()
|
torrents = self.get_torrents_status()
|
||||||
if torrents:
|
if torrents:
|
||||||
self.data['num_torrents'] = len(torrents)
|
self.data['num_torrents'] = len(torrents)
|
||||||
|
|
||||||
if 'free_space_bytes' in self.format:
|
if 'free_space_bytes' in self.format:
|
||||||
self.data['free_space_bytes'] = self.get_free_space(self.path)
|
self.data['free_space_bytes'] = self.get_free_space(self.path)
|
||||||
if 'used_space_bytes' in self.format:
|
if 'used_space_bytes' in self.format:
|
||||||
self.data['used_space_bytes'] = self.get_path_size(self.path)
|
self.data['used_space_bytes'] = self.get_path_size(self.path)
|
||||||
|
except FailedToReconnectException:
|
||||||
|
return
|
||||||
|
|
||||||
self.parse_values(self.data)
|
self.parse_values(self.data)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user