summaryrefslogtreecommitdiff
path: root/apt
diff options
context:
space:
mode:
authorMichael Vogt <mvo@debian.org>2013-12-31 23:25:13 +0100
committerMichael Vogt <mvo@debian.org>2014-01-05 20:04:30 +0100
commit3bf9c3fe4d19ed4d985dc8b7747a737699f46a7e (patch)
tree75ad948c351605fd7ac50b176f1149c4e2a513e4 /apt
parente3c26754af1891d2c50993730467fc9335ec5f09 (diff)
downloadpython-apt-3bf9c3fe4d19ed4d985dc8b7747a737699f46a7e.tar.gz
make test_pep8.py pass
Diffstat (limited to 'apt')
-rw-r--r--apt/auth.py39
-rw-r--r--apt/debfile.py148
-rw-r--r--apt/package.py12
-rw-r--r--apt/progress/gtk2.py8
-rw-r--r--apt/progress/text.py9
-rw-r--r--apt/utils.py2
6 files changed, 129 insertions, 89 deletions
diff --git a/apt/auth.py b/apt/auth.py
index d5a66b4a..acc612a9 100644
--- a/apt/auth.py
+++ b/apt/auth.py
@@ -67,7 +67,8 @@ def _call_apt_key_script(*args, **kwargs):
# configuration from the chroot to the apt-key script by using
# a temporary APT_CONFIG file. The apt-key script uses apt-config
# shell internally
- conf = tempfile.NamedTemporaryFile(prefix="apt-key", suffix=".conf")
+ conf = tempfile.NamedTemporaryFile(
+ prefix="apt-key", suffix=".conf")
conf.write(apt_pkg.config.dump().encode("UTF-8"))
conf.flush()
env["APT_CONFIG"] = conf.name
@@ -84,11 +85,12 @@ def _call_apt_key_script(*args, **kwargs):
output, stderr = proc.communicate(content)
if proc.returncode:
- raise AptKeyError("The apt-key script failed with return code %s:\n"
- "%s\n"
- "stdout: %s\n"
- "stderr: %s" % (proc.returncode, " ".join(cmd),
- output,stderr))
+ raise AptKeyError(
+ "The apt-key script failed with return code %s:\n"
+ "%s\n"
+ "stdout: %s\n"
+ "stderr: %s" % (
+ proc.returncode, " ".join(cmd), output, stderr))
elif stderr:
sys.stderr.write(stderr) # Forward stderr
@@ -97,6 +99,7 @@ def _call_apt_key_script(*args, **kwargs):
if conf is not None:
conf.close()
+
def add_key_from_file(filename):
"""Import a GnuPG key file to trust repositores signed by it.
@@ -109,6 +112,7 @@ def add_key_from_file(filename):
raise AptKeyError("Key file cannot be accessed: %s" % filename)
_call_apt_key_script("add", filename)
+
def add_key_from_keyserver(keyid, keyserver):
"""Import a GnuPG key file to trust repositores signed by it.
@@ -125,8 +129,9 @@ def add_key_from_keyserver(keyid, keyserver):
finally:
shutil.rmtree(tmp_keyring_dir)
+
def _add_key_from_keyserver(keyid, keyserver, tmp_keyring_dir):
- if len(keyid) < 160/8:
+ if len(keyid) < (160 / 8):
raise AptKeyError("Only long keyids (v4, 160bit) are supported")
# create a temp keyring dir
tmp_secret_keyring = os.path.join(tmp_keyring_dir, "secring.gpg")
@@ -136,14 +141,14 @@ def _add_key_from_keyserver(keyid, keyserver, tmp_keyring_dir):
"gpg",
"--no-default-keyring", "--no-options",
"--homedir", tmp_keyring_dir,
- ]
+ ]
# download the key to a temp keyring first
res = subprocess.call(gpg_default_options + [
"--secret-keyring", tmp_secret_keyring,
"--keyring", tmp_keyring,
"--keyserver", keyserver,
"--recv", keyid,
- ])
+ ])
if res != 0:
raise AptKeyError("recv from '%s' failed for '%s'" % (
keyserver, keyid))
@@ -154,7 +159,7 @@ def _add_key_from_keyserver(keyid, keyserver, tmp_keyring_dir):
"--keyring", tmp_keyring,
"--output", tmp_export_keyring,
"--export", keyid,
- ])
+ ])
if res != 0:
raise AptKeyError("export of '%s' failed", keyid)
# now verify the fingerprint, this is probably redundant as we
@@ -166,10 +171,10 @@ def _add_key_from_keyserver(keyid, keyserver, tmp_keyring_dir):
"--fingerprint",
"--batch",
"--with-colons",
- ],
- stdout=subprocess.PIPE,
- universal_newlines=True).communicate()[0]
- got_fingerprint=None
+ ],
+ stdout=subprocess.PIPE,
+ universal_newlines=True).communicate()[0]
+ got_fingerprint = None
for line in output.splitlines():
if line.startswith("fpr:"):
got_fingerprint = line.split(":")[9]
@@ -185,6 +190,7 @@ def _add_key_from_keyserver(keyid, keyserver, tmp_keyring_dir):
# finally add it
add_key_from_file(tmp_export_keyring)
+
def add_key(content):
"""Import a GnuPG key to trust repositores signed by it.
@@ -194,6 +200,7 @@ def add_key(content):
_call_apt_key_script("adv", "--quiet", "--batch",
"--import", "-", stdin=content)
+
def remove_key(fingerprint):
"""Remove a GnuPG key to no longer trust repositores signed by it.
@@ -202,6 +209,7 @@ def remove_key(fingerprint):
"""
_call_apt_key_script("rm", fingerprint)
+
def export_key(fingerprint):
"""Return the GnuPG key in text format.
@@ -210,6 +218,7 @@ def export_key(fingerprint):
"""
return _call_apt_key_script("export", fingerprint)
+
def update():
"""Update the local keyring with the archive keyring and remove from
the local keyring the archive keys which are no longer valid. The
@@ -218,6 +227,7 @@ def update():
"""
return _call_apt_key_script("update")
+
def net_update():
"""Work similar to the update command above, but get the archive
keyring from an URI instead and validate it against a master key.
@@ -228,6 +238,7 @@ def net_update():
"""
return _call_apt_key_script("net-update")
+
def list_keys():
"""Returns a list of TrustedKey instances for each key which is
used to trust repositories.
diff --git a/apt/debfile.py b/apt/debfile.py
index c845b1f2..679c8468 100644
--- a/apt/debfile.py
+++ b/apt/debfile.py
@@ -27,17 +27,19 @@ import sys
from apt_pkg import gettext as _
from StringIO import StringIO
+
class NoDebArchiveException(IOError):
"""Exception which is raised if a file is no Debian archive."""
+
class DebPackage(object):
"""A Debian Package (.deb file)."""
# Constants for comparing the local package file with the version
# in the cache
- (VERSION_NONE,
- VERSION_OUTDATED,
- VERSION_SAME,
+ (VERSION_NONE,
+ VERSION_OUTDATED,
+ VERSION_SAME,
VERSION_NEWER) = range(4)
debug = 0
@@ -68,7 +70,7 @@ class DebPackage(object):
self._sections = apt_pkg.TagSection(control)
self.pkgname = self._sections["Package"]
self._check_was_run = False
-
+
def __getitem__(self, key):
return self._sections[key]
@@ -91,15 +93,15 @@ class DebPackage(object):
""" return the list of files in control.tar.gt """
control = []
try:
- self._debfile.control.go(lambda item, data: control.append(item.name))
+ self._debfile.control.go(
+ lambda item, data: control.append(item.name))
except SystemError:
return [_("List of control files for '%s' could not be read") %
self.filename]
return sorted(control)
-
# helper that will return a pkgname with a multiarch suffix if needed
- def _maybe_append_multiarch_suffix(self, pkgname,
+ def _maybe_append_multiarch_suffix(self, pkgname,
in_conflict_checking=False):
# trivial cases
if ":" in pkgname:
@@ -108,7 +110,7 @@ class DebPackage(object):
return pkgname
elif self._cache.is_virtual_package(pkgname):
return pkgname
- elif (pkgname in self._cache and
+ elif (pkgname in self._cache and
self._cache[pkgname].candidate and
self._cache[pkgname].candidate.architecture == "all"):
return pkgname
@@ -126,7 +128,7 @@ class DebPackage(object):
return pkgname
# for conflicts we need a special case here, any not multiarch enabled
# package has a implicit conflict
- if (in_conflict_checking and
+ if (in_conflict_checking and
not (cand.multi_arch & cand.MULTI_ARCH_SAME)):
return pkgname
return multiarch_pkgname
@@ -150,7 +152,9 @@ class DebPackage(object):
# check for virtual pkgs
if not depname in self._cache:
if self._cache.is_virtual_package(depname):
- self._dbg(3, "_is_or_group_satisfied(): %s is virtual dep" % depname)
+ self._dbg(
+ 3, "_is_or_group_satisfied(): %s is virtual dep" %
+ depname)
for pkg in self._cache.get_providing_packages(depname):
if pkg.is_installed:
return True
@@ -163,13 +167,15 @@ class DebPackage(object):
# if no real dependency is installed, check if there is
# a package installed that provides this dependency
# (e.g. scrollkeeper dependecies are provided by rarian-compat)
- # but only do that if there is no version required in the
+ # but only do that if there is no version required in the
# dependency (we do not supprot versionized dependencies)
if not oper:
for ppkg in self._cache.get_providing_packages(
depname, include_nonvirtual=True):
if ppkg.is_installed:
- self._dbg(3, "found installed '%s' that provides '%s'" % (ppkg.name, depname))
+ self._dbg(
+ 3, "found installed '%s' that provides '%s'" % (
+ ppkg.name, depname))
return True
return False
@@ -212,16 +218,19 @@ class DebPackage(object):
or_str += dep[0]
if ver and oper:
or_str += " (%s %s)" % (dep[2], dep[1])
- if dep != or_group[len(or_group)-1]:
+ if dep != or_group[len(or_group) - 1]:
or_str += "|"
- self._failure_string += _("Dependency is not satisfiable: %s\n") % or_str
+ self._failure_string += _(
+ "Dependency is not satisfiable: %s\n") % or_str
return False
def _check_single_pkg_conflict(self, pkgname, ver, oper):
"""Return True if a pkg conflicts with a real installed/marked pkg."""
# FIXME: deal with conflicts against its own provides
# (e.g. Provides: ftp-server, Conflicts: ftp-server)
- self._dbg(3, "_check_single_pkg_conflict() pkg='%s' ver='%s' oper='%s'" % (pkgname, ver, oper))
+ self._dbg(
+ 3, "_check_single_pkg_conflict() pkg='%s' ver='%s' oper='%s'" % (
+ pkgname, ver, oper))
pkg = self._cache[pkgname]
if pkg.is_installed:
pkgver = pkg.installed.version
@@ -265,8 +274,8 @@ class DebPackage(object):
if self.pkgname == pkg.name:
self._dbg(3, "conflict on self, ignoring")
continue
- if self._check_single_pkg_conflict(pkg.name, ver,
- oper):
+ if self._check_single_pkg_conflict(
+ pkg.name, ver, oper):
self._installed_conflicts.add(pkg.name)
continue
if self._check_single_pkg_conflict(depname, ver, oper):
@@ -289,7 +298,8 @@ class DebPackage(object):
# find depends
for key in "Depends", "Pre-Depends":
try:
- depends.extend(apt_pkg.parse_depends(self._sections[key], False))
+ depends.extend(
+ apt_pkg.parse_depends(self._sections[key], False))
except KeyError:
pass
return depends
@@ -349,22 +359,22 @@ class DebPackage(object):
return res
def check_breaks_existing_packages(self):
- """
- check if installing the package would break exsisting
+ """
+ check if installing the package would break exsisting
package on the system, e.g. system has:
smc depends on smc-data (= 1.4)
and user tries to installs smc-data 1.6
"""
# show progress information as this step may take some time
size = float(len(self._cache))
- steps = max(int(size/50), 1)
+ steps = max(int(size / 50), 1)
debver = self._sections["Version"]
debarch = self._sections["Architecture"]
# store what we provide so that we can later check against that
- provides = [ x[0][0] for x in self.provides]
+ provides = [x[0][0] for x in self.provides]
for (i, pkg) in enumerate(self._cache):
- if i%steps == 0:
- self._cache.op_progress.update(float(i)/size*100.0)
+ if i % steps == 0:
+ self._cache.op_progress.update(float(i) / size * 100.0)
if not pkg.is_installed:
continue
# check if the exising dependencies are still satisfied
@@ -373,14 +383,21 @@ class DebPackage(object):
for dep_or in pkg.installed.dependencies:
for dep in dep_or.or_dependencies:
if dep.name == self.pkgname:
- if not apt_pkg.check_dep(debver, dep.relation, dep.version):
+ if not apt_pkg.check_dep(
+ debver, dep.relation, dep.version):
self._dbg(2, "would break (depends) %s" % pkg.name)
- # TRANSLATORS: the first '%s' is the package that breaks, the second the dependency that makes it break, the third the relation (e.g. >=) and the latest the version for the releation
- self._failure_string += _("Breaks existing package '%(pkgname)s' dependency %(depname)s (%(deprelation)s %(depversion)s)") % {
- 'pkgname' : pkg.name,
- 'depname' : dep.name,
- 'deprelation' : dep.relation,
- 'depversion' : dep.version}
+ # TRANSLATORS: the first '%s' is the package that
+ # breaks, the second the dependency that makes it
+ # break, the third the relation (e.g. >=) and the
+ # latest the version for the releation
+ self._failure_string += _(
+ "Breaks existing package '%(pkgname)s' "
+ "dependency %(depname)s "
+ "(%(deprelation)s %(depversion)s)") % {
+ 'pkgname': pkg.name,
+ 'depname': dep.name,
+ 'deprelation': dep.relation,
+ 'depversion': dep.version}
self._cache.op_progress.done()
return False
# now check if there are conflicts against this package on
@@ -388,25 +405,41 @@ class DebPackage(object):
if "Conflicts" in ver.depends_list:
for conflicts_ver_list in ver.depends_list["Conflicts"]:
for c_or in conflicts_ver_list:
- if c_or.target_pkg.name == self.pkgname and c_or.target_pkg.architecture == debarch:
- if apt_pkg.check_dep(debver, c_or.comp_type, c_or.target_ver):
- self._dbg(2, "would break (conflicts) %s" % pkg.name)
- # TRANSLATORS: the first '%s' is the package that conflicts, the second the packagename that it conflicts with (so the name of the deb the user tries to install), the third is the relation (e.g. >=) and the last is the version for the relation
- self._failure_string += _("Breaks existing package '%(pkgname)s' conflict: %(targetpkg)s (%(comptype)s %(targetver)s)") % {
- 'pkgname' : pkg.name,
- 'targetpkg' : c_or.target_pkg.name,
- 'comptype' : c_or.comp_type,
- 'targetver' : c_or.target_ver }
+ if (c_or.target_pkg.name == self.pkgname and
+ c_or.target_pkg.architecture == debarch):
+ if apt_pkg.check_dep(
+ debver, c_or.comp_type, c_or.target_ver):
+ self._dbg(
+ 2, "would break (conflicts) %s" % pkg.name)
+ # TRANSLATORS: the first '%s' is the package
+ # that conflicts, the second the packagename
+ # that it conflicts with (so the name of the
+ # deb the user tries to install), the third is
+ # the relation (e.g. >=) and the last is the
+ # version for the relation
+ self._failure_string += _(
+ "Breaks existing package '%(pkgname)s' "
+ "conflict: %(targetpkg)s "
+ "(%(comptype)s %(targetver)s)") % {
+ 'pkgname': pkg.name,
+ 'targetpkg': c_or.target_pkg.name,
+ 'comptype': c_or.comp_type,
+ 'targetver': c_or.target_ver}
self._cache.op_progress.done()
return False
if (c_or.target_pkg.name in provides and
self.pkgname != pkg.name):
- self._dbg(2, "would break (conflicts) %s" % provides)
- self._failure_string += _("Breaks existing package '%(pkgname)s' that conflict: '%(targetpkg)s'. But the '%(debfile)s' provides it via: '%(provides)s'") % {
- 'provides' : ",".join(provides),
- 'debfile' : self.filename,
- 'targetpkg' : c_or.target_pkg.name,
- 'pkgname' : pkg.name }
+ self._dbg(
+ 2, "would break (conflicts) %s" % provides)
+ self._failure_string += _(
+ "Breaks existing package '%(pkgname)s' "
+ "that conflict: '%(targetpkg)s'. But the "
+ "'%(debfile)s' provides it via: "
+ "'%(provides)s'") % {
+ 'provides': ",".join(provides),
+ 'debfile': self.filename,
+ 'targetpkg': c_or.target_pkg.name,
+ 'pkgname': pkg.name}
self._cache.op_progress.done()
return False
self._cache.op_progress.done()
@@ -453,7 +486,7 @@ class DebPackage(object):
self._failure_string = _("No Architecture field in the package")
return False
arch = self._sections["Architecture"]
- if arch != "all" and arch != apt_pkg.config.find("APT::Architecture"):
+ if arch != "all" and arch != apt_pkg.config.find("APT::Architecture"):
if arch in apt_pkg.get_architectures():
self._multiarch = arch
self.pkgname = "%s:%s" % (self.pkgname, self._multiarch)
@@ -467,7 +500,8 @@ class DebPackage(object):
if self.compare_to_version_in_cache() == self.VERSION_OUTDATED:
if self._cache[self.pkgname].installed:
# the deb is older than the installed
- self._failure_string = _("A later version is already installed")
+ self._failure_string = _(
+ "A later version is already installed")
return False
# FIXME: this sort of error handling sux
@@ -477,7 +511,7 @@ class DebPackage(object):
if not self.check_conflicts():
return False
- # check if installing it would break anything on the
+ # check if installing it would break anything on the
# current system
if not self.check_breaks_existing_packages():
return False
@@ -513,8 +547,6 @@ class DebPackage(object):
pass
# check depends
for or_group in depends:
- #print "or_group: %s" % or_group
- #print "or_group satified: %s" % self._is_or_group_satisfied(or_group)
if not self._is_or_group_satisfied(or_group):
if not self._satisfy_or_group(or_group):
return False
@@ -533,7 +565,8 @@ class DebPackage(object):
"""Return missing dependencies."""
self._dbg(1, "Installing: %s" % self._need_pkgs)
if not self._check_was_run:
- raise AttributeError("property only available after check() was run")
+ raise AttributeError(
+ "property only available after check() was run")
return self._need_pkgs
@property
@@ -546,7 +579,8 @@ class DebPackage(object):
remove = []
unauthenticated = []
if not self._check_was_run:
- raise AttributeError("property only available after check() was run")
+ raise AttributeError(
+ "property only available after check() was run")
for pkg in self._cache:
if pkg.marked_install or pkg.marked_upgrade:
install.append(pkg.name)
@@ -565,7 +599,7 @@ class DebPackage(object):
def to_hex(in_data):
hex = ""
for (i, c) in enumerate(in_data):
- if i%80 == 0:
+ if i % 80 == 0:
hex += "\n"
hex += "%2.2x " % ord(c)
return hex
@@ -588,7 +622,7 @@ class DebPackage(object):
else:
s += chr(b)
return s
-
+
def _get_content(self, part, name, auto_decompress=True, auto_hex=True):
if name.startswith("./"):
name = name[2:]
@@ -643,6 +677,7 @@ class DebPackage(object):
install_progress.finishUpdate()
return res
+
class DscSrcPackage(DebPackage):
"""A locally available source package."""
@@ -698,7 +733,7 @@ class DscSrcPackage(DebPackage):
" ".join(self.binaries))
self._sections["Description"] = s
self._check_was_run = False
-
+
def check(self):
"""Check if the package is installable.."""
if not self.check_conflicts():
@@ -712,6 +747,7 @@ class DscSrcPackage(DebPackage):
# after _satisfy_depends() should probably be done
return self._satisfy_depends(self.depends)
+
def _test():
"""Test function"""
from apt.cache import Cache
diff --git a/apt/package.py b/apt/package.py
index 79dac71d..d4217195 100644
--- a/apt/package.py
+++ b/apt/package.py
@@ -26,16 +26,8 @@ import re
import socket
import subprocess
import urllib2
-try:
- from collections import Mapping, Sequence
-except ImportError:
- # (for Python < 2.6) pylint: disable-msg=C0103
- Sequence = Mapping = object
-
-try:
- from collections import Sequence
-except ImportError:
- Sequence = object
+
+from collections import Mapping, Sequence
import apt_pkg
import apt.progress.text
diff --git a/apt/progress/gtk2.py b/apt/progress/gtk2.py
index 63e531fa..b978c34f 100644
--- a/apt/progress/gtk2.py
+++ b/apt/progress/gtk2.py
@@ -27,6 +27,7 @@ pygtk.require('2.0')
import gtk
try:
import glib
+ glib # pyflakes
except ImportError:
import gobject as glib
import gobject
@@ -87,7 +88,6 @@ class GOpProgress(gobject.GObject, base.OpProgress):
self.emit("status-finished")
-
class GInstallProgress(gobject.GObject, base.InstallProgress):
"""Installation progress with GObject signals.
@@ -241,12 +241,12 @@ class GAcquireProgress(gobject.GObject, base.AcquireProgress):
current_item = self.total_items
if self.current_cps > 0:
text = (_("Downloading file %(current)li of %(total)li with "
- "%(speed)s/s") % \
+ "%(speed)s/s") %
{"current": current_item,
"total": self.total_items,
"speed": apt_pkg.size_to_str(self.current_cps)})
else:
- text = (_("Downloading file %(current)li of %(total)li") % \
+ text = (_("Downloading file %(current)li of %(total)li") %
{"current": current_item,
"total": self.total_items})
@@ -358,7 +358,7 @@ class GtkAptProgress(gtk.VBox):
if percent is None or percent == -1:
self._progressbar.pulse()
else:
- self._progressbar.set_fraction(percent/100.0)
+ self._progressbar.set_fraction(percent / 100.0)
while gtk.events_pending():
gtk.main_iteration()
diff --git a/apt/progress/text.py b/apt/progress/text.py
index c5eec092..76a4309e 100644
--- a/apt/progress/text.py
+++ b/apt/progress/text.py
@@ -47,7 +47,7 @@ class TextProgress(object):
# Fill remaining stuff with whitespace
if self._width > len(msg):
self._file.write((self._width - len(msg)) * ' ')
- elif maximize: # Needed for OpProgress.
+ elif maximize: # Needed for OpProgress.
self._width = max(self._width, len(msg))
if newline:
self._file.write("\n")
@@ -114,7 +114,7 @@ class AcquireProgress(base.AcquireProgress, TextProgress):
import struct
buf = fcntl.ioctl(self._file, termios.TIOCGWINSZ, 8 * ' ')
dummy, col, dummy, dummy = struct.unpack('hhhh', buf)
- self._width = col - 1 # 1 for the cursor
+ self._width = col - 1 # 1 for the cursor
def ims_hit(self, item):
"""Called when an item is update (e.g. not modified on the server)."""
@@ -188,8 +188,9 @@ class AcquireProgress(base.AcquireProgress, TextProgress):
# Add the total size and percent
if worker.total_size and not worker.current_item.owner.complete:
- val += "/%sB %i%%" % (apt_pkg.size_to_str(worker.total_size),
- worker.current_size*100.0/worker.total_size)
+ val += "/%sB %i%%" % (
+ apt_pkg.size_to_str(worker.total_size),
+ worker.current_size * 100.0 / worker.total_size)
val += ']'
diff --git a/apt/utils.py b/apt/utils.py
index 08140258..9451f4bc 100644
--- a/apt/utils.py
+++ b/apt/utils.py
@@ -32,7 +32,7 @@ def get_maintenance_end_date(release_date, m_months):
years = m_months // 12
months = m_months % 12
support_end_year = (release_date.year + years +
- (release_date.month + months)//12)
+ (release_date.month + months) // 12)
support_end_month = (release_date.month + months) % 12
# special case: this happens when e.g. doing 2010-06 + 18 months
if support_end_month == 0: