diff options
-rw-r--r-- | deluge/tests/common.py | 2 | ||||
-rw-r--r-- | deluge/tests/test_client.py | 6 | ||||
-rw-r--r-- | deluge/tests/test_common.py | 6 | ||||
-rw-r--r-- | deluge/tests/test_ui_console.py | 4 | ||||
-rw-r--r-- | deluge/tests/test_ui_entry.py | 18 | ||||
-rw-r--r-- | deluge/ui/console/main.py | 63 | ||||
-rw-r--r-- | deluge/ui/console/modes/basemode.py | 4 | ||||
-rw-r--r-- | requirements.txt | 1 |
8 files changed, 53 insertions, 51 deletions
diff --git a/deluge/tests/common.py b/deluge/tests/common.py index f0ddb2b99..be33f8c58 100644 --- a/deluge/tests/common.py +++ b/deluge/tests/common.py @@ -69,7 +69,7 @@ def add_watchdog(deferred, timeout=0.05, message=None): return value deferred.addBoth(callback) - watchdog = reactor.callLater(timeout, defer.timeout, deferred) + watchdog = reactor.callLater(timeout, defer.Deferred.addTimeout, deferred) return watchdog diff --git a/deluge/tests/test_client.py b/deluge/tests/test_client.py index c89ad5309..ae1e95a71 100644 --- a/deluge/tests/test_client.py +++ b/deluge/tests/test_client.py @@ -11,7 +11,7 @@ from twisted.internet import defer import deluge.component as component from deluge import error -from deluge.common import AUTH_LEVEL_NORMAL, get_localhost_auth, windows_check +from deluge.common import AUTH_LEVEL_NORMAL, get_localhost_auth from deluge.core.authmanager import AUTH_LEVEL_ADMIN from deluge.ui.client import Client, DaemonSSLProxy, client @@ -79,10 +79,6 @@ class NoVersionSendingClient(Client): class ClientTestCase(BaseTestCase, DaemonBase): - - if windows_check(): - skip = 'windows cant start_core not enough arguments for format string' - def set_up(self): d = self.common_set_up() d.addCallback(self.start_core) diff --git a/deluge/tests/test_common.py b/deluge/tests/test_common.py index 3cecb6467..4f6aa2fd4 100644 --- a/deluge/tests/test_common.py +++ b/deluge/tests/test_common.py @@ -8,6 +8,7 @@ from __future__ import unicode_literals import os +import sys import tarfile from twisted.trial import unittest @@ -98,8 +99,9 @@ class CommonTestCase(unittest.TestCase): self.assertTrue(is_infohash('2dc5d0e71a66fe69649a640d39cb00a259704973')) def test_get_path_size(self): - if windows_check(): - raise unittest.SkipTest('os devnull is different on windows') + if windows_check() and sys.version_info < (3, 8): + # https://bugs.python.org/issue1311 + raise unittest.SkipTest('os.devnull returns False on Windows') self.assertTrue(get_path_size(os.devnull) == 0) self.assertTrue(get_path_size('non-existant.file') == -1) diff --git a/deluge/tests/test_ui_console.py b/deluge/tests/test_ui_console.py index da97f5c15..3667c608e 100644 --- a/deluge/tests/test_ui_console.py +++ b/deluge/tests/test_ui_console.py @@ -9,7 +9,6 @@ from __future__ import unicode_literals import argparse -from deluge.common import windows_check from deluge.ui.console.cmdline.commands.add import Command from deluge.ui.console.cmdline.commands.config import json_eval from deluge.ui.console.widgets.fields import TextInput @@ -46,8 +45,7 @@ class UIConsoleFieldTestCase(BaseTestCase): complete=False, ) self.assertTrue(t) - if not windows_check(): - self.assertTrue(t.handle_read(33)) + self.assertTrue(t.handle_read(33)) class UIConsoleCommandsTestCase(BaseTestCase): diff --git a/deluge/tests/test_ui_entry.py b/deluge/tests/test_ui_entry.py index bf4cff5f3..f85bc7d7d 100644 --- a/deluge/tests/test_ui_entry.py +++ b/deluge/tests/test_ui_entry.py @@ -19,6 +19,9 @@ from twisted.internet import defer import deluge import deluge.component as component +import deluge.ui.console +import deluge.ui.console.cmdline.commands.quit +import deluge.ui.console.main import deluge.ui.web.server from deluge.common import PY2, get_localhost_auth, windows_check from deluge.ui import ui_entry @@ -28,11 +31,6 @@ from . import common from .basetest import BaseTestCase from .daemon_base import DaemonBase -if not windows_check(): - import deluge.ui.console - import deluge.ui.console.cmdline.commands.quit - import deluge.ui.console.main - DEBUG_COMMAND = False sys_stdout = sys.stdout @@ -102,7 +100,7 @@ class UIWithDaemonBaseTestCase(UIBaseTestCase, DaemonBase): class DelugeEntryTestCase(BaseTestCase): if windows_check(): - skip = 'cannot test console ui on windows' + skip = 'Console ui test on Windows broken due to sys args issue' def set_up(self): common.set_tmp_config_dir() @@ -250,7 +248,7 @@ class WebUIBaseTestCase(UIBaseTestCase): class WebUIScriptEntryTestCase(BaseTestCase, WebUIBaseTestCase): if windows_check(): - skip = 'cannot test console ui on windows' + skip = 'Console ui test on Windows broken due to sys args issue' def __init__(self, testname): super(WebUIScriptEntryTestCase, self).__init__(testname) @@ -269,7 +267,7 @@ class WebUIScriptEntryTestCase(BaseTestCase, WebUIBaseTestCase): class WebUIDelugeScriptEntryTestCase(BaseTestCase, WebUIBaseTestCase): if windows_check(): - skip = 'cannot test console ui on windows' + skip = 'Console ui test on Windows broken due to sys args issue' def __init__(self, testname): super(WebUIDelugeScriptEntryTestCase, self).__init__(testname) @@ -466,7 +464,7 @@ class ConsoleScriptEntryWithDaemonTestCase( ): if windows_check(): - skip = 'cannot test console ui on windows' + skip = 'Console ui test on Windows broken due to sys args issue' def __init__(self, testname): super(ConsoleScriptEntryWithDaemonTestCase, self).__init__(testname) @@ -492,7 +490,7 @@ class ConsoleScriptEntryWithDaemonTestCase( class ConsoleScriptEntryTestCase(BaseTestCase, ConsoleUIBaseTestCase): if windows_check(): - skip = 'cannot test console ui on windows' + skip = 'Console ui test on Windows broken due to sys args issue' def __init__(self, testname): super(ConsoleScriptEntryTestCase, self).__init__(testname) diff --git a/deluge/ui/console/main.py b/deluge/ui/console/main.py index 23965bbb2..c74d9022f 100644 --- a/deluge/ui/console/main.py +++ b/deluge/ui/console/main.py @@ -67,6 +67,14 @@ DEFAULT_CONSOLE_PREFS = { } +class MockConsoleLog(object): + def write(self, data): + pass + + def flush(self): + pass + + class ConsoleUI(component.Component, TermResizeHandler): def __init__(self, options, cmds, log_stream): component.Component.__init__(self, 'ConsoleUI') @@ -114,6 +122,7 @@ class ConsoleUI(component.Component, TermResizeHandler): all commands are executed. Else None is returned. """ if self.options.parsed_cmds: + # Non-Interactive mode self.interactive = False if not self._commands: print('No valid console commands found') @@ -122,41 +131,37 @@ class ConsoleUI(component.Component, TermResizeHandler): deferred = self.exec_args(self.options) reactor.run() return deferred - else: - # Interactive - if deluge.common.windows_check(): - print( - """\nDeluge-console does not run in interactive mode on Windows. \n -Please use commands from the command line, e.g.:\n - deluge-console.exe help - deluge-console.exe info - deluge-console.exe "add --help" - deluge-console.exe "add -p c:\\mytorrents c:\\new.torrent" -""" - ) - else: - class ConsoleLog(object): - def write(self, data): - pass + # Interactive - def flush(self): - pass + # We use the curses.wrapper function to prevent the console from getting + # messed up if an uncaught exception is experienced. + try: + from curses import wrapper + except ImportError: + wrapper = None - # We don't ever want log output to terminal when running in - # interactive mode, so insert a dummy here - self.log_stream.out = ConsoleLog() + if deluge.common.windows_check() and not wrapper: + print( + """\nDeluge-console does not run in interactive mode on Windows. \n +Please use commands from the command line, e.g.:\n +deluge-console.exe help +deluge-console.exe info +deluge-console.exe "add --help" +deluge-console.exe "add -p c:\\mytorrents c:\\new.torrent" +""" + ) - # Set Esc key delay to 0 to avoid a very annoying delay - # due to curses waiting in case of other key are pressed - # after ESC is pressed - os.environ.setdefault('ESCDELAY', '0') + # We don't ever want log output to terminal when running in + # interactive mode, so insert a dummy here + self.log_stream.out = MockConsoleLog() - # We use the curses.wrapper function to prevent the console from getting - # messed up if an uncaught exception is experienced. - from curses import wrapper + # Set Esc key delay to 0 to avoid a very annoying delay + # due to curses waiting in case of other key are pressed + # after ESC is pressed + os.environ.setdefault('ESCDELAY', '0') - wrapper(self.run) + wrapper(self.run) def quit(self): if client.connected(): diff --git a/deluge/ui/console/modes/basemode.py b/deluge/ui/console/modes/basemode.py index 5520b0b46..5267eae5a 100644 --- a/deluge/ui/console/modes/basemode.py +++ b/deluge/ui/console/modes/basemode.py @@ -67,7 +67,9 @@ class TermResizeHandler(object): try: signal.signal(signal.SIGWINCH, self.on_terminal_size) except ValueError as ex: - log.debug('Unable to catch SIGWINCH signal: %s', ex) + log.debug('TermResize unavailable, unable to catch SIGWINCH signal: %s', ex) + except AttributeError as ex: + log.debug('TermResize unavailable, no SIGWINCH signal on Windows: %s', ex) def on_terminal_size(self, *args): # Get the new rows and cols value diff --git a/requirements.txt b/requirements.txt index c9cfee9eb..c414829b9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,5 +9,6 @@ six setproctitle pywin32; sys_platform == 'win32' certifi; sys_platform == 'win32' +windows-curses; sys_platform == 'win32' zope.interface>=4.4.2 distro; 'linux' in sys_platform or 'bsd' in sys_platform |