Merge lp:~jelmer/bzr-builddeb/apt-deprecated into lp:bzr-builddeb

Proposed by Jelmer Vernooij
Status: Merged
Merged at revision: 456
Proposed branch: lp:~jelmer/bzr-builddeb/apt-deprecated
Merge into: lp:bzr-builddeb
Diff against target: 36 lines (+11/-5)
1 file modified
upstream.py (+11/-5)
To merge this branch: bzr merge lp:~jelmer/bzr-builddeb/apt-deprecated
Reviewer Review Type Date Requested Status
Bzr-builddeb-hackers Pending
Review via email: mp+25846@code.launchpad.net

Description of the change

Another (and hopefully the last) branch to cope with some renames in the apt API. Previously we would could the right API functions but we would still obtain a reference to the functions by their older names, which triggers a deprecation warning on newer versions of python-apt.

This changes the code to only attempt to get a reference to the older name if the newer name is not available.

To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote :

Can I suggest a helper function?

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

see updated

453. By Jelmer Vernooij

Use helper function.

Revision history for this message
Robert Collins (lifeless) wrote :

Much nicer, I think.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'upstream.py'
2--- upstream.py 2010-04-22 10:54:52 +0000
3+++ upstream.py 2010-05-24 01:50:40 +0000
4@@ -111,21 +111,27 @@
5 apt_pkg = _apt_pkg
6 apt_pkg.init()
7
8+ def get_fn(obj, new_name, old_name):
9+ try:
10+ return getattr(obj, new_name)
11+ except AttributeError:
12+ return getattr(obj, old_name)
13+
14 # Handle the case where the apt.sources file contains no source
15 # URIs (LP:375897)
16 try:
17- get_sources = getattr(apt_pkg, 'SourceRecords',
18- getattr(apt_pkg, 'GetPkgSrcRecords', None))
19+ get_sources = get_fn(apt_pkg, 'SourceRecords',
20+ "GetPkgSrcRecords")
21 sources = get_sources()
22 except SystemError:
23 raise PackageVersionNotPresent(package, upstream_version, self)
24
25- restart = getattr(sources, 'restart', getattr(sources, 'Restart', None))
26+ restart = get_fn(sources, 'restart', 'Restart')
27 restart()
28 note("Using apt to look for the upstream tarball.")
29- lookup = getattr(sources, 'lookup', getattr(sources, 'Lookup', None))
30+ lookup = get_fn(sources, 'lookup', 'Lookup')
31 while lookup(package):
32- version = getattr(sources, 'version', getattr(sources, 'Version', None))
33+ version = get_fn(sources, 'version', 'Version')
34 if upstream_version == Version(version).upstream_version:
35 if self._run_apt_source(package, version, target_dir):
36 return

Subscribers

People subscribed via source and target branches