summaryrefslogtreecommitdiffstats
path: root/deluge
diff options
context:
space:
mode:
authorbendikro <bro.devel+deluge@gmail.com>2020-04-02 22:02:00 +0100
committerCalum Lind <calumlind+deluge@gmail.com>2022-02-12 19:03:52 +0000
commit66b5a2fc407fe4420da05efd447d35c32d88c6c0 (patch)
tree2a7509123da9493a71b4f7012e8c34f2378a0c0e /deluge
parent29f0789223f56f9f1cc7cdf59cde244c65d0cb40 (diff)
downloaddeluge-66b5a2fc407fe4420da05efd447d35c32d88c6c0.tar.gz
deluge-66b5a2fc407fe4420da05efd447d35c32d88c6c0.tar.bz2
deluge-66b5a2fc407fe4420da05efd447d35c32d88c6c0.zip
[Console] Fix incorrect test for when a host is online
The tests in connectionmanager for when a host is online are broken and always considers a host as online. When an error occurs in e.g. in _on_connect_fail, report_message() in PopupsHandler expects the message to be string, not a Twisted Failure. Fix by checking if message is string and log a warning before converting to string. Closes: https://github.com/deluge-torrent/deluge/pull/277
Diffstat (limited to 'deluge')
-rw-r--r--deluge/ui/console/modes/connectionmanager.py31
-rw-r--r--deluge/ui/hostlist.py2
2 files changed, 20 insertions, 13 deletions
diff --git a/deluge/ui/console/modes/connectionmanager.py b/deluge/ui/console/modes/connectionmanager.py
index d85c1f861..0ccdd93db 100644
--- a/deluge/ui/console/modes/connectionmanager.py
+++ b/deluge/ui/console/modes/connectionmanager.py
@@ -30,9 +30,12 @@ class ConnectionManager(BaseMode, PopupsHandler):
self.all_torrents = None
self.hostlist = HostList()
BaseMode.__init__(self, stdscr, encoding=encoding)
- self.update_hosts_status()
def update_select_host_popup(self):
+ if self.popup and not isinstance(self.popup, SelectablePopup):
+ # Ignore MessagePopup on popup stack upon connect fail
+ return
+
selected_index = self.popup.current_selection() if self.popup else None
popup = SelectablePopup(
@@ -47,22 +50,24 @@ class ConnectionManager(BaseMode, PopupsHandler):
% (_('Quit'), _('Add Host'), _('Delete Host')),
space_below=True,
)
- self.push_popup(popup, clear=True)
for host_entry in self.hostlist.get_hosts_info():
host_id, hostname, port, user = host_entry
- args = {'data': host_id, 'foreground': 'red'}
- state = 'Offline'
- if host_id in self.statuses:
- state = 'Online'
- args.update({'data': self.statuses[host_id], 'foreground': 'green'})
- host_str = '%s:%d [%s]' % (hostname, port, state)
- self.popup.add_line(
+ host_status = self.statuses.get(host_id)
+
+ state = host_status[1] if host_status else 'Offline'
+ state_color = 'green' if state in ('Online', 'Connected') else 'red'
+ host_str = f'{hostname}:{port} [{state}]'
+
+ args = {'data': host_id, 'foreground': state_color}
+ popup.add_line(
host_id, host_str, selectable=True, use_underline=True, **args
)
if selected_index:
- self.popup.set_selection(selected_index)
+ popup.set_selection(selected_index)
+
+ self.push_popup(popup, clear=True)
self.inlist = True
self.refresh()
@@ -82,7 +87,7 @@ class ConnectionManager(BaseMode, PopupsHandler):
d.addCallback(on_console_start)
def _on_connect_fail(self, result):
- self.report_message('Failed to connect!', result)
+ self.report_message('Failed to connect!', result.getErrorMessage())
self.refresh()
if hasattr(result, 'getTraceback'):
log.exception(result)
@@ -164,7 +169,9 @@ class ConnectionManager(BaseMode, PopupsHandler):
if not self.popup:
self.update_select_host_popup()
- self.popup.refresh()
+ if self.popup:
+ self.popup.refresh()
+
curses.doupdate()
@overrides(BaseMode)
diff --git a/deluge/ui/hostlist.py b/deluge/ui/hostlist.py
index cfd7e2e59..cb5a13447 100644
--- a/deluge/ui/hostlist.py
+++ b/deluge/ui/hostlist.py
@@ -218,7 +218,7 @@ class HostList:
try:
ip = gethostbyname(host)
except gaierror as ex:
- log.error('Error resolving host %s to ip: %s', host, ex.args[1])
+ log.warning('Unable to resolve host %s to IP: %s', host, ex.args[1])
return defer.succeed(status_offline)
host_conn_info = (