summaryrefslogtreecommitdiffstats
path: root/deluge/ui/console/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'deluge/ui/console/main.py')
-rw-r--r--deluge/ui/console/main.py74
1 files changed, 37 insertions, 37 deletions
diff --git a/deluge/ui/console/main.py b/deluge/ui/console/main.py
index 23965bb..31d1db1 100644
--- a/deluge/ui/console/main.py
+++ b/deluge/ui/console/main.py
@@ -1,4 +1,3 @@
-# -*- coding: utf-8 -*-
#
# Copyright (C) 2008-2009 Ido Abramovich <ido.deluge@gmail.com>
# Copyright (C) 2009 Andrew Resch <andrewresch@gmail.com>
@@ -8,8 +7,6 @@
# See LICENSE for more details.
#
-from __future__ import print_function, unicode_literals
-
import locale
import logging
import os
@@ -67,6 +64,14 @@ DEFAULT_CONSOLE_PREFS = {
}
+class MockConsoleLog:
+ 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 +119,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 +128,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():
@@ -281,7 +283,7 @@ Please use commands from the command line, e.g.:\n
@overrides(TermResizeHandler)
def on_terminal_size(self, *args):
- rows, cols = super(ConsoleUI, self).on_terminal_size(args)
+ rows, cols = super().on_terminal_size(args)
for mode in self.modes:
self.modes[mode].on_resize(rows, cols)
@@ -706,7 +708,7 @@ class EventLog(component.Component):
if not t_name:
return
- self.write('%s: {!info!}%s ({!cyan!}%s{!info!})' % (state, t_name, torrent_id))
+ self.write(f'{state}: {{!info!}}{t_name} ({{!cyan!}}{torrent_id}{{!info!}})')
def on_torrent_finished_event(self, torrent_id):
if component.get('TorrentList').config['ring_bell']:
@@ -734,7 +736,7 @@ class EventLog(component.Component):
except KeyError:
pass
- self.write('ConfigValueChanged: {!input!}%s: %s%s' % (key, color, value))
+ self.write(f'ConfigValueChanged: {{!input!}}{key}: {color}{value}')
def write(self, s):
current_time = time.localtime()
@@ -748,8 +750,6 @@ class EventLog(component.Component):
if date_different:
string = time.strftime(self.date_change_format)
- if deluge.common.PY2:
- string = string.decode()
self.console.write_event(' ')
self.console.write_event(string)