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
=== modified file 'cmds.py'
--- cmds.py 2011-06-03 12:17:42 +0000
+++ cmds.py 2011-06-12 22:45:52 +0000
@@ -747,9 +747,10 @@
747 version, upstream_branch, upstream_revision, v3,747 version, upstream_branch, upstream_revision, v3,
748 location)748 location)
749 conflicts = self._do_merge(tree, tarball_filename, package,749 conflicts = self._do_merge(tree, tarball_filename, package,
750 version, current_version, upstream_branch, upstream_revision,750 version, current_version, upstream_branch,
751 merge_type, force)751 upstream_revision, merge_type, force)
752 if current_version is not None and Version(current_version) >= Version(version):752 if (current_version is not None and
753 Version(current_version) >= Version(version)):
753 raise BzrCommandError(754 raise BzrCommandError(
754 "Upstream version %s has already been merged." % version)755 "Upstream version %s has already been merged." % version)
755 if not tree.has_filename("debian"):756 if not tree.has_filename("debian"):
@@ -765,7 +766,8 @@
765 else:766 else:
766 note("The new upstream version has been imported.")767 note("The new upstream version has been imported.")
767 if conflicts:768 if conflicts:
768 note("You should now resolve the conflicts, review the changes, and then commit.")769 note("You should now resolve the conflicts, review the "
770 "changes, and then commit.")
769 else:771 else:
770 note("You should now review the changes and then commit.")772 note("You should now review the changes and then commit.")
771773
772774
=== modified file 'launchpad.py'
--- launchpad.py 2011-03-29 20:44:00 +0000
+++ launchpad.py 2011-06-12 22:45:52 +0000
@@ -1,4 +1,4 @@
1# test_util.py -- Lookups via. launchpadlib1# launchpad.py -- Lookups via. launchpadlib
2# Copyright (C) 2009 Canonical Ltd.2# Copyright (C) 2009 Canonical Ltd.
3#3#
4# This file is part of bzr-builddeb.4# This file is part of bzr-builddeb.
@@ -35,7 +35,9 @@
35 HAVE_LPLIB = False35 HAVE_LPLIB = False
3636
3737
38def _get_launchpad():38def get_launchpad():
39 if not HAVE_LPLIB:
40 return None
39 try:41 try:
40 return Launchpad.login_anonymously("bzr-builddeb",42 return Launchpad.login_anonymously("bzr-builddeb",
41 service_root=LPNET_SERVICE_ROOT)43 service_root=LPNET_SERVICE_ROOT)
@@ -53,9 +55,12 @@
5355
5456
55def ubuntu_bugs_for_debian_bug(bug_id):57def ubuntu_bugs_for_debian_bug(bug_id):
56 if not HAVE_LPLIB:58 """Find Ubuntu bugs linked to a particular Debian bug.
57 return []59
58 lp = _get_launchpad()60 :param bug_id: Debian bug id
61 :return: Liust of Launchpad bug ids for Ubuntu bugs
62 """
63 lp = get_launchpad()
59 if lp is None:64 if lp is None:
60 return []65 return []
61 try:66 try:
@@ -71,9 +76,12 @@
7176
7277
73def debian_bugs_for_ubuntu_bug(bug_id):78def debian_bugs_for_ubuntu_bug(bug_id):
74 if not HAVE_LPLIB:79 """Find the Debian bugs linked to a particular Ubuntu bug.
75 return []80
76 lp = _get_launchpad()81 :param bug_id: The Launchpad bug ID for the Ubuntu bug
82 :return: List of Debian bug URLs.
83 """
84 lp = get_launchpad()
77 if lp is None:85 if lp is None:
78 return []86 return []
79 try:87 try:
@@ -91,16 +99,15 @@
91 return []99 return []
92100
93101
94def get_upstream_branch_url(package, distribution_name, distroseries_name):102def get_upstream_projectseries_for_package(package, distribution_name, distroseries_name):
95 """Return the upstream branch URL based on a package in a distribution.103 """Return the upstream project series for a package.
96104
105 :param package: Package name
97 :param distribution_name: Distribution name106 :param distribution_name: Distribution name
98 :param package: Source package name107 :param distroseries_name: Distribution series name
99 :param distroseries_name: Distroseries name108 :return: Launchpad object for the upstream project series
100 """109 """
101 if not HAVE_LPLIB:110 lp = get_launchpad()
102 return None
103 lp = _get_launchpad()
104 if lp is None:111 if lp is None:
105 return None112 return None
106 distribution = lp.distributions[distribution_name]113 distribution = lp.distributions[distribution_name]
@@ -121,9 +128,24 @@
121 note("%s: Source package %s in %s not linked to a product series" % (128 note("%s: Source package %s in %s not linked to a product series" % (
122 distribution_name, package, sourcepackage))129 distribution_name, package, sourcepackage))
123 return None130 return None
124 branch = productseries.branch131 return productseries
132
133
134def get_upstream_branch_url(package, distribution_name, distroseries_name):
135 """Return the upstream branch URL based on a package in a distribution.
136
137 :param distribution_name: Distribution name
138 :param package: Source package name
139 :param distroseries_name: Distroseries name
140 """
141 projectseries = get_upstream_projectseries_for_package(
142 package, distribution_name, distroseries_name)
143 if projectseries is None:
144 return
145 branch = projectseries.branch
125 if branch is None:146 if branch is None:
126 note(("%s: upstream product series %s for source package %s does not have "147 note(("%s: upstream project series %s for source package %s does "
127 "a branch") % (distribution_name, distroseries, package))148 "not have a branch") % (distribution_name, distroseries_name,
149 package))
128 return None150 return None
129 return branch.bzr_identity151 return branch.bzr_identity
130152
=== modified file 'repack_tarball.py'
--- repack_tarball.py 2010-08-19 00:15:35 +0000
+++ repack_tarball.py 2011-06-12 22:45:52 +0000
@@ -208,7 +208,7 @@
208 The source must exist, and the target cannot exist, unless it is identical208 The source must exist, and the target cannot exist, unless it is identical
209 to the source.209 to the source.
210210
211 :param source_name: the curent name of the file/dir211 :param source_name: the current name of the file/dir
212 :type source_name: string212 :type source_name: string
213 :param new_name: the desired name of the tarball213 :param new_name: the desired name of the tarball
214 :type new_name: string214 :type new_name: string
215215
=== modified file 'upstream/__init__.py'
--- upstream/__init__.py 2011-06-03 12:17:42 +0000
+++ upstream/__init__.py 2011-06-12 22:45:52 +0000
@@ -31,6 +31,7 @@
31 # Prior to 0.1.15 the debian module was called debian_bundle31 # Prior to 0.1.15 the debian module was called debian_bundle
32 from debian_bundle.changelog import Version32 from debian_bundle.changelog import Version
3333
34from bzrlib import osutils
34from bzrlib.trace import (35from bzrlib.trace import (
35 note,36 note,
36 warning,37 warning,
@@ -475,3 +476,82 @@
475 if self.version is not None:476 if self.version is not None:
476 return self.version477 return self.version
477 return extract_tarball_version(self.path, package)478 return extract_tarball_version(self.path, package)
479
480
481class LaunchpadReleaseFileSource(UpstreamSource):
482 """Source that retrieves release files from Launchpad."""
483
484 @classmethod
485 def from_package(cls, distribution_name, distroseries_name, package):
486 """Create a LaunchpadReleaseFileSource from a distribution package.
487
488 :param distribution_name: Name of the distribution (e.g. "Ubuntu")
489 :param distroseries_name: Name of the distribution series
490 (e.g. "oneiric")
491 :param package: Package name
492 :return: A `LaunchpadReleaseFileSource`
493 """
494 from bzrlib.plugins.builddeb.launchpad import (
495 get_upstream_projectseries_for_package,
496 )
497 project_series = get_upstream_projectseries_for_package(
498 package, distribution_name, distroseries_name)
499 if project_series is None:
500 return None
501 return cls(project_series=project_series)
502
503 def __init__(self, project=None, project_series=None):
504 if project_series is None:
505 self.project_series = project.development_focus
506 else:
507 self.project_series = project_series
508 if project is None:
509 self.project = project_series.project
510 else:
511 self.project = project
512
513 def fetch_tarball(self, package, version, target_dir):
514 release = self.project.getRelease(version=version)
515 if release is None:
516 raise PackageVersionNotPresent(package, version, self)
517 release_files = []
518 for f in release.files:
519 if f.file_type == "Code Release Tarball":
520 release_files.append(f.file)
521 if len(release_files) == 0:
522 warning("Release %s for package %s found on Launchpad but no "
523 "associated tarballs.", version, package)
524 raise PackageVersionNotPresent(package, version, self)
525 elif len(release_files) > 1:
526 warning("More than one release file for release %s of package %s"
527 "found on Launchpad. Using the first.", version, package)
528 hosted_file = release_files[0]
529 dest_name = tarball_name(package, version)
530 tmpdir = tempfile.mkdtemp(prefix="builddeb-get-orig-source-")
531 try:
532 inf = hosted_file.open()
533 try:
534 note("Downloading upstream tarball %s from Launchpad",
535 inf.filename)
536 filename = inf.filename.encode(osutils._fs_enc)
537 filename = filename.replace("/", "")
538 tmppath = os.path.join(tmpdir, filename)
539 outf = open(tmppath, 'wb')
540 try:
541 outf.write(inf.read())
542 finally:
543 outf.close()
544 finally:
545 inf.close()
546 repack_tarball(tmppath, dest_name, target_dir=target_dir,
547 force_gz=True)
548 return os.path.join(target_dir, dest_name)
549 finally:
550 shutil.rmtree(tmpdir)
551
552 def get_latest_version(self, package, version):
553 versions = []
554 for release in self.project_series.releases:
555 versions.append((release.date_released, release.version))
556 versions.sort()
557 return versions[-1][1].encode("utf-8")

Subscribers

People subscribed via source and target branches