[Lint] Fix various pylint warnings and fixup code

* 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.
This commit is contained in:
Andrew Resch 2016-10-17 22:32:43 -07:00 committed by Calum Lind
parent da4b2b4849
commit d579efa041
12 changed files with 43 additions and 51 deletions

View File

@ -8,6 +8,7 @@
#
"""Common functions for various parts of Deluge to use."""
from __future__ import print_function
import base64
import functools
@ -1047,14 +1048,14 @@ def run_profiled(func, *args, **kwargs):
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)

View File

@ -50,8 +50,7 @@ class Core(CorePluginBase):
@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

View File

@ -7,6 +7,8 @@
# See LICENSE for more details.
#
from __future__ import print_function
import os
import sys
import tempfile
@ -64,7 +66,7 @@ def add_watchdog(deferred, timeout=0.05, message=None):
watchdog.cancel()
if not deferred.called:
if message:
print message
print(message)
deferred.cancel()
return value
@ -190,7 +192,7 @@ class ProcessOutputHandler(protocol.ProcessProtocol):
if self.check_callbacks(data):
pass
elif '[ERROR' in data:
print data,
print(data, end=' ')
def errReceived(self, data): # NOQA
"""Process output from stderr"""
@ -201,7 +203,7 @@ class ProcessOutputHandler(protocol.ProcessProtocol):
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,

View File

@ -1,3 +1,5 @@
from __future__ import print_function
import os.path
import pytest
@ -20,7 +22,7 @@ class DaemonBase(object):
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()

View File

@ -1,3 +1,5 @@
from __future__ import print_function
import pytest
from twisted.trial import unittest
@ -46,7 +48,7 @@ class FilesTabTestCase(BaseTestCase):
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:
@ -55,9 +57,9 @@ class FilesTabTestCase(BaseTestCase):
_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):

View File

@ -7,6 +7,7 @@ from twisted.python.failure import Failure
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
@ -14,13 +15,6 @@ 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()

View File

@ -8,20 +8,21 @@ from deluge.ui.util import lang
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()

View File

@ -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)

View File

@ -150,8 +150,7 @@ class Preferences(component.Component):
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:

View File

@ -15,25 +15,19 @@ from urlparse import urljoin, urlparse
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__)

View File

@ -25,6 +25,7 @@ Options:
--version
Display version information and exit.
"""
from __future__ import print_function
import array
import ast
@ -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)
@ -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
@ -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:
@ -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
@ -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:

View File

@ -232,8 +232,8 @@ class Build(_build):
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):