launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #05928
[Merge] lp:~cjwatson/launchpad/new-python-apt into lp:launchpad
Colin Watson has proposed merging lp:~cjwatson/launchpad/new-python-apt into lp:launchpad.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
Related bugs:
Bug #551510 in Launchpad itself: "Port to new python-apt API"
https://bugs.launchpad.net/launchpad/+bug/551510
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/new-python-apt/+merge/85649
= Summary =
Port Launchpad to the new python-apt API, introduced in lucid. Launchpad currently has to ignore a DeprecationWarning for its use of the old API; this is obviously bad since it might be removed at some point.
== Proposed fix ==
The proposed fix is fairly obvious for the most part; I searched for '(import|from) apt' and ran python-apt's utils/migrate-0.8.py script over them, screened out false positives, and replaced everything that was left with modern forms.
== Implementation details ==
I didn't discuss this with anyone before implementation since it seemed likely to be fairly mechanical. Maybe that was a mistake, since a few things did come up:
* The new apt_pkg.parse_depends and apt_pkg.parse_src_depends interfaces have a slight difference in how they return strictly-less and strictly-greater dependencies, indicating these by '<' and '>' rather than '<<' and '>>'. Personally I think this is a misdesign in python-apt; if you actually try to use '<' and '>' in control files you get less-or-equal and greater-or-equal semantics respectively due to a very old design error in dpkg, which is why we have '<<' and '>>' in the first place, and it's better not to confuse the situation further by exposing these as '<' and '>'. Thus, I think the right thing to do here is to map these operators back to the versions used in control files. There are only three relevant call sites so this isn't hard.
* cronscripts/publishing/maintenance-check.py passes deprecated apt.progress.FetchProgress and apt.progress.OpProgress instances to apt.Cache methods. I could have replaced these with modern forms, but it's unnecessary since by lucid python-apt has reasonable defaults for these parameters.
* The replacements for apt_inst.debExtract* are substantially more OOPy. This necessitated some changes to lib/lp/archiveuploader/nascentuploadfile.py that went a bit beyond search-and-replace. (The new version is more compact and I think more readable, though.)
* apt_pkg.TagFile objects are iterable. Where appropriate, I made use of this rather than using the 'step' (previously 'Step') method, which is ugly because it mutates the object.
== Tests ==
bin/test -vvct 'archivepublisher|archiveuploader|registry|soyuz'
== Demo and Q/A ==
This is mainly internal rearrangement, and I don't think any particular Q/A is required, although I'm happy to be corrected. The only untested code being modified here is scripts/ftpmaster-tools/sync-source.py, but (a) the changes to that are fairly simple and (b) that's in the process of going away in favour of API syncs anyway.
== lint ==
I cleaned up some pre-existing lint. What's left is:
./cronscripts/publishing/maintenance-check.py
86: Line exceeds 78 characters.
86: E501 line too long (84 characters)
./lib/lp/archiveuploader/tests/test_tagfiles.py
123: Line exceeds 78 characters.
145: Line exceeds 78 characters.
123: E501 line too long (83 characters)
145: E501 line too long (89 characters)
These are long URLs and didn't really seem worth adjusting to satisfy lint. (I hope to rewrite maintenance-check.py soon, anyway ...)
./lib/lp/soyuz/model/sourcepackagerelease.py
205: redefinition of function 'copyright' from line 196
lint is wrong; this is a setter property.
./scripts/ftpmaster-tools/sync-source.py
27: '_pythonpath' imported but unused
Usual lint wrongness.
--
https://code.launchpad.net/~cjwatson/launchpad/new-python-apt/+merge/85649
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/new-python-apt into lp:launchpad.
=== modified file 'cronscripts/publishing/maintenance-check.py'
--- cronscripts/publishing/maintenance-check.py 2010-11-25 13:34:33 +0000
+++ cronscripts/publishing/maintenance-check.py 2011-12-14 12:38:23 +0000
@@ -6,13 +6,7 @@
# https://code.edge.launchpad.net/~mvo/ubuntu-maintenance-check/python-port
# (where it will vanish once taken here)
-# this warning filter is only needed on older versions of python-apt,
-# once the machine runs lucid it can be removed
-import warnings
-warnings.filterwarnings("ignore", "apt API not stable yet")
import apt
-warnings.resetwarnings()
-
import apt_pkg
import logging
import os
@@ -82,13 +76,13 @@
# germinate output base directory
BASE_URL = os.environ.get(
- "MAINTENANCE_CHECK_BASE_URL",
+ "MAINTENANCE_CHECK_BASE_URL",
"http://people.canonical.com/~ubuntu-archive/germinate-output/")
# hints dir url, hints file is "$distro.hints" by default
# (e.g. lucid.hints)
HINTS_DIR_URL = os.environ.get(
- "MAINTENANCE_CHECK_HINTS_DIR_URL",
+ "MAINTENANCE_CHECK_HINTS_DIR_URL",
"http://people.canonical.com/~ubuntu-archive/seeds/platform.%s/SUPPORTED_HINTS")
# we need the archive root to parse the Sources file to support
@@ -107,9 +101,9 @@
:return: A list of binary package names.
"""
pkgnames = set()
- recs = apt_pkg.GetPkgSrcRecords()
- while recs.Lookup(srcname):
- for binary in recs.Binaries:
+ recs = apt_pkg.SourceRecords()
+ while recs.lookup(srcname):
+ for binary in recs.binaries:
pkgnames.add(binary)
return pkgnames
@@ -168,7 +162,7 @@
# open cache with our just prepared rootdir
cache = apt.Cache(rootdir=rootdir)
try:
- cache.update(apt.progress.FetchProgress())
+ cache.update()
except SystemError:
logging.exception("cache.update() failed")
@@ -212,7 +206,7 @@
"""
pkgs_in_seeds = {}
for bseed in seeds:
- for seed in [bseed]: #, bseed+".build-depends", bseed+".seed"]:
+ for seed in [bseed]: # , bseed+".build-depends", bseed+".seed"]:
pkgs_in_seeds[seed] = set()
seedurl = "%s/%s.%s/%s" % (BASE_URL, name, distro, seed)
logging.debug("looking for '%s'" % seedurl)
@@ -292,7 +286,6 @@
pkg_support_time[pkg] += " (%s)" % ", ".join(
what_seeds(pkg, pkgs_in_seeds))
-
return pkg_support_time
@@ -353,14 +346,14 @@
# now go over the bits in main that we have not seen (because
# they are not in any seed and got added manually into "main"
for arch in PRIMARY_ARCHES:
- rootdir="./aptroot.%s" % distro
- apt_pkg.Config.Set("APT::Architecture", arch)
+ rootdir = "./aptroot.%s" % distro
+ apt_pkg.config.set("APT::Architecture", arch)
cache = apt.Cache(rootdir=rootdir)
try:
- cache.update(apt.progress.FetchProgress())
+ cache.update()
except SystemError:
logging.exception("cache.update() failed")
- cache.open(apt.progress.OpProgress())
+ cache.open()
for pkg in cache:
if not pkg.name in pkg_support_time:
pkg_support_time[pkg.name] = support_timeframe[-1][0]
=== modified file 'lib/lp/archivepublisher/domination.py'
--- lib/lp/archivepublisher/domination.py 2011-11-04 19:11:18 +0000
+++ lib/lp/archivepublisher/domination.py 2011-12-14 12:38:23 +0000
@@ -97,7 +97,7 @@
# Ugly, but works
-apt_pkg.InitSystem()
+apt_pkg.init_system()
def join_spr_spn():
@@ -192,7 +192,7 @@
If both publications are for the same version, their creation dates
break the tie.
"""
- version_comparison = apt_pkg.VersionCompare(
+ version_comparison = apt_pkg.version_compare(
self.getPackageVersion(pub1), self.getPackageVersion(pub2))
if version_comparison == 0:
=== modified file 'lib/lp/archivepublisher/tests/test_dominator.py'
--- lib/lp/archivepublisher/tests/test_dominator.py 2011-11-04 19:11:18 +0000
+++ lib/lp/archivepublisher/tests/test_dominator.py 2011-12-14 12:38:23 +0000
@@ -506,7 +506,7 @@
]
spphs = make_spphs_for_versions(self.factory, versions)
- debian_sorted_versions = sorted(versions, cmp=apt_pkg.VersionCompare)
+ debian_sorted_versions = sorted(versions, cmp=apt_pkg.version_compare)
# Assumption: in this case, Debian version ordering is not the
# same as alphabetical version ordering.
@@ -515,7 +515,7 @@
# The compare method produces the Debian ordering.
sorted_spphs = sorted(spphs, cmp=GeneralizedPublication().compare)
self.assertEqual(
- sorted(versions, cmp=apt_pkg.VersionCompare),
+ sorted(versions, cmp=apt_pkg.version_compare),
list_source_versions(sorted_spphs))
def test_compare_breaks_tie_with_creation_date(self):
=== modified file 'lib/lp/archiveuploader/dscfile.py'
--- lib/lp/archiveuploader/dscfile.py 2011-12-09 00:20:44 +0000
+++ lib/lp/archiveuploader/dscfile.py 2011-12-14 12:38:23 +0000
@@ -288,7 +288,6 @@
raise EarlyReturnUploadError(
"Unsupported source format: %s" % self._dict['Format'])
-
#
# Useful properties.
#
@@ -383,7 +382,7 @@
"%s: invalid %s field produced by a broken version "
"of dpkg-dev (1.10.11)" % (self.filename, field_name))
try:
- apt_pkg.ParseSrcDepends(field)
+ apt_pkg.parse_src_depends(field)
except (SystemExit, KeyboardInterrupt):
raise
except Exception, error:
=== modified file 'lib/lp/archiveuploader/nascentupload.py'
--- lib/lp/archiveuploader/nascentupload.py 2011-11-28 16:12:04 +0000
+++ lib/lp/archiveuploader/nascentupload.py 2011-12-14 12:38:23 +0000
@@ -655,7 +655,7 @@
def _checkVersion(self, proposed_version, archive_version, filename):
"""Check if the proposed version is higher than the one in archive."""
- if apt_pkg.VersionCompare(proposed_version, archive_version) < 0:
+ if apt_pkg.version_compare(proposed_version, archive_version) < 0:
self.reject("%s: Version older than that in the archive. %s <= %s"
% (filename, proposed_version, archive_version))
=== modified file 'lib/lp/archiveuploader/nascentuploadfile.py'
--- lib/lp/archiveuploader/nascentuploadfile.py 2011-08-28 07:29:11 +0000
+++ lib/lp/archiveuploader/nascentuploadfile.py 2011-12-14 12:38:23 +0000
@@ -58,7 +58,7 @@
from lp.soyuz.model.files import SourceFileMixin
-apt_pkg.InitSystem()
+apt_pkg.init_system()
class UploadError(Exception):
@@ -86,13 +86,12 @@
self.future_files = {}
self.ancient_files = {}
- def callback(self, kind, name, link, mode, uid, gid, size, mtime,
- major, minor):
- """Callback designed to cope with apt_inst.debExtract.
+ def callback(self, member, data):
+ """Callback designed to cope with apt_inst.TarFile.go.
It check and store timestamp details of the extracted DEB.
"""
- self.check_cutoff(name, mtime)
+ self.check_cutoff(member.name, member.mtime)
def check_cutoff(self, name, mtime):
"""Check the timestamp details of the supplied file.
@@ -529,28 +528,27 @@
yield error
def extractAndParseControl(self):
- """Extract and parse tcontrol information."""
- deb_file = open(self.filepath, "r")
+ """Extract and parse control information."""
try:
- control_file = apt_inst.debExtractControl(deb_file)
- control_lines = apt_pkg.ParseSection(control_file)
+ deb_file = apt_inst.DebFile(self.filepath)
+ control_file = deb_file.control.extractdata("control")
+ control_lines = apt_pkg.TagSection(control_file)
except (SystemExit, KeyboardInterrupt):
raise
except:
- deb_file.close()
yield UploadError(
- "%s: debExtractControl() raised %s, giving up."
+ "%s: extracting control file raised %s, giving up."
% (self.filename, sys.exc_type))
return
for mandatory_field in self.mandatory_fields:
- if control_lines.Find(mandatory_field) is None:
+ if control_lines.find(mandatory_field) is None:
yield UploadError(
"%s: control file lacks mandatory field %r"
% (self.filename, mandatory_field))
control = {}
for key in control_lines.keys():
- control[key] = control_lines.Find(key)
+ control[key] = control_lines.find(key)
self.parseControl(control)
def parseControl(self, control):
@@ -718,7 +716,7 @@
if data_tar == "data.tar.xz":
parsed_deps = []
try:
- parsed_deps = apt_pkg.ParseDepends(
+ parsed_deps = apt_pkg.parse_depends(
self.control['Pre-Depends'])
except (ValueError, TypeError):
yield UploadError(
@@ -739,7 +737,7 @@
# VersionCompare returns values similar to cmp;
# negative if first < second, zero if first ==
# second and positive if first > second.
- if apt_pkg.VersionCompare(
+ if apt_pkg.version_compare(
version, XZ_REQUIRED_DPKG_VER) >= 0:
# Pre-Depends dpkg is fine.
return
@@ -765,49 +763,33 @@
tar_checker = TarFileDateChecker(future_cutoff, past_cutoff)
tar_checker.reset()
try:
- deb_file = open(self.filepath, "rb")
- apt_inst.debExtract(deb_file, tar_checker.callback,
- "control.tar.gz")
- # Only one of these files is present in the archive, so loop
- # until we find one of them, otherwise fail.
- data_files = ("data.tar.gz", "data.tar.bz2", "data.tar.lzma",
- "data.tar.xz")
- for file in data_files:
- deb_file.seek(0)
- try:
- apt_inst.debExtract(deb_file, tar_checker.callback, file)
- except SystemError:
- continue
- else:
- deb_file.close()
-
- future_files = tar_checker.future_files.keys()
- if future_files:
- first_file = future_files[0]
- timestamp = time.ctime(
- tar_checker.future_files[first_file])
- yield UploadError(
- "%s: has %s file(s) with a time stamp too "
- "far into the future (e.g. %s [%s])."
- % (self.filename, len(future_files), first_file,
- timestamp))
-
- ancient_files = tar_checker.ancient_files.keys()
- if ancient_files:
- first_file = ancient_files[0]
- timestamp = time.ctime(
- tar_checker.ancient_files[first_file])
- yield UploadError(
- "%s: has %s file(s) with a time stamp too "
- "far in the past (e.g. %s [%s])."
- % (self.filename, len(ancient_files), first_file,
- timestamp))
- return
-
- deb_file.close()
- yield UploadError(
- "Could not find data tarball in %s" % self.filename)
-
+ deb_file = apt_inst.DebFile(self.filepath)
+ except SystemError, error:
+ # We get an error from the constructor if the .deb does not
+ # contain all the expected ar members.
+ yield UploadError(error)
+ try:
+ deb_file.control.go(tar_checker.callback)
+ deb_file.data.go(tar_checker.callback)
+ future_files = tar_checker.future_files.keys()
+ if future_files:
+ first_file = future_files[0]
+ timestamp = time.ctime(tar_checker.future_files[first_file])
+ yield UploadError(
+ "%s: has %s file(s) with a time stamp too "
+ "far into the future (e.g. %s [%s])."
+ % (self.filename, len(future_files), first_file,
+ timestamp))
+
+ ancient_files = tar_checker.ancient_files.keys()
+ if ancient_files:
+ first_file = ancient_files[0]
+ timestamp = time.ctime(tar_checker.ancient_files[first_file])
+ yield UploadError(
+ "%s: has %s file(s) with a time stamp too "
+ "far in the past (e.g. %s [%s])."
+ % (self.filename, len(ancient_files), first_file,
+ timestamp))
except (SystemExit, KeyboardInterrupt):
raise
except Exception, error:
=== modified file 'lib/lp/archiveuploader/tagfiles.py'
--- lib/lp/archiveuploader/tagfiles.py 2011-05-20 07:47:17 +0000
+++ lib/lp/archiveuploader/tagfiles.py 2011-12-14 12:38:23 +0000
@@ -35,7 +35,7 @@
with tempfile.TemporaryFile() as f:
f.write(strip_pgp_signature(content))
f.seek(0)
- stanzas = list(apt_pkg.ParseTagFile(f))
+ stanzas = list(apt_pkg.TagFile(f))
if len(stanzas) != 1:
raise TagFileParseError(
"%s: multiple stanzas where only one is expected" % filename)
=== modified file 'lib/lp/archiveuploader/tests/test_tagfiles.py'
--- lib/lp/archiveuploader/tests/test_tagfiles.py 2011-05-22 23:47:25 +0000
+++ lib/lp/archiveuploader/tests/test_tagfiles.py 2011-12-14 12:38:23 +0000
@@ -82,8 +82,8 @@
tagfile_path = datadir("test436182_0.1_source.changes")
tagfile = open(tagfile_path)
- self.apt_pkg_parsed_version = apt_pkg.ParseTagFile(tagfile)
- self.apt_pkg_parsed_version.Step()
+ self.apt_pkg_parsed_version = apt_pkg.TagFile(tagfile)
+ self.apt_pkg_parsed_version.step()
self.parse_tagfile_version = parse_tagfile(tagfile_path)
@@ -104,7 +104,7 @@
self.assertEqual(
expected_text,
- self.apt_pkg_parsed_version.Section['Binary'])
+ self.apt_pkg_parsed_version.section['Binary'])
self.assertEqual(
expected_text,
@@ -114,8 +114,7 @@
"""parse_tagfile should not leave leading or tailing '\n' when
parsing newline delimited fields.
- Newline-delimited fields should be parsed to match
- apt_pkg.ParseTageFile.
+ Newline-delimited fields should be parsed to match apt_pkg.TagFile.
Note: in the past, our parse_tagfile function left the leading
'\n' in the parsed value, whereas it should not have.
@@ -133,7 +132,7 @@
self.assertEqual(
expected_text,
- self.apt_pkg_parsed_version.Section['Files'])
+ self.apt_pkg_parsed_version.section['Files'])
self.assertEqual(
expected_text,
@@ -158,7 +157,7 @@
self.assertEqual(
expected_text,
- self.apt_pkg_parsed_version.Section['Description'])
+ self.apt_pkg_parsed_version.section['Description'])
# In the past our parse_tagfile function replaced blank-line
# indicators in the description (' .\n') with new lines ('\n'),
=== modified file 'lib/lp/registry/browser/distroseries.py'
--- lib/lp/registry/browser/distroseries.py 2011-11-26 04:03:29 +0000
+++ lib/lp/registry/browser/distroseries.py 2011-12-14 12:38:23 +0000
@@ -1073,7 +1073,7 @@
# The child doesn't have this package. Treat that as the
# parent being newer.
return False
- comparison = apt_pkg.VersionCompare(
+ comparison = apt_pkg.version_compare(
dsd.parent_source_version, dsd.source_version)
return comparison < 0
=== modified file 'lib/lp/registry/browser/sourcepackage.py'
--- lib/lp/registry/browser/sourcepackage.py 2011-09-13 05:23:16 +0000
+++ lib/lp/registry/browser/sourcepackage.py 2011-12-14 12:38:23 +0000
@@ -22,9 +22,9 @@
import urllib
from apt_pkg import (
- ParseSrcDepends,
+ parse_src_depends,
upstream_version,
- VersionCompare,
+ version_compare,
)
from lazr.enum import (
EnumeratedType,
@@ -512,11 +512,11 @@
def _relationship_parser(self, content):
"""Wrap the relationship_builder for SourcePackages.
- Define apt_pkg.ParseSrcDep as a relationship 'parser' and
+ Define apt_pkg.parse_src_depends as a relationship 'parser' and
IDistroSeries.getBinaryPackage as 'getter'.
"""
getter = self.context.distroseries.getBinaryPackage
- parser = ParseSrcDepends
+ parser = parse_src_depends
return relationship_builder(content, parser=parser, getter=getter)
@property
@@ -680,7 +680,7 @@
# Compare the base version contained in the full debian version
# to upstream release's version.
base_version = upstream_version(current_release.version)
- age = VersionCompare(upstream_release.version, base_version)
+ age = version_compare(upstream_release.version, base_version)
if age > 0:
return PackageUpstreamTracking.NEWER
elif age < 0:
=== modified file 'lib/lp/registry/model/distroseries.py'
--- lib/lp/registry/model/distroseries.py 2011-10-18 11:56:34 +0000
+++ lib/lp/registry/model/distroseries.py 2011-12-14 12:38:23 +0000
@@ -1461,7 +1461,7 @@
packagenames)
for spph in spphs:
latest_release = latest_releases.get(spph.meta_sourcepackage)
- if latest_release is not None and apt_pkg.VersionCompare(
+ if latest_release is not None and apt_pkg.version_compare(
latest_release.version, spph.source_package_version) > 0:
version = latest_release
else:
=== modified file 'lib/lp/registry/model/distroseriesdifference.py'
--- lib/lp/registry/model/distroseriesdifference.py 2011-08-31 13:20:28 +0000
+++ lib/lp/registry/model/distroseriesdifference.py 2011-12-14 12:38:23 +0000
@@ -774,7 +774,7 @@
new_source_version = new_parent_source_version = None
if self.source_pub:
new_source_version = self.source_pub.source_package_version
- if self.source_version is None or apt_pkg.VersionCompare(
+ if self.source_version is None or apt_pkg.version_compare(
self.source_version, new_source_version) != 0:
self.source_version = new_source_version
updated = True
@@ -786,7 +786,7 @@
if self.parent_source_pub:
new_parent_source_version = (
self.parent_source_pub.source_package_version)
- if self.parent_source_version is None or apt_pkg.VersionCompare(
+ if self.parent_source_version is None or apt_pkg.version_compare(
self.parent_source_version,
new_parent_source_version) != 0:
self.parent_source_version = new_parent_source_version
@@ -800,13 +800,13 @@
# If this difference was resolved but now the versions don't match
# then we re-open the difference.
if self.status == DistroSeriesDifferenceStatus.RESOLVED:
- if apt_pkg.VersionCompare(
+ if apt_pkg.version_compare(
self.source_version, self.parent_source_version) < 0:
# Higher parent version.
updated = True
self.status = DistroSeriesDifferenceStatus.NEEDS_ATTENTION
elif (
- apt_pkg.VersionCompare(
+ apt_pkg.version_compare(
self.source_version, self.parent_source_version) > 0
and not manual):
# The child was updated with a higher version so it's
@@ -820,12 +820,12 @@
elif self.status in (
DistroSeriesDifferenceStatus.NEEDS_ATTENTION,
DistroSeriesDifferenceStatus.BLACKLISTED_CURRENT):
- if apt_pkg.VersionCompare(
+ if apt_pkg.version_compare(
self.source_version, self.parent_source_version) == 0:
updated = True
self.status = DistroSeriesDifferenceStatus.RESOLVED
elif (
- apt_pkg.VersionCompare(
+ apt_pkg.version_compare(
self.source_version, self.parent_source_version) > 0
and not manual):
# If the derived version is lower than the parent's, we
=== modified file 'lib/lp/soyuz/browser/binarypackagerelease.py'
--- lib/lp/soyuz/browser/binarypackagerelease.py 2011-05-27 21:12:25 +0000
+++ lib/lp/soyuz/browser/binarypackagerelease.py 2011-12-14 12:38:23 +0000
@@ -8,7 +8,7 @@
'BinaryPackageView',
]
-from apt_pkg import ParseDepends
+from apt_pkg import parse_depends
from canonical.launchpad.webapp import Navigation
from lp.soyuz.browser.packagerelationship import relationship_builder
@@ -33,7 +33,7 @@
IDistroArchSeries.getBinaryPackage as 'getter'.
"""
getter = self.context.build.distro_arch_series.getBinaryPackage
- parser = ParseDepends
+ parser = parse_depends
return relationship_builder(content, parser=parser, getter=getter)
def depends(self):
=== modified file 'lib/lp/soyuz/browser/packagerelationship.py'
--- lib/lp/soyuz/browser/packagerelationship.py 2011-05-27 21:12:25 +0000
+++ lib/lp/soyuz/browser/packagerelationship.py 2011-12-14 12:38:23 +0000
@@ -41,6 +41,12 @@
url = canonical_url(target_object)
else:
url = None
+ # The apt_pkg 0.8 API returns '<' and '>' rather than the '<<' and
+ # '>>' form used in control files.
+ if operator == '<':
+ operator = '<<'
+ elif operator == '>':
+ operator = '>>'
relationship_set.add(name, operator, version, url)
return relationship_set
@@ -81,4 +87,3 @@
def __iter__(self):
return iter(sorted(
self.contents, key=std_operator.attrgetter('name')))
-
=== modified file 'lib/lp/soyuz/model/binarypackagebuild.py'
--- lib/lp/soyuz/model/binarypackagebuild.py 2011-11-28 10:28:54 +0000
+++ lib/lp/soyuz/model/binarypackagebuild.py 2011-12-14 12:38:23 +0000
@@ -435,13 +435,18 @@
"It is expected to be a tuple containing only another "
"tuple with 3 elements (name, version, relation)."
% (token, self.title, self.id, self.dependencies))
+ # Map relations to the canonical form used in control files.
+ if relation == '<':
+ relation = '<<'
+ elif relation == '>':
+ relation = '>>'
return (name, version, relation)
def _checkDependencyVersion(self, available, required, relation):
"""Return True if the available version satisfies the context."""
# This dict maps the package version relationship syntax in lambda
# functions which returns boolean according the results of
- # apt_pkg.VersionCompare function (see the order above).
+ # apt_pkg.version_compare function (see the order above).
# For further information about pkg relationship syntax see:
#
# http://www.debian.org/doc/debian-policy/ch-relationships.html
@@ -449,11 +454,11 @@
version_relation_map = {
# any version is acceptable if no relationship is given
'': lambda x: True,
- # stricly later
+ # strictly later
'>>': lambda x: x == 1,
# later or equal
'>=': lambda x: x >= 0,
- # stricly equal
+ # strictly equal
'=': lambda x: x == 0,
# earlier or equal
'<=': lambda x: x <= 0,
@@ -465,7 +470,7 @@
# it behaves similar to cmp, i.e. returns negative
# if first < second, zero if first == second and
# positive if first > second.
- dep_result = apt_pkg.VersionCompare(available, required)
+ dep_result = apt_pkg.version_compare(available, required)
return version_relation_map[relation](dep_result)
@@ -502,12 +507,13 @@
def updateDependencies(self):
"""See `IBuild`."""
- # apt_pkg requires InitSystem to get VersionCompare working properly.
- apt_pkg.InitSystem()
+ # apt_pkg requires init_system to get version_compare working
+ # properly.
+ apt_pkg.init_system()
# Check package build dependencies using apt_pkg
try:
- parsed_deps = apt_pkg.ParseDepends(self.dependencies)
+ parsed_deps = apt_pkg.parse_depends(self.dependencies)
except (ValueError, TypeError):
raise UnparsableDependencies(
"Build dependencies for %s (%s) could not be parsed: '%s'\n"
=== modified file 'lib/lp/soyuz/model/sourcepackagerelease.py'
--- lib/lp/soyuz/model/sourcepackagerelease.py 2011-11-17 11:21:22 +0000
+++ lib/lp/soyuz/model/sourcepackagerelease.py 2011-12-14 12:38:23 +0000
@@ -639,7 +639,7 @@
if self.changelog is None:
return None
- apt_pkg.InitSystem()
+ apt_pkg.init_system()
chunks = []
changelog = self.changelog
# The python-debian API for parsing changelogs is pretty awful. The
@@ -649,7 +649,7 @@
for block in Changelog(changelog.read()):
version = block._raw_version
if (since_version and
- apt_pkg.VersionCompare(version, since_version) <= 0):
+ apt_pkg.version_compare(version, since_version) <= 0):
break
# Poking in private attributes is not nice but again the
# API is terrible. We want to ensure that the name/date
=== modified file 'lib/lp/soyuz/scripts/gina/archive.py'
--- lib/lp/soyuz/scripts/gina/archive.py 2011-08-23 08:17:55 +0000
+++ lib/lp/soyuz/scripts/gina/archive.py 2011-12-14 12:38:23 +0000
@@ -199,10 +199,10 @@
# because most of them are the same for all architectures,
# but we go over it to also cover source packages that only
# compile for one architecture.
- sources = apt_pkg.ParseTagFile(info_set.srcfile)
- while sources.Step():
+ sources = apt_pkg.TagFile(info_set.srcfile)
+ for section in sources:
try:
- src_tmp = dict(sources.Section)
+ src_tmp = dict(section)
src_tmp['Component'] = info_set.component
src_name = src_tmp['Package']
except KeyError:
@@ -222,10 +222,10 @@
tmpbin_map = self.bin_map[info_set.arch]
- binaries = apt_pkg.ParseTagFile(info_set.binfile)
- while binaries.Step():
+ binaries = apt_pkg.TagFile(info_set.binfile)
+ for section in binaries:
try:
- bin_tmp = dict(binaries.Section)
+ bin_tmp = dict(section)
# The component isn't listed in the tagfile.
bin_tmp['Component'] = info_set.component
bin_name = bin_tmp['Package']
@@ -237,10 +237,10 @@
tmpbin_map[bin_name] = bin_tmp
# Run over the D-I stanzas and store info in tmp_bin_map.
- dibinaries = apt_pkg.ParseTagFile(info_set.difile)
- while dibinaries.Step():
+ dibinaries = apt_pkg.TagFile(info_set.difile)
+ for section in dibinaries:
try:
- dibin_tmp = dict(dibinaries.Section)
+ dibin_tmp = dict(section)
dibin_tmp['Component'] = info_set.component
dibin_name = dibin_tmp['Package']
except KeyError:
=== modified file 'lib/lp/soyuz/scripts/packagecopier.py'
--- lib/lp/soyuz/scripts/packagecopier.py 2011-12-02 12:52:05 +0000
+++ lib/lp/soyuz/scripts/packagecopier.py 2011-12-14 12:38:23 +0000
@@ -504,8 +504,8 @@
if ancestry is not None:
ancestry_version = ancestry.sourcepackagerelease.version
copy_version = source.sourcepackagerelease.version
- apt_pkg.InitSystem()
- if apt_pkg.VersionCompare(copy_version, ancestry_version) < 0:
+ apt_pkg.init_system()
+ if apt_pkg.version_compare(copy_version, ancestry_version) < 0:
raise CannotCopy(
"version older than the %s published in %s" %
(ancestry.displayname, ancestry.distroseries.name))
=== modified file 'lib/lp/soyuz/tests/test_publish_archive_indexes.py'
--- lib/lp/soyuz/tests/test_publish_archive_indexes.py 2011-07-27 23:06:20 +0000
+++ lib/lp/soyuz/tests/test_publish_archive_indexes.py 2011-12-14 12:38:23 +0000
@@ -22,7 +22,7 @@
def setUp(self):
"""Setup global attributes."""
TestNativePublishingBase.setUp(self)
- apt_pkg.InitSystem()
+ apt_pkg.init_system()
def testSourceStanza(self):
"""Check just-created source publication Index stanza.
@@ -59,7 +59,7 @@
pub_source.getIndexStanza().splitlines())
def testSourceStanzaCustomFields(self):
- """Check just-created source publication Index stanza
+ """Check just-created source publication Index stanza
with custom fields (Python-Version).
"""
pub_source = self.getPubSource(
@@ -274,13 +274,13 @@
class TestNativeArchiveIndexesReparsing(TestNativePublishingBase):
"""Tests for ensuring the native archive indexes that we publish
- can be parsed correctly by apt_get.ParseTagFiles.
+ can be parsed correctly by apt_pkg.TagFile.
"""
def setUp(self):
"""Setup global attributes."""
TestNativePublishingBase.setUp(self)
- apt_pkg.InitSystem()
+ apt_pkg.init_system()
def write_stanza_and_reparse(self, stanza):
"""Helper method to return the apt_pkg parser for the stanza."""
@@ -289,35 +289,34 @@
index_file.write(stanza.encode('utf-8'))
index_file.close()
- parser = apt_pkg.ParseTagFile(open(index_filename))
+ parser = apt_pkg.TagFile(open(index_filename))
# We're only interested in one stanza, so we'll parse it and remove
# the tmp file again.
- parser.Step()
+ section = next(parser)
os.remove(index_filename)
- return parser
+ return section
def test_getIndexStanza_binary_stanza(self):
"""Check a binary stanza with APT parser."""
pub_binary = self.getPubBinaries()[0]
- parser = self.write_stanza_and_reparse(pub_binary.getIndexStanza())
+ section = self.write_stanza_and_reparse(pub_binary.getIndexStanza())
- self.assertEqual(parser.Section.get('Package'), 'foo-bin')
+ self.assertEqual(section.get('Package'), 'foo-bin')
self.assertEqual(
- parser.Section.get('Description').splitlines(),
+ section.get('Description').splitlines(),
['Foo app is great', ' Well ...', ' it does nothing, though'])
def test_getIndexStanza_source_stanza(self):
"""Check a source stanza with APT parser."""
pub_source = self.getPubSource()
- parser = self.write_stanza_and_reparse(pub_source.getIndexStanza())
+ section = self.write_stanza_and_reparse(pub_source.getIndexStanza())
- self.assertEqual(parser.Section.get('Package'), 'foo')
- self.assertEqual(
- parser.Section.get('Maintainer'), 'Foo Bar <foo@xxxxxxx>')
+ self.assertEqual(section.get('Package'), 'foo')
+ self.assertEqual(section.get('Maintainer'), 'Foo Bar <foo@xxxxxxx>')
def test_getIndexStanza_with_corrupt_dsc_binaries(self):
"""Ensure corrupt binary fields are written correctly to indexes.
@@ -331,11 +330,10 @@
leaves a trailing '\n' (which results in a blank line after the
Binary field).
- The second issue causes apt_pkg.ParseTagFile() to error during
+ The second issue causes apt_pkg.TagFile() to error during
germination when it attempts to parse the generated Sources index.
- But the first issue will also cause apt_pkg.ParseTagFile to
- skip each newline of a multiline field that is not preceded with
- a space.
+ But the first issue will also cause apt_pkg.TagFile to skip each
+ newline of a multiline field that is not preceded with a space.
This test ensures that binary fields saved as such will continue
to be written correctly to index files.
@@ -350,19 +348,18 @@
pub_source.sourcepackagerelease.dsc_binaries = (
'foo_bin,\nbar_bin,\nzed_bin')
- parser = self.write_stanza_and_reparse(pub_source.getIndexStanza())
+ section = self.write_stanza_and_reparse(pub_source.getIndexStanza())
- self.assertEqual('foo', parser.Section['Package'])
+ self.assertEqual('foo', section['Package'])
# Without the fix, this raises a key-error due to apt-pkg not
# being able to parse the file.
self.assertEqual(
- '666', parser.Section['Version'],
+ '666', section['Version'],
'The Version field should be parsed correctly.')
# Without the fix, the second binary would not be parsed at all.
- self.assertEqual(
- 'foo_bin,\n bar_bin,\n zed_bin', parser.Section['Binary'])
+ self.assertEqual('foo_bin,\n bar_bin,\n zed_bin', section['Binary'])
def test_getIndexStanza_with_correct_dsc_binaries(self):
"""Ensure correct binary fields are written correctly to indexes.
@@ -374,9 +371,9 @@
leaves a trailing '\n' (which results in a blank line after the
Binary field).
- This test ensures that when our parser is updated to store
- the binary field in the same way that apt_pkg.ParseTagFiles would,
- that it will continue to be written correctly to index files.
+ This test ensures that when our parser is updated to store the
+ binary field in the same way that apt_pkg.TagFile would, that it
+ will continue to be written correctly to index files.
"""
pub_source = self.getPubSource()
@@ -385,19 +382,18 @@
pub_source.sourcepackagerelease.dsc_binaries = (
'foo_bin,\n bar_bin,\n zed_bin')
- parser = self.write_stanza_and_reparse(pub_source.getIndexStanza())
+ section = self.write_stanza_and_reparse(pub_source.getIndexStanza())
- self.assertEqual('foo', parser.Section['Package'])
+ self.assertEqual('foo', section['Package'])
# Without the fix, this raises a key-error due to apt-pkg not
# being able to parse the file.
self.assertEqual(
- '666', parser.Section['Version'],
+ '666', section['Version'],
'The Version field should be parsed correctly.')
# Without the fix, the second binary would not be parsed at all.
- self.assertEqual(
- 'foo_bin,\n bar_bin,\n zed_bin', parser.Section['Binary'])
+ self.assertEqual('foo_bin,\n bar_bin,\n zed_bin', section['Binary'])
class TestIndexStanzaFieldsHelper(unittest.TestCase):
@@ -409,7 +405,6 @@
Provides an method to format the option in a ready-to-use string.
"""
-
def test_simple(self):
fields = IndexStanzaFields()
fields.append('breakfast', 'coffee')
=== modified file 'lib/lp_sitecustomize.py'
--- lib/lp_sitecustomize.py 2011-09-28 11:31:49 +0000
+++ lib/lp_sitecustomize.py 2011-12-14 12:38:23 +0000
@@ -129,10 +129,6 @@
filter_pattern = '.*(Zope 3.6|provide.*global site manager).*'
warnings.filterwarnings(
'ignore', filter_pattern, category=DeprecationWarning)
- # XXX wgrant 2010-03-30 bug=551510:
- # Also filter apt_pkg warnings, since Lucid's python-apt has a new API.
- warnings.filterwarnings(
- 'ignore', '.*apt_pkg.*', category=DeprecationWarning)
def customize_logger():
=== modified file 'scripts/ftpmaster-tools/sync-source.py'
--- scripts/ftpmaster-tools/sync-source.py 2011-10-15 00:25:33 +0000
+++ scripts/ftpmaster-tools/sync-source.py 2011-12-14 12:38:23 +0000
@@ -121,7 +121,7 @@
is_debian_changelog = 1
if previous_version is None:
previous_version = "9999:9999"
- elif apt_pkg.VersionCompare(
+ elif apt_pkg.version_compare(
match.group('version'), previous_version) > 0:
urgency = max(
urgency_to_numeric(match.group('urgency')), urgency)
@@ -192,13 +192,13 @@
raise LaunchpadScriptFailure(
"debian/control not found in extracted source.")
control_filehandle = open(control_filename)
- Control = apt_pkg.ParseTagFile(control_filehandle)
- while Control.Step():
- source = Control.Section.Find("Source")
- package = Control.Section.Find("Package")
- section = Control.Section.Find("Section")
- priority = Control.Section.Find("Priority")
- description = Control.Section.Find("Description")
+ control = apt_pkg.TagFile(control_filehandle)
+ for control_section in control:
+ source = control_section.find("Source")
+ package = control_section.find("Package")
+ section = control_section.find("Section")
+ priority = control_section.find("Priority")
+ description = control_section.find("Description")
if source is not None:
if section is not None:
source_section = section
@@ -398,7 +398,7 @@
if pkg not in S:
S[pkg] = [version, component]
else:
- if apt_pkg.VersionCompare(S[pkg][0], version) < 0:
+ if apt_pkg.version_compare(S[pkg][0], version) < 0:
Log.warning(
"%s: skipping because %s is < %s" % (
pkg, version, S[pkg][0]))
@@ -434,7 +434,7 @@
# if pkg not in B:
# B[pkg] = [version, component]
# else:
- # if apt_pkg.VersionCompare(B[pkg][0], version) < 0:
+ # if apt_pkg.version_compare(B[pkg][0], version) < 0:
# B[pkg] = [version, component]
# XXX James Troup 2006-02-22: so... let's fall back on raw SQL
@@ -462,7 +462,7 @@
if pkg not in B:
B[pkg] = [version, component]
else:
- if apt_pkg.VersionCompare(B[pkg][0], version) < 0:
+ if apt_pkg.version_compare(B[pkg][0], version) < 0:
B[pkg] = [version, component]
return B
@@ -479,21 +479,21 @@
filename = "%s%s%s_%s" % (origin["name"], suite, component, filename)
sources_filehandle = open(filename)
- Sources = apt_pkg.ParseTagFile(sources_filehandle)
- while Sources.Step():
- pkg = Sources.Section.Find("Package")
- version = Sources.Section.Find("Version")
+ sources = apt_pkg.TagFile(sources_filehandle)
+ for sources_section in sources:
+ pkg = sources_section.find("Package")
+ version = sources_section.find("Version")
- if pkg in S and apt_pkg.VersionCompare(
+ if pkg in S and apt_pkg.version_compare(
S[pkg]["version"], version) > 0:
continue
S[pkg] = {}
S[pkg]["version"] = version
- directory = Sources.Section.Find("Directory", "")
+ directory = sources_section.find("Directory", "")
files = {}
- for line in Sources.Section.Find("Files").split('\n'):
+ for line in sources_section.find("Files").split('\n'):
(md5sum, size, filename) = line.strip().split()
files[filename] = {}
files[filename]["md5sum"] = md5sum
@@ -577,7 +577,7 @@
source_version = Sources[pkg]["version"]
if (dest_version is None
- or apt_pkg.VersionCompare(dest_version, source_version) < 0):
+ or apt_pkg.version_compare(dest_version, source_version) < 0):
if (dest_version is not None
and (not Options.force
and dest_version.find("ubuntu") != -1)):
Follow ups