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
=== modified file 'upstream.py'
--- upstream.py 2010-04-22 10:54:52 +0000
+++ upstream.py 2010-05-24 01:50:40 +0000
@@ -111,21 +111,27 @@
111 apt_pkg = _apt_pkg111 apt_pkg = _apt_pkg
112 apt_pkg.init()112 apt_pkg.init()
113113
114 def get_fn(obj, new_name, old_name):
115 try:
116 return getattr(obj, new_name)
117 except AttributeError:
118 return getattr(obj, old_name)
119
114 # Handle the case where the apt.sources file contains no source120 # Handle the case where the apt.sources file contains no source
115 # URIs (LP:375897)121 # URIs (LP:375897)
116 try:122 try:
117 get_sources = getattr(apt_pkg, 'SourceRecords',123 get_sources = get_fn(apt_pkg, 'SourceRecords',
118 getattr(apt_pkg, 'GetPkgSrcRecords', None))124 "GetPkgSrcRecords")
119 sources = get_sources()125 sources = get_sources()
120 except SystemError:126 except SystemError:
121 raise PackageVersionNotPresent(package, upstream_version, self)127 raise PackageVersionNotPresent(package, upstream_version, self)
122128
123 restart = getattr(sources, 'restart', getattr(sources, 'Restart', None))129 restart = get_fn(sources, 'restart', 'Restart')
124 restart()130 restart()
125 note("Using apt to look for the upstream tarball.")131 note("Using apt to look for the upstream tarball.")
126 lookup = getattr(sources, 'lookup', getattr(sources, 'Lookup', None))132 lookup = get_fn(sources, 'lookup', 'Lookup')
127 while lookup(package):133 while lookup(package):
128 version = getattr(sources, 'version', getattr(sources, 'Version', None))134 version = get_fn(sources, 'version', 'Version')
129 if upstream_version == Version(version).upstream_version:135 if upstream_version == Version(version).upstream_version:
130 if self._run_apt_source(package, version, target_dir):136 if self._run_apt_source(package, version, target_dir):
131 return137 return

Subscribers

People subscribed via source and target branches