[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:
parent
da4b2b4849
commit
d579efa041
|
@ -8,6 +8,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
"""Common functions for various parts of Deluge to use."""
|
"""Common functions for various parts of Deluge to use."""
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
import functools
|
import functools
|
||||||
|
@ -1047,14 +1048,14 @@ def run_profiled(func, *args, **kwargs):
|
||||||
if output_file:
|
if output_file:
|
||||||
profiler.dump_stats(output_file)
|
profiler.dump_stats(output_file)
|
||||||
log.info("Profile stats saved to %s", 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:
|
else:
|
||||||
import pstats
|
import pstats
|
||||||
import StringIO
|
import StringIO
|
||||||
strio = StringIO.StringIO()
|
strio = StringIO.StringIO()
|
||||||
ps = pstats.Stats(profiler, stream=strio).sort_stats('cumulative')
|
ps = pstats.Stats(profiler, stream=strio).sort_stats('cumulative')
|
||||||
ps.print_stats()
|
ps.print_stats()
|
||||||
print strio.getvalue()
|
print(strio.getvalue())
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return profiler.runcall(func, *args)
|
return profiler.runcall(func, *args)
|
||||||
|
|
|
@ -50,8 +50,7 @@ class Core(CorePluginBase):
|
||||||
@export
|
@export
|
||||||
def got_deluge_web(self):
|
def got_deluge_web(self):
|
||||||
try:
|
try:
|
||||||
from deluge.ui.web import server
|
from deluge.ui.web import server # noqa pylint: disable=unused-import
|
||||||
assert server # silence pyflakes
|
|
||||||
return True
|
return True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
# See LICENSE for more details.
|
# See LICENSE for more details.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
|
@ -64,7 +66,7 @@ def add_watchdog(deferred, timeout=0.05, message=None):
|
||||||
watchdog.cancel()
|
watchdog.cancel()
|
||||||
if not deferred.called:
|
if not deferred.called:
|
||||||
if message:
|
if message:
|
||||||
print message
|
print(message)
|
||||||
deferred.cancel()
|
deferred.cancel()
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
@ -190,7 +192,7 @@ class ProcessOutputHandler(protocol.ProcessProtocol):
|
||||||
if self.check_callbacks(data):
|
if self.check_callbacks(data):
|
||||||
pass
|
pass
|
||||||
elif '[ERROR' in data:
|
elif '[ERROR' in data:
|
||||||
print data,
|
print(data, end=' ')
|
||||||
|
|
||||||
def errReceived(self, data): # NOQA
|
def errReceived(self, data): # NOQA
|
||||||
"""Process output from stderr"""
|
"""Process output from stderr"""
|
||||||
|
@ -201,7 +203,7 @@ class ProcessOutputHandler(protocol.ProcessProtocol):
|
||||||
return
|
return
|
||||||
data = "\n%s" % data.strip()
|
data = "\n%s" % data.strip()
|
||||||
prefixed = data.replace("\n", "\nSTDERR: ")
|
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,
|
def start_core(listen_port=58846, logfile=None, timeout=10, timeout_msg=None,
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -20,7 +22,7 @@ class DaemonBase(object):
|
||||||
def terminate_core(self, *args):
|
def terminate_core(self, *args):
|
||||||
if args[0] is not None:
|
if args[0] is not None:
|
||||||
if hasattr(args[0], "getTraceback"):
|
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:
|
if not self.core.killed:
|
||||||
d = self.core.kill()
|
d = self.core.kill()
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from twisted.trial import unittest
|
from twisted.trial import unittest
|
||||||
|
|
||||||
|
@ -46,7 +48,7 @@ class FilesTabTestCase(BaseTestCase):
|
||||||
level = 1
|
level = 1
|
||||||
|
|
||||||
def p_level(s, l):
|
def p_level(s, l):
|
||||||
print "%s%s" % (" " * l, s)
|
print("%s%s" % (" " * l, s))
|
||||||
|
|
||||||
def _print_treestore_children(i, lvl):
|
def _print_treestore_children(i, lvl):
|
||||||
while i:
|
while i:
|
||||||
|
@ -55,9 +57,9 @@ class FilesTabTestCase(BaseTestCase):
|
||||||
_print_treestore_children(treestore.iter_children(i), lvl + 2)
|
_print_treestore_children(treestore.iter_children(i), lvl + 2)
|
||||||
i = treestore.iter_next(i)
|
i = treestore.iter_next(i)
|
||||||
|
|
||||||
print "\n%s" % title
|
print("\n%s" % title)
|
||||||
_print_treestore_children(root, level)
|
_print_treestore_children(root, level)
|
||||||
print ""
|
print("")
|
||||||
|
|
||||||
def verify_treestore(self, treestore, tree):
|
def verify_treestore(self, treestore, tree):
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ from twisted.python.failure import Failure
|
||||||
from twisted.trial import unittest
|
from twisted.trial import unittest
|
||||||
from twisted.web.error import PageRedirect
|
from twisted.web.error import PageRedirect
|
||||||
from twisted.web.http import NOT_MODIFIED
|
from twisted.web.http import NOT_MODIFIED
|
||||||
|
from twisted.web.resource import Resource
|
||||||
from twisted.web.server import Site
|
from twisted.web.server import Site
|
||||||
from twisted.web.util import redirectTo
|
from twisted.web.util import redirectTo
|
||||||
|
|
||||||
|
@ -14,13 +15,6 @@ from deluge.httpdownloader import download_file
|
||||||
from deluge.log import setup_logger
|
from deluge.log import setup_logger
|
||||||
from deluge.ui.web.common import compress
|
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()
|
temp_dir = tempfile.mkdtemp()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,20 +8,21 @@ from deluge.ui.util import lang
|
||||||
from . import common
|
from . import common
|
||||||
from .basetest import BaseTestCase
|
from .basetest import BaseTestCase
|
||||||
|
|
||||||
libs_available = True
|
|
||||||
# Allow running other tests without GTKUI dependencies available
|
# Allow running other tests without GTKUI dependencies available
|
||||||
try:
|
try:
|
||||||
from gobject import TYPE_UINT64
|
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:
|
except ImportError as err:
|
||||||
libs_available = False
|
libs_available = False
|
||||||
TYPE_UINT64 = "Whatever"
|
TYPE_UINT64 = "Whatever"
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
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()
|
lang.setup_translations()
|
||||||
|
|
||||||
|
|
|
@ -26,9 +26,6 @@ class WebServerTestCase(WebServerTestBase, WebServerMockBase):
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_get_torrent_info(self):
|
def test_get_torrent_info(self):
|
||||||
"""
|
|
||||||
|
|
||||||
"""
|
|
||||||
agent = Agent(reactor)
|
agent = Agent(reactor)
|
||||||
|
|
||||||
self.mock_authentication_ignore(self.deluge_web.auth)
|
self.mock_authentication_ignore(self.deluge_web.auth)
|
||||||
|
|
|
@ -150,8 +150,7 @@ class Preferences(component.Component):
|
||||||
|
|
||||||
if not deluge.common.osx_check() and not deluge.common.windows_check():
|
if not deluge.common.osx_check() and not deluge.common.windows_check():
|
||||||
try:
|
try:
|
||||||
import appindicator
|
import appindicator # noqa pylint: disable=unused-import
|
||||||
assert appindicator # silence pyflakes
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -15,25 +15,19 @@ from urlparse import urljoin, urlparse
|
||||||
|
|
||||||
from twisted.internet import defer, threads
|
from twisted.internet import defer, threads
|
||||||
from twisted.web.error import PageRedirect
|
from twisted.web.error import PageRedirect
|
||||||
|
from twisted.web.resource import ForbiddenResource, NoResource
|
||||||
|
|
||||||
from deluge.component import Component
|
from deluge.component import Component
|
||||||
from deluge.configmanager import get_config_dir
|
from deluge.configmanager import get_config_dir
|
||||||
from deluge.decorators import proxy
|
from deluge.decorators import proxy
|
||||||
from deluge.httpdownloader import download_file
|
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:
|
try:
|
||||||
import PIL.Image as Image
|
import PIL.Image as Image
|
||||||
import deluge.ui.Win32IconImagePlugin
|
|
||||||
assert deluge.ui.Win32IconImagePlugin # silence pyflakes
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
PIL_INSTALLED = False
|
PIL_INSTALLED = False
|
||||||
else:
|
else:
|
||||||
|
import deluge.ui.Win32IconImagePlugin # noqa pylint: disable=unused-import, ungrouped-imports
|
||||||
PIL_INSTALLED = True
|
PIL_INSTALLED = True
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
25
msgfmt.py
25
msgfmt.py
|
@ -25,6 +25,7 @@ Options:
|
||||||
--version
|
--version
|
||||||
Display version information and exit.
|
Display version information and exit.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import array
|
import array
|
||||||
import ast
|
import ast
|
||||||
|
@ -42,9 +43,9 @@ def usage(ecode, msg=''):
|
||||||
"""
|
"""
|
||||||
Print usage and msg and exit with given code.
|
Print usage and msg and exit with given code.
|
||||||
"""
|
"""
|
||||||
print >> sys.stderr, __doc__
|
print(__doc__, file=sys.stderr)
|
||||||
if msg:
|
if msg:
|
||||||
print >> sys.stderr, msg
|
print(msg, file=sys.stderr)
|
||||||
sys.exit(ecode)
|
sys.exit(ecode)
|
||||||
|
|
||||||
|
|
||||||
|
@ -115,8 +116,8 @@ def make(filename, outfile):
|
||||||
try:
|
try:
|
||||||
with open(infile) as _file:
|
with open(infile) as _file:
|
||||||
lines = _file.readlines()
|
lines = _file.readlines()
|
||||||
except IOError, msg:
|
except IOError as msg:
|
||||||
print >> sys.stderr, msg
|
print(msg, file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
section = None
|
section = None
|
||||||
|
@ -170,8 +171,8 @@ def make(filename, outfile):
|
||||||
elif section == section_str:
|
elif section == section_str:
|
||||||
msgstr += l
|
msgstr += l
|
||||||
else:
|
else:
|
||||||
print >> sys.stderr, 'Syntax error on %s:%d' % (infile, lno), 'before:'
|
print('Syntax error on %s:%d' % (infile, lno), 'before:', file=sys.stderr)
|
||||||
print >> sys.stderr, l
|
print(l, file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
# Add last entry
|
# Add last entry
|
||||||
if section == section_str:
|
if section == section_str:
|
||||||
|
@ -183,15 +184,15 @@ def make(filename, outfile):
|
||||||
try:
|
try:
|
||||||
with open(outfile, "wb") as _file:
|
with open(outfile, "wb") as _file:
|
||||||
_file.write(output)
|
_file.write(output)
|
||||||
except IOError, msg:
|
except IOError as msg:
|
||||||
print >> sys.stderr, msg
|
print(msg, file=sys.stderr)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.getopt(sys.argv[1:], 'hVo:',
|
opts, args = getopt.getopt(sys.argv[1:], 'hVo:',
|
||||||
['help', 'version', 'output-file='])
|
['help', 'version', 'output-file='])
|
||||||
except getopt.error, msg:
|
except getopt.error as msg:
|
||||||
usage(1, msg)
|
usage(1, msg)
|
||||||
|
|
||||||
outfile = None
|
outfile = None
|
||||||
|
@ -200,14 +201,14 @@ def main():
|
||||||
if opt in ('-h', '--help'):
|
if opt in ('-h', '--help'):
|
||||||
usage(0)
|
usage(0)
|
||||||
elif opt in ('-V', '--version'):
|
elif opt in ('-V', '--version'):
|
||||||
print >> sys.stderr, "msgfmt.py", __version__
|
print("msgfmt.py", __version__, file=sys.stderr)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
elif opt in ('-o', '--output-file'):
|
elif opt in ('-o', '--output-file'):
|
||||||
outfile = arg
|
outfile = arg
|
||||||
# do it
|
# do it
|
||||||
if not args:
|
if not args:
|
||||||
print >> sys.stderr, 'No input file given'
|
print('No input file given', file=sys.stderr)
|
||||||
print >> sys.stderr, "Try `msgfmt --help' for more information."
|
print("Try `msgfmt --help' for more information.", file=sys.stderr)
|
||||||
return
|
return
|
||||||
|
|
||||||
for filename in args:
|
for filename in args:
|
||||||
|
|
4
setup.py
4
setup.py
|
@ -232,8 +232,8 @@ class Build(_build):
|
||||||
try:
|
try:
|
||||||
from deluge._libtorrent import lt
|
from deluge._libtorrent import lt
|
||||||
print('Found libtorrent version: %s' % lt.__version__)
|
print('Found libtorrent version: %s' % lt.__version__)
|
||||||
except ImportError, e:
|
except ImportError as ex:
|
||||||
print('Warning libtorrent not found: %s' % e)
|
print('Warning libtorrent not found: %s' % ex)
|
||||||
|
|
||||||
|
|
||||||
class InstallData(_install_data):
|
class InstallData(_install_data):
|
||||||
|
|
Loading…
Reference in New Issue