Skip to content

Commit

Permalink
[Lint] Fix various pylint warnings and fixup code
Browse files Browse the repository at this point in the history
 * Use print function
 * Fix except as statements
 * Remove old twisted 8 code
 * Remove empty docstring
 * Refactor try statement to only contain the relevant import and
   disable pylint import msgs.
 * Use flake8 noqa and pylint comment and drop pyflakes workarounds.
  • Loading branch information
aresch authored and cas-- committed Oct 26, 2016
1 parent da4b2b4 commit d579efa
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 51 deletions.
5 changes: 3 additions & 2 deletions deluge/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#

"""Common functions for various parts of Deluge to use."""
from __future__ import print_function

import base64
import functools
Expand Down Expand Up @@ -1047,14 +1048,14 @@ def on_shutdown():
if output_file:
profiler.dump_stats(output_file)
log.info("Profile stats saved to %s", output_file)
print "Profile stats saved to %s" % output_file
print("Profile stats saved to %s" % output_file)
else:
import pstats
import StringIO
strio = StringIO.StringIO()
ps = pstats.Stats(profiler, stream=strio).sort_stats('cumulative')
ps.print_stats()
print strio.getvalue()
print(strio.getvalue())

try:
return profiler.runcall(func, *args)
Expand Down
3 changes: 1 addition & 2 deletions deluge/plugins/WebUi/deluge/plugins/webui/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ def _on_stop(self, *args):
@export
def got_deluge_web(self):
try:
from deluge.ui.web import server
assert server # silence pyflakes
from deluge.ui.web import server # noqa pylint: disable=unused-import
return True
except ImportError:
return False
Expand Down
8 changes: 5 additions & 3 deletions deluge/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# See LICENSE for more details.
#

from __future__ import print_function

import os
import sys
import tempfile
Expand Down Expand Up @@ -64,7 +66,7 @@ def callback(value):
watchdog.cancel()
if not deferred.called:
if message:
print message
print(message)
deferred.cancel()
return value

Expand Down Expand Up @@ -190,7 +192,7 @@ def outReceived(self, data): # NOQA
if self.check_callbacks(data):
pass
elif '[ERROR' in data:
print data,
print(data, end=' ')

def errReceived(self, data): # NOQA
"""Process output from stderr"""
Expand All @@ -201,7 +203,7 @@ def errReceived(self, data): # NOQA
return
data = "\n%s" % data.strip()
prefixed = data.replace("\n", "\nSTDERR: ")
print "\n%s" % prefixed
print("\n%s" % prefixed)


def start_core(listen_port=58846, logfile=None, timeout=10, timeout_msg=None,
Expand Down
4 changes: 3 additions & 1 deletion deluge/tests/daemon_base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import print_function

import os.path

import pytest
Expand All @@ -20,7 +22,7 @@ def common_set_up(self):
def terminate_core(self, *args):
if args[0] is not None:
if hasattr(args[0], "getTraceback"):
print "terminate_core: Errback Exception: %s" % args[0].getTraceback()
print("terminate_core: Errback Exception: %s" % args[0].getTraceback())

if not self.core.killed:
d = self.core.kill()
Expand Down
8 changes: 5 additions & 3 deletions deluge/tests/test_files_tab.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import print_function

import pytest
from twisted.trial import unittest

Expand Down Expand Up @@ -46,7 +48,7 @@ def print_treestore(self, title, treestore):
level = 1

def p_level(s, l):
print "%s%s" % (" " * l, s)
print("%s%s" % (" " * l, s))

def _print_treestore_children(i, lvl):
while i:
Expand All @@ -55,9 +57,9 @@ def _print_treestore_children(i, lvl):
_print_treestore_children(treestore.iter_children(i), lvl + 2)
i = treestore.iter_next(i)

print "\n%s" % title
print("\n%s" % title)
_print_treestore_children(root, level)
print ""
print("")

def verify_treestore(self, treestore, tree):

Expand Down
8 changes: 1 addition & 7 deletions deluge/tests/test_httpdownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,14 @@
from twisted.trial import unittest
from twisted.web.error import PageRedirect
from twisted.web.http import NOT_MODIFIED
from twisted.web.resource import Resource
from twisted.web.server import Site
from twisted.web.util import redirectTo

from deluge.httpdownloader import download_file
from deluge.log import setup_logger
from deluge.ui.web.common import compress

try:
from twisted.web.resource import Resource
except ImportError:
# twisted 8
from twisted.web.error import Resource


temp_dir = tempfile.mkdtemp()


Expand Down
13 changes: 7 additions & 6 deletions deluge/tests/test_torrentview.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@
from . import common
from .basetest import BaseTestCase

libs_available = True
# Allow running other tests without GTKUI dependencies available
try:
from gobject import TYPE_UINT64
from deluge.ui.gtkui.mainwindow import MainWindow
from deluge.ui.gtkui.menubar import MenuBar
from deluge.ui.gtkui.torrentdetails import TorrentDetails
from deluge.ui.gtkui.torrentview import TorrentView
from deluge.ui.gtkui.gtkui import DEFAULT_PREFS
except ImportError as err:
libs_available = False
TYPE_UINT64 = "Whatever"
import traceback
traceback.print_exc()
else:
libs_available = True
from deluge.ui.gtkui.mainwindow import MainWindow # pylint: disable=ungrouped-imports
from deluge.ui.gtkui.menubar import MenuBar
from deluge.ui.gtkui.torrentdetails import TorrentDetails
from deluge.ui.gtkui.torrentview import TorrentView
from deluge.ui.gtkui.gtkui import DEFAULT_PREFS

lang.setup_translations()

Expand Down
3 changes: 0 additions & 3 deletions deluge/tests/test_webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ class WebServerTestCase(WebServerTestBase, WebServerMockBase):

@defer.inlineCallbacks
def test_get_torrent_info(self):
"""
"""
agent = Agent(reactor)

self.mock_authentication_ignore(self.deluge_web.auth)
Expand Down
3 changes: 1 addition & 2 deletions deluge/ui/gtkui/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ def set_separator(model, _iter, data=None):

if not deluge.common.osx_check() and not deluge.common.windows_check():
try:
import appindicator
assert appindicator # silence pyflakes
import appindicator # noqa pylint: disable=unused-import
except ImportError:
pass
else:
Expand Down
10 changes: 2 additions & 8 deletions deluge/ui/tracker_icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,19 @@

from twisted.internet import defer, threads
from twisted.web.error import PageRedirect
from twisted.web.resource import ForbiddenResource, NoResource

from deluge.component import Component
from deluge.configmanager import get_config_dir
from deluge.decorators import proxy
from deluge.httpdownloader import download_file

try:
from twisted.web.resource import NoResource, ForbiddenResource
except ImportError:
# twisted 8
from twisted.web.error import NoResource, ForbiddenResource

try:
import PIL.Image as Image
import deluge.ui.Win32IconImagePlugin
assert deluge.ui.Win32IconImagePlugin # silence pyflakes
except ImportError:
PIL_INSTALLED = False
else:
import deluge.ui.Win32IconImagePlugin # noqa pylint: disable=unused-import, ungrouped-imports
PIL_INSTALLED = True

log = logging.getLogger(__name__)
Expand Down
25 changes: 13 additions & 12 deletions msgfmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
--version
Display version information and exit.
"""
from __future__ import print_function

import array
import ast
Expand All @@ -42,9 +43,9 @@ def usage(ecode, msg=''):
"""
Print usage and msg and exit with given code.
"""
print >> sys.stderr, __doc__
print(__doc__, file=sys.stderr)
if msg:
print >> sys.stderr, msg
print(msg, file=sys.stderr)
sys.exit(ecode)


Expand Down Expand Up @@ -115,8 +116,8 @@ def make(filename, outfile):
try:
with open(infile) as _file:
lines = _file.readlines()
except IOError, msg:
print >> sys.stderr, msg
except IOError as msg:
print(msg, file=sys.stderr)
sys.exit(1)

section = None
Expand Down Expand Up @@ -170,8 +171,8 @@ def make(filename, outfile):
elif section == section_str:
msgstr += l
else:
print >> sys.stderr, 'Syntax error on %s:%d' % (infile, lno), 'before:'
print >> sys.stderr, l
print('Syntax error on %s:%d' % (infile, lno), 'before:', file=sys.stderr)
print(l, file=sys.stderr)
sys.exit(1)
# Add last entry
if section == section_str:
Expand All @@ -183,15 +184,15 @@ def make(filename, outfile):
try:
with open(outfile, "wb") as _file:
_file.write(output)
except IOError, msg:
print >> sys.stderr, msg
except IOError as msg:
print(msg, file=sys.stderr)


def main():
try:
opts, args = getopt.getopt(sys.argv[1:], 'hVo:',
['help', 'version', 'output-file='])
except getopt.error, msg:
except getopt.error as msg:
usage(1, msg)

outfile = None
Expand All @@ -200,14 +201,14 @@ def main():
if opt in ('-h', '--help'):
usage(0)
elif opt in ('-V', '--version'):
print >> sys.stderr, "msgfmt.py", __version__
print("msgfmt.py", __version__, file=sys.stderr)
sys.exit(0)
elif opt in ('-o', '--output-file'):
outfile = arg
# do it
if not args:
print >> sys.stderr, 'No input file given'
print >> sys.stderr, "Try `msgfmt --help' for more information."
print('No input file given', file=sys.stderr)
print("Try `msgfmt --help' for more information.", file=sys.stderr)
return

for filename in args:
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ def run(self):
try:
from deluge._libtorrent import lt
print('Found libtorrent version: %s' % lt.__version__)
except ImportError, e:
print('Warning libtorrent not found: %s' % e)
except ImportError as ex:
print('Warning libtorrent not found: %s' % ex)


class InstallData(_install_data):
Expand Down

0 comments on commit d579efa

Please sign in to comment.