mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-09 18:08:39 +00:00
[Console] Refactor quit code and cleanup conn mgr
This commit is contained in:
parent
d474576104
commit
15e0e0f30a
8 changed files with 57 additions and 84 deletions
|
@ -10,9 +10,7 @@
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from twisted.internet import error, reactor
|
import deluge.component as component
|
||||||
|
|
||||||
from deluge.ui.client import client
|
|
||||||
|
|
||||||
from . import BaseCommand
|
from . import BaseCommand
|
||||||
|
|
||||||
|
@ -23,12 +21,4 @@ class Command(BaseCommand):
|
||||||
interactive_only = True
|
interactive_only = True
|
||||||
|
|
||||||
def handle(self, options):
|
def handle(self, options):
|
||||||
if client.connected():
|
component.get('ConsoleUI').quit()
|
||||||
def on_disconnect(result):
|
|
||||||
reactor.stop()
|
|
||||||
return client.disconnect().addCallback(on_disconnect)
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
reactor.stop()
|
|
||||||
except error.ReactorNotRunning:
|
|
||||||
pass
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from twisted.internet import defer, reactor
|
from twisted.internet import defer, error, reactor
|
||||||
|
|
||||||
import deluge.common
|
import deluge.common
|
||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
|
@ -155,6 +155,17 @@ Please use commands from the command line, e.g.:\n
|
||||||
import curses.wrapper
|
import curses.wrapper
|
||||||
curses.wrapper(self.run)
|
curses.wrapper(self.run)
|
||||||
|
|
||||||
|
def quit(self):
|
||||||
|
if client.connected():
|
||||||
|
def on_disconnect(result):
|
||||||
|
reactor.stop()
|
||||||
|
return client.disconnect().addCallback(on_disconnect)
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
reactor.stop()
|
||||||
|
except error.ReactorNotRunning:
|
||||||
|
pass
|
||||||
|
|
||||||
def exec_args(self, options):
|
def exec_args(self, options):
|
||||||
"""Execute console commands from command line."""
|
"""Execute console commands from command line."""
|
||||||
from deluge.ui.console.cmdline.command import Commander
|
from deluge.ui.console.cmdline.command import Commander
|
||||||
|
|
|
@ -450,16 +450,9 @@ class AddTorrents(BaseMode):
|
||||||
self.refresh()
|
self.refresh()
|
||||||
return
|
return
|
||||||
|
|
||||||
if util.is_printable_char(c):
|
if util.is_printable_chr(c):
|
||||||
if chr(c) == 'Q':
|
if chr(c) == 'Q':
|
||||||
from twisted.internet import reactor
|
component.get('ConsoleUI').quit()
|
||||||
if client.connected():
|
|
||||||
def on_disconnect(result):
|
|
||||||
reactor.stop()
|
|
||||||
client.disconnect().addCallback(on_disconnect)
|
|
||||||
else:
|
|
||||||
reactor.stop()
|
|
||||||
return
|
|
||||||
elif chr(c) == 'q':
|
elif chr(c) == 'q':
|
||||||
self.back_to_overview()
|
self.back_to_overview()
|
||||||
return
|
return
|
||||||
|
@ -487,7 +480,7 @@ class AddTorrents(BaseMode):
|
||||||
elif c == util.KEY_ESC:
|
elif c == util.KEY_ESC:
|
||||||
self.back_to_overview()
|
self.back_to_overview()
|
||||||
else:
|
else:
|
||||||
if util.is_printable_char(c):
|
if util.is_printable_chr(c):
|
||||||
if chr(c) == 'h':
|
if chr(c) == 'h':
|
||||||
self.popup = MessagePopup(self, 'Help', HELP_STR, width_req=0.75)
|
self.popup = MessagePopup(self, 'Help', HELP_STR, width_req=0.75)
|
||||||
elif chr(c) == '>':
|
elif chr(c) == '>':
|
||||||
|
|
|
@ -13,8 +13,8 @@ import logging
|
||||||
|
|
||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
from deluge.decorators import overrides
|
from deluge.decorators import overrides
|
||||||
from deluge.ui.client import client
|
|
||||||
from deluge.ui.console.modes.basemode import BaseMode
|
from deluge.ui.console.modes.basemode import BaseMode
|
||||||
|
from deluge.ui.console.utils.curses_util import is_printable_chr
|
||||||
from deluge.ui.console.widgets.popup import InputPopup, PopupsHandler, SelectablePopup
|
from deluge.ui.console.widgets.popup import InputPopup, PopupsHandler, SelectablePopup
|
||||||
from deluge.ui.hostlist import HostList
|
from deluge.ui.hostlist import HostList
|
||||||
|
|
||||||
|
@ -38,14 +38,13 @@ class ConnectionManager(BaseMode, PopupsHandler):
|
||||||
self.update_select_host_popup()
|
self.update_select_host_popup()
|
||||||
|
|
||||||
def update_select_host_popup(self):
|
def update_select_host_popup(self):
|
||||||
selected_index = None
|
selected_index = self.popup.current_selection() if self.popup else None
|
||||||
if self.popup:
|
|
||||||
selected_index = self.popup.current_selection()
|
|
||||||
|
|
||||||
popup = SelectablePopup(self, _('Select Host'), self._host_selected, border_off_west=1, active_wrap=True)
|
popup = SelectablePopup(
|
||||||
popup.add_header("{!white,black,bold!}'Q'=%s, 'a'=%s, 'D'=%s" %
|
self, _('Select Host'), self._host_selected, border_off_west=1, active_wrap=True)
|
||||||
(_('Quit'), _('Add New Host'), _('Delete Host')),
|
popup.add_header(
|
||||||
space_below=True)
|
"{!white,black,bold!}'Q'=%s, 'a'=%s, 'D'=%s" %
|
||||||
|
(_('Quit'), _('Add Host'), _('Delete Host')), space_below=True)
|
||||||
self.push_popup(popup, clear=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():
|
||||||
|
@ -58,25 +57,22 @@ class ConnectionManager(BaseMode, PopupsHandler):
|
||||||
host_str = '%s:%d [%s]' % (hostname, port, state)
|
host_str = '%s:%d [%s]' % (hostname, port, state)
|
||||||
self.popup.add_line(host_id, host_str, selectable=True, use_underline=True, **args)
|
self.popup.add_line(host_id, host_str, selectable=True, use_underline=True, **args)
|
||||||
|
|
||||||
if selected_index is not None:
|
if selected_index:
|
||||||
self.popup.set_selection(selected_index)
|
self.popup.set_selection(selected_index)
|
||||||
self.inlist = True
|
self.inlist = True
|
||||||
self.refresh()
|
self.refresh()
|
||||||
|
|
||||||
def update_hosts_status(self):
|
def update_hosts_status(self):
|
||||||
|
|
||||||
for host_entry in self.hostlist.get_hosts_info():
|
for host_entry in self.hostlist.get_hosts_info():
|
||||||
def on_host_status(status_info):
|
def on_host_status(status_info):
|
||||||
self.statuses[status_info[0]] = status_info
|
self.statuses[status_info[0]] = status_info
|
||||||
self.update_select_host_popup()
|
self.update_select_host_popup()
|
||||||
|
|
||||||
self.hostlist.get_host_status(host_entry[0]).addCallback(on_host_status)
|
self.hostlist.get_host_status(host_entry[0]).addCallback(on_host_status)
|
||||||
|
|
||||||
def _on_connected(self, result):
|
def _on_connected(self, result):
|
||||||
d = component.get('ConsoleUI').start_console()
|
|
||||||
|
|
||||||
def on_console_start(result):
|
def on_console_start(result):
|
||||||
component.get('ConsoleUI').set_mode('TorrentList')
|
component.get('ConsoleUI').set_mode('TorrentList')
|
||||||
|
d = component.get('ConsoleUI').start_console()
|
||||||
d.addCallback(on_console_start)
|
d.addCallback(on_console_start)
|
||||||
|
|
||||||
def _on_connect_fail(self, result):
|
def _on_connect_fail(self, result):
|
||||||
|
@ -100,9 +96,12 @@ class ConnectionManager(BaseMode, PopupsHandler):
|
||||||
|
|
||||||
def add_popup(self):
|
def add_popup(self):
|
||||||
self.inlist = False
|
self.inlist = False
|
||||||
popup = InputPopup(self, _('Add Host (Up & Down arrows to navigate, Esc to cancel)'),
|
popup = InputPopup(
|
||||||
border_off_north=1, border_off_east=1,
|
self,
|
||||||
close_cb=self._do_add)
|
_('Add Host (Up & Down arrows to navigate, Esc to cancel)'),
|
||||||
|
border_off_north=1,
|
||||||
|
border_off_east=1,
|
||||||
|
close_cb=self._do_add)
|
||||||
popup.add_text_input('hostname', _('Hostname:'))
|
popup.add_text_input('hostname', _('Hostname:'))
|
||||||
popup.add_text_input('port', _('Port:'))
|
popup.add_text_input('port', _('Port:'))
|
||||||
popup.add_text_input('username', _('Username:'))
|
popup.add_text_input('username', _('Username:'))
|
||||||
|
@ -111,16 +110,16 @@ class ConnectionManager(BaseMode, PopupsHandler):
|
||||||
self.refresh()
|
self.refresh()
|
||||||
|
|
||||||
def add_host(self, hostname, port, username, password):
|
def add_host(self, hostname, port, username, password):
|
||||||
|
log.info('Adding host: %s', hostname)
|
||||||
try:
|
try:
|
||||||
self.hostlist.add_host(hostname, port, username, password)
|
self.hostlist.add_host(hostname, port, username, password)
|
||||||
except ValueError as ex:
|
except ValueError as ex:
|
||||||
self.report_message(_('Error adding host'), '%s' % ex)
|
self.report_message(_('Error adding host'), '%s: %s' % (hostname, ex))
|
||||||
return
|
|
||||||
else:
|
else:
|
||||||
self.update_select_host_popup()
|
self.update_select_host_popup()
|
||||||
|
|
||||||
def delete_host(self, host_id):
|
def delete_host(self, host_id):
|
||||||
log.debug('deleting host: %s', host_id)
|
log.info('Deleting host: %s', host_id)
|
||||||
self.hostlist.remove_host(host_id)
|
self.hostlist.remove_host(host_id)
|
||||||
self.update_select_host_popup()
|
self.update_select_host_popup()
|
||||||
|
|
||||||
|
@ -171,28 +170,21 @@ class ConnectionManager(BaseMode, PopupsHandler):
|
||||||
def read_input(self):
|
def read_input(self):
|
||||||
c = self.stdscr.getch()
|
c = self.stdscr.getch()
|
||||||
|
|
||||||
if c > 31 and c < 256:
|
if is_printable_chr(c):
|
||||||
if chr(c) == 'q' and self.inlist:
|
|
||||||
return
|
|
||||||
if chr(c) == 'Q':
|
if chr(c) == 'Q':
|
||||||
from twisted.internet import reactor
|
component.get('ConsoleUI').quit()
|
||||||
if client.connected():
|
elif self.inlist:
|
||||||
def on_disconnect(result):
|
if chr(c) == 'q':
|
||||||
reactor.stop()
|
return
|
||||||
client.disconnect().addCallback(on_disconnect)
|
elif chr(c) == 'D':
|
||||||
else:
|
host_id = self.popup.current_selection()[1]
|
||||||
reactor.stop()
|
self.delete_host(host_id)
|
||||||
return
|
return
|
||||||
if chr(c) == 'D' and self.inlist:
|
elif chr(c) == 'a':
|
||||||
host_id = self.popup.current_selection()[1]
|
self.add_popup()
|
||||||
self.delete_host(host_id)
|
return
|
||||||
return
|
|
||||||
if chr(c) == 'a' and self.inlist:
|
|
||||||
self.add_popup()
|
|
||||||
return
|
|
||||||
|
|
||||||
if self.popup:
|
if self.popup:
|
||||||
if self.popup.handle_read(c) and self.popup.closed():
|
if self.popup.handle_read(c) and self.popup.closed():
|
||||||
self.pop_popup()
|
self.pop_popup()
|
||||||
self.refresh()
|
self.refresh()
|
||||||
return
|
|
||||||
|
|
|
@ -292,17 +292,11 @@ class Preferences(BaseMode, PopupsHandler):
|
||||||
self.refresh()
|
self.refresh()
|
||||||
return
|
return
|
||||||
|
|
||||||
if util.is_printable_char(c):
|
if util.is_printable_chr(c):
|
||||||
if chr(c) == 'Q':
|
char = chr(c)
|
||||||
from twisted.internet import reactor
|
if char == 'Q':
|
||||||
if client.connected():
|
component.get('ConsoleUI').quit()
|
||||||
def on_disconnect(result):
|
elif char == 'h':
|
||||||
reactor.stop()
|
|
||||||
client.disconnect().addCallback(on_disconnect)
|
|
||||||
else:
|
|
||||||
reactor.stop()
|
|
||||||
return
|
|
||||||
elif chr(c) == 'h':
|
|
||||||
self.push_popup(MessagePopup(self, 'Preferences Help', HELP_STR))
|
self.push_popup(MessagePopup(self, 'Preferences Help', HELP_STR))
|
||||||
|
|
||||||
if self.sidebar.has_focus() and c == util.KEY_ESC:
|
if self.sidebar.has_focus() and c == util.KEY_ESC:
|
||||||
|
|
|
@ -259,16 +259,9 @@ class TorrentList(BaseMode, PopupsHandler):
|
||||||
self.pop_popup()
|
self.pop_popup()
|
||||||
self.refresh()
|
self.refresh()
|
||||||
return ret
|
return ret
|
||||||
if util.is_printable_char(c):
|
if util.is_printable_chr(c):
|
||||||
if chr(c) == 'Q':
|
if chr(c) == 'Q':
|
||||||
from twisted.internet import reactor
|
component.get('ConsoleUI').quit()
|
||||||
if client.connected():
|
|
||||||
def on_disconnect(result):
|
|
||||||
reactor.stop()
|
|
||||||
client.disconnect().addCallback(on_disconnect)
|
|
||||||
else:
|
|
||||||
reactor.stop()
|
|
||||||
return
|
|
||||||
elif chr(c) == 'C':
|
elif chr(c) == 'C':
|
||||||
self.consoleui.set_mode('ConnectionManager')
|
self.consoleui.set_mode('ConnectionManager')
|
||||||
return
|
return
|
||||||
|
@ -312,7 +305,7 @@ class TorrentList(BaseMode, PopupsHandler):
|
||||||
self.show_torrent_details(tid)
|
self.show_torrent_details(tid)
|
||||||
return
|
return
|
||||||
|
|
||||||
elif util.is_printable_char(c):
|
elif util.is_printable_chr(c):
|
||||||
if chr(c) == 'a':
|
if chr(c) == 'a':
|
||||||
show_torrent_add_popup(self)
|
show_torrent_add_popup(self)
|
||||||
elif chr(c) == 'v':
|
elif chr(c) == 'v':
|
||||||
|
|
|
@ -31,7 +31,7 @@ KEY_CTRL_AND_ARROW_UP = 566
|
||||||
KEY_CTRL_AND_ARROW_DOWN = 525
|
KEY_CTRL_AND_ARROW_DOWN = 525
|
||||||
|
|
||||||
|
|
||||||
def is_printable_char(c):
|
def is_printable_chr(c):
|
||||||
return c >= 32 and c <= 126
|
return c >= 32 and c <= 126
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -849,7 +849,7 @@ class ComboInput(InputField):
|
||||||
|
|
||||||
def search_handler(key):
|
def search_handler(key):
|
||||||
"""Handle keyboard input to seach the list"""
|
"""Handle keyboard input to seach the list"""
|
||||||
if not util.is_printable_char(key):
|
if not util.is_printable_chr(key):
|
||||||
return
|
return
|
||||||
selected = select_popup.current_selection()
|
selected = select_popup.current_selection()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue