Merge lp:~jelmer/bzr-builddeb/lp-tar-source into lp:bzr-builddeb

Proposed by Jelmer Vernooij
Status: Merged
Approved by: James Westby
Approved revision: 570
Merged at revision: 574
Proposed branch: lp:~jelmer/bzr-builddeb/lp-tar-source
Merge into: lp:bzr-builddeb
Diff against target: 239 lines (+127/-23)
4 files modified
cmds.py (+6/-4)
launchpad.py (+40/-18)
repack_tarball.py (+1/-1)
upstream/__init__.py (+80/-0)
To merge this branch: bzr merge lp:~jelmer/bzr-builddeb/lp-tar-source
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+64348@code.launchpad.net

Description of the change

Add an upstream branch source that uses the upstream tarballs registered on Launchpad.

I've tested this manually here, but as with any launchpadlib code, it's hard to test as part of a testsuite. :-/

At this point it's not hooked up yet, as I wasn't sure where we should put it, and whether it should only be enabled if --launchpad is specified.

To post a comment you must log in.
Revision history for this message
James Westby (james-w) wrote :

I guess we'll have to live with it not being tested.

Thanks,

James

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cmds.py'
2--- cmds.py 2011-06-03 12:17:42 +0000
3+++ cmds.py 2011-06-12 22:45:52 +0000
4@@ -747,9 +747,10 @@
5 version, upstream_branch, upstream_revision, v3,
6 location)
7 conflicts = self._do_merge(tree, tarball_filename, package,
8- version, current_version, upstream_branch, upstream_revision,
9- merge_type, force)
10- if current_version is not None and Version(current_version) >= Version(version):
11+ version, current_version, upstream_branch,
12+ upstream_revision, merge_type, force)
13+ if (current_version is not None and
14+ Version(current_version) >= Version(version)):
15 raise BzrCommandError(
16 "Upstream version %s has already been merged." % version)
17 if not tree.has_filename("debian"):
18@@ -765,7 +766,8 @@
19 else:
20 note("The new upstream version has been imported.")
21 if conflicts:
22- note("You should now resolve the conflicts, review the changes, and then commit.")
23+ note("You should now resolve the conflicts, review the "
24+ "changes, and then commit.")
25 else:
26 note("You should now review the changes and then commit.")
27
28
29=== modified file 'launchpad.py'
30--- launchpad.py 2011-03-29 20:44:00 +0000
31+++ launchpad.py 2011-06-12 22:45:52 +0000
32@@ -1,4 +1,4 @@
33-# test_util.py -- Lookups via. launchpadlib
34+# launchpad.py -- Lookups via. launchpadlib
35 # Copyright (C) 2009 Canonical Ltd.
36 #
37 # This file is part of bzr-builddeb.
38@@ -35,7 +35,9 @@
39 HAVE_LPLIB = False
40
41
42-def _get_launchpad():
43+def get_launchpad():
44+ if not HAVE_LPLIB:
45+ return None
46 try:
47 return Launchpad.login_anonymously("bzr-builddeb",
48 service_root=LPNET_SERVICE_ROOT)
49@@ -53,9 +55,12 @@
50
51
52 def ubuntu_bugs_for_debian_bug(bug_id):
53- if not HAVE_LPLIB:
54- return []
55- lp = _get_launchpad()
56+ """Find Ubuntu bugs linked to a particular Debian bug.
57+
58+ :param bug_id: Debian bug id
59+ :return: Liust of Launchpad bug ids for Ubuntu bugs
60+ """
61+ lp = get_launchpad()
62 if lp is None:
63 return []
64 try:
65@@ -71,9 +76,12 @@
66
67
68 def debian_bugs_for_ubuntu_bug(bug_id):
69- if not HAVE_LPLIB:
70- return []
71- lp = _get_launchpad()
72+ """Find the Debian bugs linked to a particular Ubuntu bug.
73+
74+ :param bug_id: The Launchpad bug ID for the Ubuntu bug
75+ :return: List of Debian bug URLs.
76+ """
77+ lp = get_launchpad()
78 if lp is None:
79 return []
80 try:
81@@ -91,16 +99,15 @@
82 return []
83
84
85-def get_upstream_branch_url(package, distribution_name, distroseries_name):
86- """Return the upstream branch URL based on a package in a distribution.
87+def get_upstream_projectseries_for_package(package, distribution_name, distroseries_name):
88+ """Return the upstream project series for a package.
89
90+ :param package: Package name
91 :param distribution_name: Distribution name
92- :param package: Source package name
93- :param distroseries_name: Distroseries name
94+ :param distroseries_name: Distribution series name
95+ :return: Launchpad object for the upstream project series
96 """
97- if not HAVE_LPLIB:
98- return None
99- lp = _get_launchpad()
100+ lp = get_launchpad()
101 if lp is None:
102 return None
103 distribution = lp.distributions[distribution_name]
104@@ -121,9 +128,24 @@
105 note("%s: Source package %s in %s not linked to a product series" % (
106 distribution_name, package, sourcepackage))
107 return None
108- branch = productseries.branch
109+ return productseries
110+
111+
112+def get_upstream_branch_url(package, distribution_name, distroseries_name):
113+ """Return the upstream branch URL based on a package in a distribution.
114+
115+ :param distribution_name: Distribution name
116+ :param package: Source package name
117+ :param distroseries_name: Distroseries name
118+ """
119+ projectseries = get_upstream_projectseries_for_package(
120+ package, distribution_name, distroseries_name)
121+ if projectseries is None:
122+ return
123+ branch = projectseries.branch
124 if branch is None:
125- note(("%s: upstream product series %s for source package %s does not have "
126- "a branch") % (distribution_name, distroseries, package))
127+ note(("%s: upstream project series %s for source package %s does "
128+ "not have a branch") % (distribution_name, distroseries_name,
129+ package))
130 return None
131 return branch.bzr_identity
132
133=== modified file 'repack_tarball.py'
134--- repack_tarball.py 2010-08-19 00:15:35 +0000
135+++ repack_tarball.py 2011-06-12 22:45:52 +0000
136@@ -208,7 +208,7 @@
137 The source must exist, and the target cannot exist, unless it is identical
138 to the source.
139
140- :param source_name: the curent name of the file/dir
141+ :param source_name: the current name of the file/dir
142 :type source_name: string
143 :param new_name: the desired name of the tarball
144 :type new_name: string
145
146=== modified file 'upstream/__init__.py'
147--- upstream/__init__.py 2011-06-03 12:17:42 +0000
148+++ upstream/__init__.py 2011-06-12 22:45:52 +0000
149@@ -31,6 +31,7 @@
150 # Prior to 0.1.15 the debian module was called debian_bundle
151 from debian_bundle.changelog import Version
152
153+from bzrlib import osutils
154 from bzrlib.trace import (
155 note,
156 warning,
157@@ -475,3 +476,82 @@
158 if self.version is not None:
159 return self.version
160 return extract_tarball_version(self.path, package)
161+
162+
163+class LaunchpadReleaseFileSource(UpstreamSource):
164+ """Source that retrieves release files from Launchpad."""
165+
166+ @classmethod
167+ def from_package(cls, distribution_name, distroseries_name, package):
168+ """Create a LaunchpadReleaseFileSource from a distribution package.
169+
170+ :param distribution_name: Name of the distribution (e.g. "Ubuntu")
171+ :param distroseries_name: Name of the distribution series
172+ (e.g. "oneiric")
173+ :param package: Package name
174+ :return: A `LaunchpadReleaseFileSource`
175+ """
176+ from bzrlib.plugins.builddeb.launchpad import (
177+ get_upstream_projectseries_for_package,
178+ )
179+ project_series = get_upstream_projectseries_for_package(
180+ package, distribution_name, distroseries_name)
181+ if project_series is None:
182+ return None
183+ return cls(project_series=project_series)
184+
185+ def __init__(self, project=None, project_series=None):
186+ if project_series is None:
187+ self.project_series = project.development_focus
188+ else:
189+ self.project_series = project_series
190+ if project is None:
191+ self.project = project_series.project
192+ else:
193+ self.project = project
194+
195+ def fetch_tarball(self, package, version, target_dir):
196+ release = self.project.getRelease(version=version)
197+ if release is None:
198+ raise PackageVersionNotPresent(package, version, self)
199+ release_files = []
200+ for f in release.files:
201+ if f.file_type == "Code Release Tarball":
202+ release_files.append(f.file)
203+ if len(release_files) == 0:
204+ warning("Release %s for package %s found on Launchpad but no "
205+ "associated tarballs.", version, package)
206+ raise PackageVersionNotPresent(package, version, self)
207+ elif len(release_files) > 1:
208+ warning("More than one release file for release %s of package %s"
209+ "found on Launchpad. Using the first.", version, package)
210+ hosted_file = release_files[0]
211+ dest_name = tarball_name(package, version)
212+ tmpdir = tempfile.mkdtemp(prefix="builddeb-get-orig-source-")
213+ try:
214+ inf = hosted_file.open()
215+ try:
216+ note("Downloading upstream tarball %s from Launchpad",
217+ inf.filename)
218+ filename = inf.filename.encode(osutils._fs_enc)
219+ filename = filename.replace("/", "")
220+ tmppath = os.path.join(tmpdir, filename)
221+ outf = open(tmppath, 'wb')
222+ try:
223+ outf.write(inf.read())
224+ finally:
225+ outf.close()
226+ finally:
227+ inf.close()
228+ repack_tarball(tmppath, dest_name, target_dir=target_dir,
229+ force_gz=True)
230+ return os.path.join(target_dir, dest_name)
231+ finally:
232+ shutil.rmtree(tmpdir)
233+
234+ def get_latest_version(self, package, version):
235+ versions = []
236+ for release in self.project_series.releases:
237+ versions.append((release.date_released, release.version))
238+ versions.sort()
239+ return versions[-1][1].encode("utf-8")

Subscribers

People subscribed via source and target branches