From 36cbfa8c618f86bcb6c08c52095be83c10c976a3 Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Wed, 16 Nov 2016 22:18:18 +0000 Subject: [PATCH] [Lint] Fix files to pass Flake8 v3.2.0 --- deluge/__rpcapi.py | 1 + deluge/bencode.py | 2 ++ deluge/common.py | 2 +- deluge/configmanager.py | 1 + deluge/log.py | 2 ++ .../plugins/Label/deluge/plugins/label/gtkui/submenu.py | 2 ++ deluge/rencode.py | 8 ++++++++ deluge/scripts/deluge_remote.py | 1 + deluge/tests/test_sessionproxy.py | 1 + deluge/tests/twisted/plugins/delugereporter.py | 1 + deluge/ui/client.py | 1 + deluge/ui/common.py | 1 + deluge/ui/console/utils/format_utils.py | 2 +- deluge/ui/gtkui/common.py | 1 + deluge/ui/gtkui/files_tab.py | 2 +- deluge/ui/gtkui/path_combo_chooser.py | 2 ++ deluge/ui/gtkui/torrentview_data_funcs.py | 1 + deluge/ui/tracker_icons.py | 1 + deluge/ui/web/common.py | 1 + docs/source/conf.py | 1 + gen_web_gettext.py | 1 + minify_web_js.py | 2 ++ packaging/win32/deluge-bbfreeze.py | 5 +++++ setup.py | 2 ++ version.py | 1 + 25 files changed, 42 insertions(+), 3 deletions(-) diff --git a/deluge/__rpcapi.py b/deluge/__rpcapi.py index 0ce9efacc..73f348ad6 100644 --- a/deluge/__rpcapi.py +++ b/deluge/__rpcapi.py @@ -28,5 +28,6 @@ def scan_for_methods(obj): cobj = classobj(obj.__name__.lower(), (object,), methods) setattr(RpcApi, obj.__name__.lower(), cobj) + scan_for_methods(Core) scan_for_methods(Daemon) diff --git a/deluge/bencode.py b/deluge/bencode.py index 5ca7a4a20..34bb15543 100644 --- a/deluge/bencode.py +++ b/deluge/bencode.py @@ -55,6 +55,7 @@ def decode_dict(x, f): r[k], f = decode_func[x[f]](x, f) return (r, f + 1) + decode_func = {} decode_func['l'] = decode_list decode_func['d'] = decode_dict @@ -122,6 +123,7 @@ def encode_dict(x, r): encode_func[type(v)](v, r) r.append('e') + encode_func = {} encode_func[Bencached] = encode_bencached encode_func[IntType] = encode_int diff --git a/deluge/common.py b/deluge/common.py index 5410a1941..d15d5e270 100644 --- a/deluge/common.py +++ b/deluge/common.py @@ -276,8 +276,8 @@ def open_url_in_browser(url): import webbrowser webbrowser.open(url) -# Formatting text functions +# Formatting text functions byte_txt = 'B' kib_txt = 'KiB' mib_txt = 'MiB' diff --git a/deluge/configmanager.py b/deluge/configmanager.py index b32f1de30..be1814b5b 100644 --- a/deluge/configmanager.py +++ b/deluge/configmanager.py @@ -95,6 +95,7 @@ class _ConfigManager(object): return self.config_files[config_file] + # Singleton functions _configmanager = _ConfigManager() diff --git a/deluge/log.py b/deluge/log.py index 9367435dd..0e4d5dde3 100644 --- a/deluge/log.py +++ b/deluge/log.py @@ -95,6 +95,7 @@ class Logging(LoggingLoggerClass): break return rv + levels = { 'info': logging.INFO, 'warn': logging.WARNING, @@ -310,4 +311,5 @@ class _BackwardsCompatibleLOG(object): ) return getattr(logging.getLogger(logger_name), name) + LOG = _BackwardsCompatibleLOG() diff --git a/deluge/plugins/Label/deluge/plugins/label/gtkui/submenu.py b/deluge/plugins/Label/deluge/plugins/label/gtkui/submenu.py index 0a4e89221..d406965a3 100644 --- a/deluge/plugins/Label/deluge/plugins/label/gtkui/submenu.py +++ b/deluge/plugins/Label/deluge/plugins/label/gtkui/submenu.py @@ -21,6 +21,8 @@ log = logging.getLogger(__name__) # Deferred Translation def _(message): return message + + NO_LABEL = _('No Label') del _ diff --git a/deluge/rencode.py b/deluge/rencode.py index e24f86548..ef5af25fd 100644 --- a/deluge/rencode.py +++ b/deluge/rencode.py @@ -214,6 +214,7 @@ def decode_false(x, f): def decode_none(x, f): return (None, f + 1) + decode_func = {} decode_func[b'0'] = decode_string decode_func[b'1'] = decode_string @@ -250,6 +251,7 @@ def make_fixed_length_string_decoders(): for i in range(STR_FIXED_COUNT): decode_func[int2byte(STR_FIXED_START + i)] = make_decoder(i) + make_fixed_length_string_decoders() @@ -265,6 +267,7 @@ def make_fixed_length_list_decoders(): for i in range(LIST_FIXED_COUNT): decode_func[int2byte(LIST_FIXED_START + i)] = make_decoder(i) + make_fixed_length_list_decoders() @@ -278,6 +281,7 @@ def make_fixed_length_int_decoders(): for i in range(INT_NEG_FIXED_COUNT): decode_func[int2byte(INT_NEG_FIXED_START + i)] = make_decoder(-1 - i) + make_fixed_length_int_decoders() @@ -293,6 +297,7 @@ def make_fixed_length_dict_decoders(): for i in range(DICT_FIXED_COUNT): decode_func[int2byte(DICT_FIXED_START + i)] = make_decoder(i) + make_fixed_length_dict_decoders() @@ -386,6 +391,7 @@ def encode_dict(x, r): encode_func[type(v)](v, r) r.append(CHR_TERM) + encode_func = {} encode_func[int] = encode_int encode_func[long] = encode_int @@ -448,6 +454,8 @@ def test(): assert 1e-10 < abs(loads(dumps(1.1, 32)) - 1.1) < 1e-6 assert abs(loads(dumps(1.1, 64)) - 1.1) < 1e-12 assert loads(dumps('Hello World!!'), decode_utf8=True) + + try: import psyco psyco.bind(dumps) diff --git a/deluge/scripts/deluge_remote.py b/deluge/scripts/deluge_remote.py index cd614ffdd..c576863fe 100644 --- a/deluge/scripts/deluge_remote.py +++ b/deluge/scripts/deluge_remote.py @@ -26,6 +26,7 @@ def is_float_digit(string): except ValueError: return False + # set up command-line options parser = OptionParser() parser.add_option('--port', help='port for deluge backend host (default: 58846)', default='58846', dest='port') diff --git a/deluge/tests/test_sessionproxy.py b/deluge/tests/test_sessionproxy.py index d8bd393ae..2698c75e5 100644 --- a/deluge/tests/test_sessionproxy.py +++ b/deluge/tests/test_sessionproxy.py @@ -94,6 +94,7 @@ class Client(object): def __getattr__(self, *args, **kwargs): return self.__noop__ + client = Client() diff --git a/deluge/tests/twisted/plugins/delugereporter.py b/deluge/tests/twisted/plugins/delugereporter.py index fcb4e2911..bcc978c79 100644 --- a/deluge/tests/twisted/plugins/delugereporter.py +++ b/deluge/tests/twisted/plugins/delugereporter.py @@ -18,6 +18,7 @@ class _Reporter(object): self.shortOpt = shortOpt self.klass = klass + deluge = _Reporter('Deluge reporter that suppresses Stacktrace from TODO tests', 'twisted.plugins.delugereporter', description='Deluge Reporter', diff --git a/deluge/ui/client.py b/deluge/ui/client.py index 6c95646e9..bcd4a52d8 100644 --- a/deluge/ui/client.py +++ b/deluge/ui/client.py @@ -784,5 +784,6 @@ class Client(object): def auth_levels_mapping_reverse(self): return self._daemon_proxy.auth_levels_mapping_reverse + # This is the object clients will use client = Client() diff --git a/deluge/ui/common.py b/deluge/ui/common.py index 686963aee..fc0fdd653 100644 --- a/deluge/ui/common.py +++ b/deluge/ui/common.py @@ -32,6 +32,7 @@ log = logging.getLogger(__name__) def _(message): return message + STATE_TRANSLATION = { 'All': _('All'), 'Active': _('Active'), diff --git a/deluge/ui/console/utils/format_utils.py b/deluge/ui/console/utils/format_utils.py index 6d08cde6c..4a26420fc 100644 --- a/deluge/ui/console/utils/format_utils.py +++ b/deluge/ui/console/utils/format_utils.py @@ -121,8 +121,8 @@ def format_column(col, lim): def format_row(row, column_widths): return ''.join([format_column(row[i], column_widths[i]) for i in range(0, len(row))]) -_strip_re = re.compile('\\{!.*?!\\}') +_strip_re = re.compile('\\{!.*?!\\}') _format_code = re.compile(r'\{\|(.*)\|\}') diff --git a/deluge/ui/gtkui/common.py b/deluge/ui/gtkui/common.py index 97943ee91..cd785269f 100644 --- a/deluge/ui/gtkui/common.py +++ b/deluge/ui/gtkui/common.py @@ -37,6 +37,7 @@ def get_pixbuf(filename): log.warning(ex) return create_blank_pixbuf() + # Status icons.. Create them from file only once to avoid constantly re-creating them. icon_downloading = get_pixbuf('downloading16.png') icon_seeding = get_pixbuf('seeding16.png') diff --git a/deluge/ui/gtkui/files_tab.py b/deluge/ui/gtkui/files_tab.py index 00e5c6884..9a36c6356 100644 --- a/deluge/ui/gtkui/files_tab.py +++ b/deluge/ui/gtkui/files_tab.py @@ -31,13 +31,13 @@ log = logging.getLogger(__name__) def _(message): return message + TRANSLATE = { 'Do Not Download': _('Do Not Download'), 'Normal Priority': _('Normal Priority'), 'High Priority': _('High Priority'), 'Highest Priority': _('Highest Priority'), } - del _ diff --git a/deluge/ui/gtkui/path_combo_chooser.py b/deluge/ui/gtkui/path_combo_chooser.py index ff07d7274..331671121 100755 --- a/deluge/ui/gtkui/path_combo_chooser.py +++ b/deluge/ui/gtkui/path_combo_chooser.py @@ -1484,8 +1484,10 @@ class PathChooserComboBox(gtk.HBox, StoredValuesPopup, GObject): 'on_show_hidden_files_checkbutton_toggled': on_show_hidden_files_toggled, } + type_register(PathChooserComboBox) + if __name__ == '__main__': import sys w = gtk.Window() diff --git a/deluge/ui/gtkui/torrentview_data_funcs.py b/deluge/ui/gtkui/torrentview_data_funcs.py index 894a9beaa..f0a0bbdc5 100644 --- a/deluge/ui/gtkui/torrentview_data_funcs.py +++ b/deluge/ui/gtkui/torrentview_data_funcs.py @@ -263,6 +263,7 @@ def cell_data_date(column, cell, model, row, data, key): date_str = common.fdate(date, date_only=True) if date > 0 else '' cell.set_property('text', date_str) + cell_data_date_added = partial(cell_data_date, key='cell_data_date_added') cell_data_date_completed = partial(cell_data_date, key='cell_data_date_completed') diff --git a/deluge/ui/tracker_icons.py b/deluge/ui/tracker_icons.py index aab374f2a..e6694e73c 100644 --- a/deluge/ui/tracker_icons.py +++ b/deluge/ui/tracker_icons.py @@ -562,6 +562,7 @@ def icon_name_to_host(icon): """ return icon.rpartition('.')[0] + MIME_MAP = { 'image/gif': 'gif', 'image/jpeg': 'jpg', diff --git a/deluge/ui/web/common.py b/deluge/ui/web/common.py index ede22767d..ff3abd567 100644 --- a/deluge/ui/web/common.py +++ b/deluge/ui/web/common.py @@ -36,6 +36,7 @@ def compress(contents, request): contents += compress_zlib.flush() return contents + try: # This is beeing done like this in order to allow tests to use the above # `compress` without requiring Mako to be instaled diff --git a/docs/source/conf.py b/docs/source/conf.py index 7b133c67a..a144f27f7 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -53,6 +53,7 @@ class Mock(object): else: return Mock() + MOCK_MODULES = ['deluge.ui.gtkui.gtkui', 'deluge._libtorrent', 'libtorrent', 'psyco', 'pygtk', 'gtk', 'gobject', 'gtk.gdk', 'pango', 'cairo', 'pangocairo', 'chardet'] diff --git a/gen_web_gettext.py b/gen_web_gettext.py index 71ea0b82d..c143b90da 100755 --- a/gen_web_gettext.py +++ b/gen_web_gettext.py @@ -95,6 +95,7 @@ def create_gettext_js(js_dir): fp.write('''GetText.add('%(key)s','${escape(_("%(key)s"))}')\n''' % locals()) return gettext_file + if __name__ == '__main__': gettext_fname = create_gettext_js(WEBUI_JS_DIR) print('Created: %s' % gettext_fname) diff --git a/minify_web_js.py b/minify_web_js.py index 645241b05..da577d792 100755 --- a/minify_web_js.py +++ b/minify_web_js.py @@ -31,6 +31,7 @@ def module_exists(module_name): else: return True + # Imports sorted by resulting file size. if module_exists('closure'): def minify_closure(file_in, file_out): @@ -109,6 +110,7 @@ def minify_js_dir(source_dir): else: print('Error minifying %s' % source_dir) + if __name__ == '__main__': if len(sys.argv) != 2: JS_SOURCE_DIRS = ['deluge/ui/web/js/deluge-all', 'deluge/ui/web/js/extjs/ext-extensions'] diff --git a/packaging/win32/deluge-bbfreeze.py b/packaging/win32/deluge-bbfreeze.py index dd69f13a2..0ee03e371 100644 --- a/packaging/win32/deluge-bbfreeze.py +++ b/packaging/win32/deluge-bbfreeze.py @@ -47,6 +47,7 @@ class VersionInfo(object): self.debug = debug self.verbose = verbose + DEBUG = False if len(sys.argv) == 2 and sys.argv[1].lower() == 'debug': DEBUG = True @@ -79,6 +80,8 @@ def recipe_gtk_override(mf): # Override bbfreeze function so that it includes all gtk libraries # in the installer so users don't require a separate GTK+ installation. return True + + bbfreeze.recipes.recipe_gtk_and_friends = recipe_gtk_override # Workaround for "ImportError: The 'packaging' package is required" with setuptools > 18.8. @@ -147,6 +150,8 @@ def ignored_files(adir, ignore_filenames): if not os.path.isdir(os.path.join(adir, ignore_file)) and ignore_file not in locale_include_list ] + + shutil.copytree(gtk_locale, os.path.join(build_dir, 'share/locale'), ignore=ignored_files) # Copy gtk theme files. diff --git a/setup.py b/setup.py index 5fcb6bf6e..4ba76264f 100755 --- a/setup.py +++ b/setup.py @@ -40,6 +40,7 @@ def windows_check(): def osx_check(): return platform.system() == 'Darwin' + desktop_data = 'deluge/ui/data/share/applications/deluge.desktop' @@ -314,6 +315,7 @@ class Clean(_clean): print('Deleting %s' % desktop_data) os.remove(desktop_data) + cmdclass = { 'build': Build, 'build_webui': BuildWebUI, diff --git a/version.py b/version.py index 7881ab224..e6e3f76fa 100755 --- a/version.py +++ b/version.py @@ -73,5 +73,6 @@ def get_version(prefix='', suffix=''): return version + if __name__ == '__main__': print(get_version(prefix='deluge-', suffix='.dev0'))