From 00d2c65ef7405f2e0c1e09715a751bc6bf6f0128 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sat, 10 Mar 2012 12:00:45 +0000 Subject: [PATCH] Cleanups for pylint The deprecated support for creating a Selections from a Policy has been removed (it didn't work anyway). DebianDistribution no longer takes pkgcache.bin path as an argument (it wasn't used). config.trust_db now works (I guess no-one had started using this yet). --- tests/basetest.py | 3 +-- tests/testdistro.py | 3 +-- zeroinstall/alias.py | 2 +- zeroinstall/cmd/import.py | 4 +--- zeroinstall/injector/config.py | 30 +++++++++++++++--------------- zeroinstall/injector/distro.py | 25 +++++++++---------------- zeroinstall/injector/download.py | 2 +- zeroinstall/injector/handler.py | 2 +- zeroinstall/injector/model.py | 3 ++- zeroinstall/injector/packagekit.py | 2 +- zeroinstall/injector/run.py | 2 +- zeroinstall/injector/sat.py | 1 - zeroinstall/injector/selections.py | 14 +------------- zeroinstall/injector/solver.py | 2 -- zeroinstall/support/__init__.py | 3 ++- zeroinstall/support/ssl_match_hostname.py | 2 ++ zeroinstall/zerostore/cli.py | 2 +- zeroinstall/zerostore/manifest.py | 4 ++-- 18 files changed, 42 insertions(+), 64 deletions(-) diff --git a/tests/basetest.py b/tests/basetest.py index 14cb148..f74ca2e 100755 --- a/tests/basetest.py +++ b/tests/basetest.py @@ -191,8 +191,7 @@ class BaseTest(unittest.TestCase): self.old_path = os.environ['PATH'] os.environ['PATH'] = dpkgdir + ':' + self.old_path - distro._host_distribution = distro.DebianDistribution(dpkgdir + '/status', - dpkgdir + '/pkgcache.bin') + distro._host_distribution = distro.DebianDistribution(dpkgdir + '/status') distro._host_distribution._packagekit = DummyPackageKit() my_dbus.system_services = {} diff --git a/tests/testdistro.py b/tests/testdistro.py index f44ea11..0a677d9 100755 --- a/tests/testdistro.py +++ b/tests/testdistro.py @@ -79,8 +79,7 @@ class TestDistro(BaseTest): def testDebian(self): dpkgdir = os.path.join(os.path.dirname(__file__), 'dpkg') host = distro.DebianDistribution( - os.path.join(dpkgdir, 'status'), - os.path.join(dpkgdir, 'pkgcache.bin')) + os.path.join(dpkgdir, 'status')) host._packagekit = DummyPackageKit() factory = self.make_factory(host) diff --git a/zeroinstall/alias.py b/zeroinstall/alias.py index f011822..4a074d0 100644 --- a/zeroinstall/alias.py +++ b/zeroinstall/alias.py @@ -72,7 +72,7 @@ def parse_script(pathname): else: raise NotAnAliasScript("Unknown option '{option}' in alias script".format(option = option)) else: - info.uri = line.split("'",2)[1] + info.uri = line.split("'", 2)[1] return info diff --git a/zeroinstall/cmd/import.py b/zeroinstall/cmd/import.py index 07907da..7a57b6b 100644 --- a/zeroinstall/cmd/import.py +++ b/zeroinstall/cmd/import.py @@ -53,6 +53,4 @@ def handle(config, options, args): task = tasks.Task(run(), "import feed") - errors = tasks.wait_for_blocker(task.finished) - if errors: - raise SafeException(_("Errors during download: ") + '\n'.join(errors)) + tasks.wait_for_blocker(task.finished) diff --git a/zeroinstall/injector/config.py b/zeroinstall/injector/config.py index 640bcff..e688d90 100644 --- a/zeroinstall/injector/config.py +++ b/zeroinstall/injector/config.py @@ -33,14 +33,14 @@ class Config(object): """ __slots__ = ['help_with_testing', 'freshness', 'network_use', 'feed_mirror', 'key_info_server', 'auto_approve_keys', - '_fetcher', '_stores', '_iface_cache', '_handler', '_trust_mgr'] + '_fetcher', '_stores', '_iface_cache', '_handler', '_trust_mgr', '_trust_db'] def __init__(self, handler = None): self.help_with_testing = False self.freshness = 60 * 60 * 24 * 30 self.network_use = network_full self._handler = handler - self._fetcher = self._stores = self._iface_cache = self._trust_mgr = None + self._fetcher = self._stores = self._iface_cache = self._trust_mgr = self._trust_db = None self.feed_mirror = DEFAULT_FEED_MIRROR self.key_info_server = DEFAULT_KEY_LOOKUP_SERVER self.auto_approve_keys = True @@ -89,19 +89,19 @@ class Config(object): return self._handler def save_globals(self): - """Write global settings.""" - parser = ConfigParser.ConfigParser() - parser.add_section('global') - - parser.set('global', 'help_with_testing', self.help_with_testing) - parser.set('global', 'network_use', self.network_use) - parser.set('global', 'freshness', self.freshness) - parser.set('global', 'auto_approve_keys', self.auto_approve_keys) - - path = basedir.save_config_path(config_site, config_prog) - path = os.path.join(path, 'global') - parser.write(open(path + '.new', 'w')) - os.rename(path + '.new', path) + """Write global settings.""" + parser = ConfigParser.ConfigParser() + parser.add_section('global') + + parser.set('global', 'help_with_testing', self.help_with_testing) + parser.set('global', 'network_use', self.network_use) + parser.set('global', 'freshness', self.freshness) + parser.set('global', 'auto_approve_keys', self.auto_approve_keys) + + path = basedir.save_config_path(config_site, config_prog) + path = os.path.join(path, 'global') + parser.write(open(path + '.new', 'w')) + os.rename(path + '.new', path) def load_config(handler = None): config = Config(handler) diff --git a/zeroinstall/injector/distro.py b/zeroinstall/injector/distro.py index 874d6c0..f00a604 100644 --- a/zeroinstall/injector/distro.py +++ b/zeroinstall/injector/distro.py @@ -242,10 +242,7 @@ class Distribution(object): class WindowsDistribution(Distribution): def get_package_info(self, package, factory): def _is_64bit_windows(): - import sys p = sys.platform - import platform - bits, linkage = platform.architecture() from win32process import IsWow64Process if p == 'win64' or (p == 'win32' and IsWow64Process()): return True elif p == 'win32': return False @@ -281,36 +278,34 @@ class WindowsDistribution(Distribution): if package == 'openjdk-6-jre': (java32_home, java64_home) = _read_hklm_reg(r"SOFTWARE\JavaSoft\Java Runtime Environment\1.6", "JavaHome") - import os.path if os.path.isfile(java32_home + r"\bin\java.exe"): impl = factory('package:windows:%s:%s:%s' % (package, '6', 'i486')) - impl.machine = 'i486'; + impl.machine = 'i486' impl.version = model.parse_version('6') impl.upstream_stability = model.packaged impl.main = java32_home + r"\bin\java.exe" if os.path.isfile(java64_home + r"\bin\java.exe"): impl = factory('package:windows:%s:%s:%s' % (package, '6', 'x86_64')) - impl.machine = 'x86_64'; + impl.machine = 'x86_64' impl.version = model.parse_version('6') impl.upstream_stability = model.packaged impl.main = java64_home + r"\bin\java.exe" if package == 'openjdk-6-jdk': (java32_home, java64_home) = _read_hklm_reg(r"SOFTWARE\JavaSoft\Java Development Kit\1.6", "JavaHome") - import os.path if os.path.isfile(java32_home + r"\bin\java.exe"): impl = factory('package:windows:%s:%s:%s' % (package, '6', 'i486')) - impl.machine = 'i486'; + impl.machine = 'i486' impl.version = model.parse_version('6') impl.upstream_stability = model.packaged impl.main = java32_home + r"\bin\java.exe" if os.path.isfile(java64_home + r"\bin\java.exe"): impl = factory('package:windows:%s:%s:%s' % (package, '6', 'x86_64')) - impl.machine = 'x86_64'; + impl.machine = 'x86_64' impl.version = model.parse_version('6') impl.upstream_stability = model.packaged impl.main = java64_home + r"\bin\java.exe" @@ -422,7 +417,7 @@ class DebianDistribution(Distribution): cache_leaf = 'dpkg-status.cache' - def __init__(self, dpkg_status, pkgcache): + def __init__(self, dpkg_status): self.dpkg_cache = Cache('dpkg-status.cache', dpkg_status, 2) self.apt_cache = {} @@ -729,7 +724,7 @@ class MacPortsDistribution(CachedDistribution): if not extra.startswith("(active)"): continue version = version.lstrip('@') - version = re.sub(r"\+.*","",version) # strip variants + version = re.sub(r"\+.*", "", version) # strip variants zi_arch = '*' clean_version = try_cleanup_distro_version(version) if clean_version: @@ -754,7 +749,7 @@ class MacPortsDistribution(CachedDistribution): impl = factory('package:macports:%s:%s:%s' % (package, version, machine)) impl.version = model.parse_version(version) if machine != '*': - impl.machine = machine + impl.machine = machine def get_score(self, disto_name): return int(disto_name == 'MacPorts') @@ -792,7 +787,7 @@ class CygwinDistribution(CachedDistribution): impl = factory('package:cygwin:%s:%s:%s' % (package, version, machine)) impl.version = model.parse_version(version) if machine != '*': - impl.machine = machine + impl.machine = machine def get_score(self, disto_name): return int(disto_name == 'Cygwin') @@ -806,7 +801,6 @@ def get_host_distribution(): global _host_distribution if not _host_distribution: dpkg_db_status = '/var/lib/dpkg/status' - pkgcache = '/var/cache/apt/pkgcache.bin' rpm_db_packages = '/var/lib/rpm/Packages' _slack_db = '/var/log/packages' _arch_db = '/var/lib/pacman' @@ -816,7 +810,6 @@ def get_host_distribution(): if sys.prefix == "/sw": dpkg_db_status = os.path.join(sys.prefix, dpkg_db_status) - pkgcache = os.path.join(sys.prefix, pkgcache) rpm_db_packages = os.path.join(sys.prefix, rpm_db_packages) if os.name == "nt": @@ -833,7 +826,7 @@ def get_host_distribution(): _host_distribution = CygwinDistribution(_cygwin_log) elif os.access(dpkg_db_status, os.R_OK) \ and os.path.getsize(dpkg_db_status) > 0: - _host_distribution = DebianDistribution(dpkg_db_status, pkgcache) + _host_distribution = DebianDistribution(dpkg_db_status) elif os.path.isfile(rpm_db_packages): _host_distribution = RPMDistribution(rpm_db_packages) elif os.path.isdir(_slack_db): diff --git a/zeroinstall/injector/download.py b/zeroinstall/injector/download.py index a6f2314..12609a5 100644 --- a/zeroinstall/injector/download.py +++ b/zeroinstall/injector/download.py @@ -9,7 +9,7 @@ This is the low-level interface for downloading interfaces, implementations, ico # Copyright (C) 2009, Thomas Leonard # See the README file for details, or visit http://0install.net. -import tempfile, os, sys, threading, gobject +import tempfile, os from zeroinstall import SafeException from zeroinstall.support import tasks diff --git a/zeroinstall/injector/handler.py b/zeroinstall/injector/handler.py index 0896163..b994e25 100644 --- a/zeroinstall/injector/handler.py +++ b/zeroinstall/injector/handler.py @@ -16,7 +16,7 @@ from zeroinstall import _ import sys from logging import warn, info -from zeroinstall import NeedDownload, SafeException +from zeroinstall import SafeException from zeroinstall.support import tasks from zeroinstall.injector import download diff --git a/zeroinstall/injector/model.py b/zeroinstall/injector/model.py index fb09ca5..ce5f50e 100644 --- a/zeroinstall/injector/model.py +++ b/zeroinstall/injector/model.py @@ -275,7 +275,8 @@ class EnvironmentBinding(Binding): def __str__(self): - return _("") % {'name': self.name,'mode': self.mode, 'insert': self.insert, 'value': self.value} + return _("") % \ + {'name': self.name, 'mode': self.mode, 'insert': self.insert, 'value': self.value} __repr__ = __str__ diff --git a/zeroinstall/injector/packagekit.py b/zeroinstall/injector/packagekit.py index 8dcbb4c..dbbf612 100644 --- a/zeroinstall/injector/packagekit.py +++ b/zeroinstall/injector/packagekit.py @@ -199,7 +199,7 @@ class PackageKitDownload: self.downloaded.trigger(exception = (ex, None)) def installed_cb(sender): - self._impl.installed = True; + self._impl.installed = True self.status = download.download_complete self.downloaded.trigger() diff --git a/zeroinstall/injector/run.py b/zeroinstall/injector/run.py index 4d736f2..f7b994d 100644 --- a/zeroinstall/injector/run.py +++ b/zeroinstall/injector/run.py @@ -47,7 +47,7 @@ def execute(policy, prog_args, dry_run = False, main = None, wrapper = None): """ execute_selections(policy.solver.selections, prog_args, dry_run, main, wrapper) -def test_selections(selections, prog_args, dry_run, main, wrapper = None): +def test_selections(selections, prog_args, dry_run, main): """Run the program in a child process, collecting stdout and stderr. @return: the output produced by the process @since: 0.27 diff --git a/zeroinstall/injector/sat.py b/zeroinstall/injector/sat.py index 9dbce04..4897a71 100644 --- a/zeroinstall/injector/sat.py +++ b/zeroinstall/injector/sat.py @@ -364,7 +364,6 @@ class SATProblem(object): return self.enqueue(lits[0], reason) clause = self.makeUnionClause(lits) - clause.learnt = learnt if learnt: # lits[0] is None because we just backtracked. diff --git a/zeroinstall/injector/selections.py b/zeroinstall/injector/selections.py index 2c6b210..ff38840 100644 --- a/zeroinstall/injector/selections.py +++ b/zeroinstall/injector/selections.py @@ -9,7 +9,7 @@ Load and save a set of chosen implementations. import os from zeroinstall import _ from zeroinstall.injector import model -from zeroinstall.injector.policy import Policy, get_deprecated_singleton_config +from zeroinstall.injector.policy import get_deprecated_singleton_config from zeroinstall.injector.model import process_binding, process_depends, binding_names, Command from zeroinstall.injector.namespaces import XMLNS_IFACE from zeroinstall.injector.qdom import Element, Prefixes @@ -141,23 +141,11 @@ class Selections(object): if source is None: # (Solver will fill everything in) pass - elif isinstance(source, Policy): - import warnings - warnings.warn("Use policy.solver.selections instead", DeprecationWarning, 2) - self._init_from_policy(source) elif isinstance(source, Element): self._init_from_qdom(source) else: raise Exception(_("Source not a qdom.Element!")) - def _init_from_policy(self, policy): - """Set the selections from a policy. - @deprecated: use Solver.selections instead - @param policy: the policy giving the selected implementations.""" - self.interface = policy.root - self.selections = policy.solver.selections.selections - self.commands = policy.solver.selections.commands - def _init_from_qdom(self, root): """Parse and load a selections document. @param root: a saved set of selections.""" diff --git a/zeroinstall/injector/solver.py b/zeroinstall/injector/solver.py index 9173e8d..0d5c4c7 100644 --- a/zeroinstall/injector/solver.py +++ b/zeroinstall/injector/solver.py @@ -407,7 +407,6 @@ class SATSolver(Solver): if self.record_details: self.details[iface] = [(impl, get_unusable_reason(impl, my_extra_restrictions, arch)) for impl in impls] - rank = 1 var_names = [] for impl in impls: if is_unusable(impl, my_extra_restrictions, arch): @@ -418,7 +417,6 @@ class SATSolver(Solver): assert impl not in impl_to_var v = problem.add_variable(ImplInfo(iface, impl, arch)) impl_to_var[impl] = v - rank += 1 var_names.append(v) if impl.machine and impl.machine != 'src': diff --git a/zeroinstall/support/__init__.py b/zeroinstall/support/__init__.py index b1e76ba..c125034 100644 --- a/zeroinstall/support/__init__.py +++ b/zeroinstall/support/__init__.py @@ -47,7 +47,7 @@ def read_bytes(fd, nbytes, null_ok = False): % {'data': repr(data), 'bytes': nbytes}) data += got nbytes -= len(got) - logging.debug(_("Message received: %s") % repr(data)) + logging.debug(_("Message received: %r"), data) return data def pretty_size(size): @@ -86,6 +86,7 @@ def ro_rmtree(root): shutil.rmtree(root) def raise_with_traceback(ex, tb): + """Raise an exception in a way that works on Python 2 and Python 3""" if hasattr(ex, 'with_traceback'): raise ex.with_traceback(tb) # Python 3 exec("raise ex, None, tb", {'ex': ex, 'tb': tb}) # Python 2 diff --git a/zeroinstall/support/ssl_match_hostname.py b/zeroinstall/support/ssl_match_hostname.py index 03b1fcf..55ed2f4 100644 --- a/zeroinstall/support/ssl_match_hostname.py +++ b/zeroinstall/support/ssl_match_hostname.py @@ -5,6 +5,8 @@ Copyright: Python Software Foundation License: MIT License Downloaded from: http://pypi.python.org/pypi/backports.ssl_match_hostname/""" +# pylint: disable=W0312 + import re class CertificateError(ValueError): diff --git a/zeroinstall/zerostore/cli.py b/zeroinstall/zerostore/cli.py index 2574bb6..ec1c3b8 100644 --- a/zeroinstall/zerostore/cli.py +++ b/zeroinstall/zerostore/cli.py @@ -122,7 +122,7 @@ def do_verify(args): root = get_stored(args[0]) required_digest = None # Get from name else: - raise UsageError(_("Missing DIGEST or DIRECTORY")) + raise UsageError(_("Missing DIGEST or DIRECTORY")) print(_("Verifying"), root) try: diff --git a/zeroinstall/zerostore/manifest.py b/zeroinstall/zerostore/manifest.py index 16fb562..60631c9 100644 --- a/zeroinstall/zerostore/manifest.py +++ b/zeroinstall/zerostore/manifest.py @@ -95,9 +95,9 @@ class OldSHA1(Algorithm): if stat.S_ISREG(m): d = sha1_new(open(full).read()).hexdigest() if m & 0o111: - yield "X %s %s %s %s" % (d, int(info.st_mtime) ,info.st_size, leaf) + yield "X %s %s %s %s" % (d, int(info.st_mtime), info.st_size, leaf) else: - yield "F %s %s %s %s" % (d, int(info.st_mtime) ,info.st_size, leaf) + yield "F %s %s %s %s" % (d, int(info.st_mtime), info.st_size, leaf) elif stat.S_ISLNK(m): target = os.readlink(full) d = sha1_new(target).hexdigest() -- 2.11.4.GIT