mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-07 00:48:41 +00:00
[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
This commit is contained in:
parent
29f0789223
commit
66b5a2fc40
2 changed files with 20 additions and 13 deletions
|
@ -30,9 +30,12 @@ class ConnectionManager(BaseMode, PopupsHandler):
|
||||||
self.all_torrents = None
|
self.all_torrents = None
|
||||||
self.hostlist = HostList()
|
self.hostlist = HostList()
|
||||||
BaseMode.__init__(self, stdscr, encoding=encoding)
|
BaseMode.__init__(self, stdscr, encoding=encoding)
|
||||||
self.update_hosts_status()
|
|
||||||
|
|
||||||
def update_select_host_popup(self):
|
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
|
selected_index = self.popup.current_selection() if self.popup else None
|
||||||
|
|
||||||
popup = SelectablePopup(
|
popup = SelectablePopup(
|
||||||
|
@ -47,22 +50,24 @@ class ConnectionManager(BaseMode, PopupsHandler):
|
||||||
% (_('Quit'), _('Add Host'), _('Delete Host')),
|
% (_('Quit'), _('Add Host'), _('Delete Host')),
|
||||||
space_below=True,
|
space_below=True,
|
||||||
)
|
)
|
||||||
self.push_popup(popup, clear=True)
|
|
||||||
|
|
||||||
for host_entry in self.hostlist.get_hosts_info():
|
for host_entry in self.hostlist.get_hosts_info():
|
||||||
host_id, hostname, port, user = host_entry
|
host_id, hostname, port, user = host_entry
|
||||||
args = {'data': host_id, 'foreground': 'red'}
|
host_status = self.statuses.get(host_id)
|
||||||
state = 'Offline'
|
|
||||||
if host_id in self.statuses:
|
state = host_status[1] if host_status else 'Offline'
|
||||||
state = 'Online'
|
state_color = 'green' if state in ('Online', 'Connected') else 'red'
|
||||||
args.update({'data': self.statuses[host_id], 'foreground': 'green'})
|
host_str = f'{hostname}:{port} [{state}]'
|
||||||
host_str = '%s:%d [%s]' % (hostname, port, state)
|
|
||||||
self.popup.add_line(
|
args = {'data': host_id, 'foreground': state_color}
|
||||||
|
popup.add_line(
|
||||||
host_id, host_str, selectable=True, use_underline=True, **args
|
host_id, host_str, selectable=True, use_underline=True, **args
|
||||||
)
|
)
|
||||||
|
|
||||||
if selected_index:
|
if selected_index:
|
||||||
self.popup.set_selection(selected_index)
|
popup.set_selection(selected_index)
|
||||||
|
|
||||||
|
self.push_popup(popup, clear=True)
|
||||||
self.inlist = True
|
self.inlist = True
|
||||||
self.refresh()
|
self.refresh()
|
||||||
|
|
||||||
|
@ -82,7 +87,7 @@ class ConnectionManager(BaseMode, PopupsHandler):
|
||||||
d.addCallback(on_console_start)
|
d.addCallback(on_console_start)
|
||||||
|
|
||||||
def _on_connect_fail(self, result):
|
def _on_connect_fail(self, result):
|
||||||
self.report_message('Failed to connect!', result)
|
self.report_message('Failed to connect!', result.getErrorMessage())
|
||||||
self.refresh()
|
self.refresh()
|
||||||
if hasattr(result, 'getTraceback'):
|
if hasattr(result, 'getTraceback'):
|
||||||
log.exception(result)
|
log.exception(result)
|
||||||
|
@ -164,7 +169,9 @@ class ConnectionManager(BaseMode, PopupsHandler):
|
||||||
if not self.popup:
|
if not self.popup:
|
||||||
self.update_select_host_popup()
|
self.update_select_host_popup()
|
||||||
|
|
||||||
self.popup.refresh()
|
if self.popup:
|
||||||
|
self.popup.refresh()
|
||||||
|
|
||||||
curses.doupdate()
|
curses.doupdate()
|
||||||
|
|
||||||
@overrides(BaseMode)
|
@overrides(BaseMode)
|
||||||
|
|
|
@ -218,7 +218,7 @@ class HostList:
|
||||||
try:
|
try:
|
||||||
ip = gethostbyname(host)
|
ip = gethostbyname(host)
|
||||||
except gaierror as ex:
|
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)
|
return defer.succeed(status_offline)
|
||||||
|
|
||||||
host_conn_info = (
|
host_conn_info = (
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue