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:
chestm007 2018-12-28 13:37:45 +11:00 committed by GitHub
parent a4ecdd6566
commit 78aa40c98c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,6 @@
import time
from deluge_client import DelugeRPCClient
from deluge_client import DelugeRPCClient, FailedToReconnectException
from i3pystatus import IntervalModule, logger
from i3pystatus.core.util import bytes_info_dict
@ -31,6 +31,7 @@ class Deluge(IntervalModule):
('username', 'username to authenticate with deluge'),
('password', 'password to authenticate to deluge'),
('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')
@ -39,6 +40,7 @@ class Deluge(IntervalModule):
path = None
libtorrent_stats = False
rounding = 2
offline_string = 'offline'
format = '{num_torrents}{free_space_bytes}'
@ -50,18 +52,27 @@ class Deluge(IntervalModule):
def run(self):
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()
if torrents:
self.data['num_torrents'] = len(torrents)
torrents = self.get_torrents_status()
if torrents:
self.data['num_torrents'] = len(torrents)
if 'free_space_bytes' in self.format:
self.data['free_space_bytes'] = self.get_free_space(self.path)
if 'used_space_bytes' in self.format:
self.data['used_space_bytes'] = self.get_path_size(self.path)
if 'free_space_bytes' in self.format:
self.data['free_space_bytes'] = self.get_free_space(self.path)
if 'used_space_bytes' in self.format:
self.data['used_space_bytes'] = self.get_path_size(self.path)
except FailedToReconnectException:
return
self.parse_values(self.data)