Bug#733489: python-apt: Improve 'Dependency' and 'BaseDependency' to get target package versions that satisfy dependencies
On 12/31/2013 10:23 PM, Michael Vogt wrote:
> Feel free to add yourself in the changelog, i.e. something like:
> + [ Michael Schaller ]
Done.
On 12/31/2013 11:00 PM, Julian Andres Klode wrote:
It would be great if you could explain what the pyflakes issues were
in a separate paragraph of the commit message. Basically the second
sentence of the previous paragraph.
Done.
See the new patch attached.
>From 2d29cf5f820cd96b7776d08c05362a65acaa9e90 Mon Sep 17 00:00:00 2001
From: Michael Schaller <michael@5challer.de>
Date: Tue, 31 Dec 2013 23:22:32 +0100
Subject: [PATCH]
* apt/cache.py:
- Fixed PEP8 issues
- Fixed pyflakes issue: Removed unused local variable 'transient'
* apt/package.py:
- Fixed PEP8 issues
- Fixed pyflakes issue: Removed unused import 'warnings'
---
apt/cache.py | 53 +++++++++++++++++++++++++----------------------------
apt/package.py | 40 +++++++++++++++++++---------------------
debian/changelog | 9 +++++++++
3 files changed, 53 insertions(+), 49 deletions(-)
diff --git a/apt/cache.py b/apt/cache.py
index 43fb55d..6b1e2bd 100644
--- a/apt/cache.py
+++ b/apt/cache.py
@@ -40,6 +40,7 @@ class FetchFailedException(IOError):
class LockFailedException(IOError):
"""Exception that is thrown when locking fails."""
+
class CacheClosedException(Exception):
"""Exception that is thrown when the cache is used after close()."""
@@ -53,7 +54,7 @@ class Cache(object):
list of available packages.
The cache can be used like a mapping from package names to Package
- objects (although only getting items is supported).
+ objects (although only getting items is supported).
Keyword arguments:
progress -- a OpProgress object
@@ -74,7 +75,7 @@ class Cache(object):
self._fullnameset = set()
self._changes_count = -1
self._sorted_set = None
-
+
self.connect("cache_post_open", self._inc_changes_count)
self.connect("cache_post_change", self._inc_changes_count)
if memonly:
@@ -86,17 +87,17 @@ class Cache(object):
apt_pkg.config.clear("APT")
apt_pkg.config.set("Dir", rootdir)
apt_pkg.init_config()
- if os.path.exists(rootdir+"/etc/apt/apt.conf"):
+ if os.path.exists(rootdir + "/etc/apt/apt.conf"):
apt_pkg.read_config_file(apt_pkg.config,
- rootdir + "/etc/apt/apt.conf")
- if os.path.isdir(rootdir+"/etc/apt/apt.conf.d"):
+ rootdir + "/etc/apt/apt.conf")
+ if os.path.isdir(rootdir + "/etc/apt/apt.conf.d"):
apt_pkg.read_config_dir(apt_pkg.config,
- rootdir + "/etc/apt/apt.conf.d")
+ rootdir + "/etc/apt/apt.conf.d")
apt_pkg.config.set("Dir::State::status",
rootdir + "/var/lib/dpkg/status")
# also set dpkg to the rootdir path so that its called for the
# --print-foreign-architectures call
- apt_pkg.config.set("Dir::bin::dpkg",
+ apt_pkg.config.set("Dir::bin::dpkg",
os.path.join(rootdir, "usr", "bin", "dpkg"))
# create required dirs/files when run with special rootdir
# automatically
@@ -105,7 +106,6 @@ class Cache(object):
# recognized (LP: #320665)
apt_pkg.init_system()
self.open(progress)
-
def _inc_changes_count(self):
"""Increase the number of changes"""
@@ -118,12 +118,12 @@ class Cache(object):
"""
files = ["/var/lib/dpkg/status",
"/etc/apt/sources.list",
- ]
+ ]
dirs = ["/var/lib/dpkg",
"/etc/apt/",
"/var/cache/apt/archives/partial",
"/var/lib/apt/lists/partial",
- ]
+ ]
for d in dirs:
if not os.path.exists(rootdir + d):
#print "creating: ", rootdir + d
@@ -165,8 +165,8 @@ class Cache(object):
i = last = 0
size = len(self._cache.packages)
for pkg in self._cache.packages:
- if progress is not None and last+100 < i:
- progress.update(i/float(size)*100)
+ if progress is not None and last + 100 < i:
+ progress.update(i / float(size) * 100)
last = i
# drop stuff with no versions (cruft)
if pkg.has_versions:
@@ -259,7 +259,8 @@ class Cache(object):
def required_download(self):
"""Get the size of the packages that are required to download."""
if self._records is None:
- raise CacheClosedException("Cache object used after close() called")
+ raise CacheClosedException(
+ "Cache object used after close() called")
pm = apt_pkg.PackageManager(self._depcache)
fetcher = apt_pkg.Acquire()
pm.get_archives(fetcher, self._list, self._records)
@@ -289,16 +290,14 @@ class Cache(object):
# now check the result (this is the code from apt-get.cc)
failed = False
- transient = False
err_msg = ""
for item in fetcher.items:
if item.status == item.STAT_DONE:
continue
if item.STAT_IDLE:
- transient = True
continue
err_msg += "Failed to fetch %s %s\n" % (item.desc_uri,
- item.error_text)
+ item.error_text)
failed = True
# we raise a exception if the download failed or it was cancelt
@@ -311,7 +310,8 @@ class Cache(object):
def _fetch_archives(self, fetcher, pm):
""" fetch the needed archives """
if self._records is None:
- raise CacheClosedException("Cache object used after close() called")
+ raise CacheClosedException(
+ "Cache object used after close() called")
# get lock
lockfile = apt_pkg.config.find_dir("Dir::Cache::Archives") + "lock"
@@ -349,7 +349,6 @@ class Cache(object):
if fetcher is None:
fetcher = apt_pkg.Acquire(progress)
-
return self._fetch_archives(fetcher,
apt_pkg.PackageManager(self._depcache))
@@ -362,12 +361,12 @@ class Cache(object):
else:
return bool(pkg.has_provides and not pkg.has_versions)
- def get_providing_packages(self, pkgname, candidate_only=True,
+ def get_providing_packages(self, pkgname, candidate_only=True,
include_nonvirtual=False):
"""Return a list of all packages providing a package.
-
+
Return a list of packages which provide the virtual package of the
- specified name.
+ specified name.
If 'candidate_only' is False, return all packages with at
least one version providing the virtual package. Otherwise,
@@ -378,7 +377,7 @@ class Cache(object):
packages providing pkgname, even if pkgname is not itself
a virtual pkg.
"""
-
+
providers = set()
get_candidate_ver = self._depcache.get_candidate_ver
try:
@@ -423,7 +422,8 @@ class Cache(object):
old_sources_list = apt_pkg.config.find("Dir::Etc::sourcelist")
old_sources_list_d = apt_pkg.config.find("Dir::Etc::sourceparts")
old_cleanup = apt_pkg.config.find("APT::List-Cleanup")
- apt_pkg.config.set("Dir::Etc::sourcelist", os.path.abspath(sources_list))
+ apt_pkg.config.set("Dir::Etc::sourcelist",
+ os.path.abspath(sources_list))
apt_pkg.config.set("Dir::Etc::sourceparts", "xxx")
apt_pkg.config.set("APT::List-Cleanup", "0")
slist = apt_pkg.SourceList()
@@ -559,9 +559,9 @@ class Cache(object):
@property
def dpkg_journal_dirty(self):
"""Return True if the dpkg was interrupted
-
+
All dpkg operations will fail until this is fixed, the action to
- fix the system if dpkg got interrupted is to run
+ fix the system if dpkg got interrupted is to run
'dpkg --configure -a' as root.
"""
dpkg_status_dir = os.path.dirname(
@@ -711,7 +711,6 @@ class FilteredCache(object):
#print "filterCachePostChange()"
self._reapply_filter()
-
# def connect(self, name, callback):
# self.cache.connect(name, callback)
@@ -750,8 +749,6 @@ def _test():
for pkg in changes:
assert pkg.name
-
-
# see if fetching works
for dirname in ["/tmp/pytest", "/tmp/pytest/partial"]:
if not os.path.exists(dirname):
diff --git a/apt/package.py b/apt/package.py
index 04d4ddd..79dac71 100644
--- a/apt/package.py
+++ b/apt/package.py
@@ -26,7 +26,6 @@ import re
import socket
import subprocess
import urllib2
-import warnings
try:
from collections import Mapping, Sequence
except ImportError:
@@ -335,7 +334,7 @@ class Version(object):
dsc = unicode(dsc, "utf-8")
except UnicodeDecodeError as err:
return _("Invalid unicode in description for '%s' (%s). "
- "Please report.") % (self.package.name, err)
+ "Please report.") % (self.package.name, err)
lines = iter(dsc.split("\n"))
# Skip the first line, since its a duplication of the summary
@@ -416,8 +415,8 @@ class Version(object):
base_deps = []
for dep_or in dep_ver_list:
base_deps.append(BaseDependency(dep_or.target_pkg.name,
- dep_or.comp_type, dep_or.target_ver,
- (type_ == "PreDepends"),
+ dep_or.comp_type, dep_or.target_ver,
+ (type_ == "PreDepends"),
rawtype=type_))
depends_list.append(Dependency(base_deps))
except KeyError:
@@ -428,7 +427,7 @@ class Version(object):
def provides(self):
""" Return a list of names that this version provides."""
return [p[0] for p in self._cand.provides_list]
-
+
@property
def enhances(self):
"""Return the list of enhances for the package version."""
@@ -601,7 +600,7 @@ class Version(object):
for item in acq.items:
if item.status != item.STAT_DONE:
raise FetchError("The item %r could not be fetched: %s" %
- (item.destfile, item.error_text))
+ (item.destfile, item.error_text))
if unpack:
outdir = src.package + '-' + apt_pkg.upstream_version(src.version)
@@ -633,8 +632,8 @@ class VersionList(Sequence):
"""
def __init__(self, package, slice_=None):
- self._package = package # apt.package.Package()
- self._versions = package._pkg.version_list # [apt_pkg.Version(), ...]
+ self._package = package # apt.package.Package()
+ self._versions = package._pkg.version_list # [apt_pkg.Version(), ...]
if slice_:
self._versions = self._versions[slice_]
@@ -659,7 +658,7 @@ class VersionList(Sequence):
return (Version(self._package, ver) for ver in self._versions)
def __contains__(self, item):
- if isinstance(item, Version): # Sequence interface
+ if isinstance(item, Version): # Sequence interface
item = item.version
# Dictionary interface.
for ver in self._versions:
@@ -702,8 +701,8 @@ class Package(object):
self._changelog = "" # Cached changelog
def __repr__(self):
- return '<Package: name:%r architecture=%r id:%r>' % (self._pkg.name,
- self._pkg.architecture, self._pkg.id)
+ return '<Package: name:%r architecture=%r id:%r>' % (
+ self._pkg.name, self._pkg.architecture, self._pkg.id)
def __lt__(self, other):
return self.name < other.name
@@ -917,10 +916,10 @@ class Package(object):
src_section = "main"
# use the section of the candidate as a starting point
section = self.candidate.section
-
+
# get the source version
src_ver = self.candidate.source_version
-
+
try:
# try to get the source version of the pkg, this differs
# for some (e.g. libnspr4 on ubuntu)
@@ -1006,7 +1005,7 @@ class Package(object):
changelog_ver = changelog_ver.split(":", 1)[1]
if (installed and apt_pkg.version_compare(
- changelog_ver, installed) <= 0):
+ changelog_ver, installed) <= 0):
break
# EOF (shouldn't really happen)
changelog += line
@@ -1020,14 +1019,14 @@ class Package(object):
except urllib2.HTTPError:
res = _("The list of changes is not available yet.\n\n"
- "Please use http://launchpad.net/ubuntu/+source/%s/"
- "%s/+changelog\n"
- "until the changes become available or try again "
- "later.") % (src_pkg, src_ver)
+ "Please use http://launchpad.net/ubuntu/+source/%s/"
+ "%s/+changelog\n"
+ "until the changes become available or try again "
+ "later.") % (src_pkg, src_ver)
return res if isinstance(res, unicode) else res.decode("utf-8")
except (IOError, httplib.BadStatusLine):
res = _("Failed to download the list of changes. \nPlease "
- "check your Internet connection.")
+ "check your Internet connection.")
return res if isinstance(res, unicode) else res.decode("utf-8")
finally:
socket.setdefaulttimeout(timeout)
@@ -1168,12 +1167,11 @@ def _test():
print "Recommends: %s" % pkg.installed.recommends
for dep in pkg.candidate.dependencies:
print ",".join("%s (%s) (%s) (%s)" % (o.name, o.version, o.relation,
- o.pre_depend) for o in dep.or_dependencies)
+ o.pre_depend) for o in dep.or_dependencies)
print "arch: %s" % pkg.candidate.architecture
print "homepage: %s" % pkg.candidate.homepage
print "rec: ", pkg.candidate.record
-
print cache["2vcard"].get_changelog()
for i in True, False:
print "Running install on random upgradable pkgs with AutoFix: %s " % i
diff --git a/debian/changelog b/debian/changelog
index 52a1000..319e721 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,9 +1,18 @@
python-apt (0.9.2) UNRELEASED; urgency=low
+ [ Michael Vogt ]
* apt/cache.py:
- when using apt.Cache(rootdir=/some/dir) only read the APT
configuration from this rootdir instead of /etc (closes: #728274)
+ [ Michael Schaller]
+ * apt/cache.py:
+ - Fixed PEP8 issues
+ - Fixed pyflakes issue: Removed unused local variable 'transient'
+ * apt/package.py:
+ - Fixed PEP8 issues
+ - Fixed pyflakes issue: Removed unused import 'warnings'
+
-- Michael Vogt <michael.vogt@ubuntu.com> Sat, 23 Nov 2013 08:49:51 +0100
python-apt (0.9.1) unstable; urgency=low
--
1.8.3.2
Reply to: