Merge lp:~jelmer/bzr-builddeb/multiple-upstream-tarballs-pt1 into lp:bzr-builddeb

Proposed by Jelmer Vernooij
Status: Merged
Approved by: James Westby
Approved revision: 573
Merged at revision: 570
Proposed branch: lp:~jelmer/bzr-builddeb/multiple-upstream-tarballs-pt1
Merge into: lp:bzr-builddeb
Diff against target: 601 lines (+141/-105)
8 files modified
cmds.py (+30/-24)
dh_make.py (+11/-5)
errors.py (+4/-3)
source_distiller.py (+6/-2)
tests/test_upstream.py (+33/-18)
upstream/__init__.py (+55/-51)
upstream/branch.py (+1/-1)
upstream/pristinetar.py (+1/-1)
To merge this branch: bzr merge lp:~jelmer/bzr-builddeb/multiple-upstream-tarballs-pt1
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+64551@code.launchpad.net

Description of the change

Initial work on supporting multiple upstream tarballs in bzr-builddeb.

This updates the UpstreamSource interface to return multiple paths for upstream tarballs and updates the AptSource and GetOrigSource implementations to actually return multiple tarballs.

Merging multiple upstream tarballs and extracting/committing multiple upstream tarballs in pristine tar branches are the next steps.

To post a comment you must log in.
Revision history for this message
James Westby (james-w) :
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-14 14:11:23 +0000
@@ -69,6 +69,7 @@
69 BuildFailedError,69 BuildFailedError,
70 DchError,70 DchError,
71 MissingChangelogError,71 MissingChangelogError,
72 MultipleUpstreamTarballsNotSupported,
72 NoPreviousUpload,73 NoPreviousUpload,
73 PackageVersionNotPresent,74 PackageVersionNotPresent,
74 StrictBuildFailed,75 StrictBuildFailed,
@@ -553,45 +554,50 @@
553 'merge had completed failed. Add the new changelog '554 'merge had completed failed. Add the new changelog '
554 'entry yourself, review the merge, and then commit.')555 'entry yourself, review the merge, and then commit.')
555556
556 def _do_merge(self, tree, tarball_filename, package, version,557 def _do_merge(self, tree, tarball_filenames, package, version,
557 current_version, upstream_branch, upstream_revision, merge_type,558 current_version, upstream_branch, upstream_revision, merge_type,
558 force):559 force):
559 db = DistributionBranch(tree.branch, None, tree=tree)560 db = DistributionBranch(tree.branch, None, tree=tree)
560 dbs = DistributionBranchSet()561 dbs = DistributionBranchSet()
561 dbs.add_branch(db)562 dbs.add_branch(db)
562 conflicts = db.merge_upstream(tarball_filename, package, version,563 if len(tarball_filenames) > 1:
564 raise MultipleUpstreamTarballsNotSupported()
565 conflicts = db.merge_upstream(tarball_filenames[0], package, version,
563 current_version, upstream_branch=upstream_branch,566 current_version, upstream_branch=upstream_branch,
564 upstream_revision=upstream_revision,567 upstream_revision=upstream_revision,
565 merge_type=merge_type, force=force)568 merge_type=merge_type, force=force)
566 return conflicts569 return conflicts
567570
568 def _fetch_tarball(self, package, version, orig_dir, location, v3):571 def _fetch_tarball(self, package, version, orig_dir, locations, v3):
569 from bzrlib.plugins.builddeb.repack_tarball import repack_tarball572 from bzrlib.plugins.builddeb.repack_tarball import repack_tarball
573 ret = []
570 format = None574 format = None
571 if v3:575 for location in locations:
572 if location.endswith(".tar.bz2") or location.endswith(".tbz2"):576 if v3:
573 format = "bz2"577 if location.endswith(".tar.bz2") or location.endswith(".tbz2"):
574 dest_name = tarball_name(package, version, format=format)578 format = "bz2"
575 tarball_filename = os.path.join(orig_dir, dest_name)579 dest_name = tarball_name(package, version, format=format)
576 try:580 tarball_filename = os.path.join(orig_dir, dest_name)
577 repack_tarball(location, dest_name, target_dir=orig_dir,581 try:
578 force_gz=not v3)582 repack_tarball(location, dest_name, target_dir=orig_dir,
579 except FileExists:583 force_gz=not v3)
580 raise BzrCommandError("The target file %s already exists, and is either "584 except FileExists:
581 "different to the new upstream tarball, or they "585 raise BzrCommandError("The target file %s already exists, and is either "
582 "are of different formats. Either delete the target "586 "different to the new upstream tarball, or they "
583 "file, or use it as the argument to import."587 "are of different formats. Either delete the target "
584 % dest_name)588 "file, or use it as the argument to import."
585 return tarball_filename589 % dest_name)
590 ret.append(tarball_filename)
591 return ret
586592
587 def _get_tarball(self, config, tree, package, version, upstream_branch,593 def _get_tarball(self, config, tree, package, version, upstream_branch,
588 upstream_revision, v3, location):594 upstream_revision, v3, locations):
589 orig_dir = config.orig_dir or default_orig_dir595 orig_dir = config.orig_dir or default_orig_dir
590 orig_dir = os.path.join(tree.basedir, orig_dir)596 orig_dir = os.path.join(tree.basedir, orig_dir)
591 if not os.path.exists(orig_dir):597 if not os.path.exists(orig_dir):
592 os.makedirs(orig_dir)598 os.makedirs(orig_dir)
593 return self._fetch_tarball(package, version, orig_dir,599 return self._fetch_tarball(package, version, orig_dir,
594 location, v3)600 locations, v3)
595601
596 def _get_changelog_info(self, tree, last_version, package, distribution):602 def _get_changelog_info(self, tree, last_version, package, distribution):
597 current_version = last_version603 current_version = last_version
@@ -738,15 +744,15 @@
738 (version, upstream_branch_source))744 (version, upstream_branch_source))
739 if need_upstream_tarball:745 if need_upstream_tarball:
740 target_dir = tempfile.mkdtemp() # FIXME: Cleanup?746 target_dir = tempfile.mkdtemp() # FIXME: Cleanup?
741 location = primary_upstream_source.fetch_tarball(747 locations = primary_upstream_source.fetch_tarball(
742 package, version, target_dir)748 package, version, target_dir)
743 source_format = get_source_format(tree)749 source_format = get_source_format(tree)
744 v3 = (source_format in [750 v3 = (source_format in [
745 FORMAT_3_0_QUILT, FORMAT_3_0_NATIVE])751 FORMAT_3_0_QUILT, FORMAT_3_0_NATIVE])
746 tarball_filename = self._get_tarball(config, tree, package,752 tarball_filenames = self._get_tarball(config, tree, package,
747 version, upstream_branch, upstream_revision, v3,753 version, upstream_branch, upstream_revision, v3,
748 location)754 locations)
749 conflicts = self._do_merge(tree, tarball_filename, package,755 conflicts = self._do_merge(tree, tarball_filenames, package,
750 version, current_version, upstream_branch, upstream_revision,756 version, current_version, upstream_branch, upstream_revision,
751 merge_type, force)757 merge_type, force)
752 if current_version is not None and Version(current_version) >= Version(version):758 if current_version is not None and Version(current_version) >= Version(version):
753759
=== modified file 'dh_make.py'
--- dh_make.py 2011-02-02 18:33:23 +0000
+++ dh_make.py 2011-06-14 14:11:23 +0000
@@ -13,6 +13,7 @@
1313
14from bzrlib.plugins.builddeb import (14from bzrlib.plugins.builddeb import (
15 default_orig_dir,15 default_orig_dir,
16 errors,
16 import_dsc,17 import_dsc,
17 upstream,18 upstream,
18 util,19 util,
@@ -50,7 +51,7 @@
50 return tree51 return tree
5152
5253
53def _get_tarball(tree, tarball, package_name, version, use_v3=False):54def _get_tarballs(tree, tarball, package_name, version, use_v3=False):
54 from bzrlib.plugins.builddeb.repack_tarball import repack_tarball55 from bzrlib.plugins.builddeb.repack_tarball import repack_tarball
55 config = util.debuild_config(tree, tree)56 config = util.debuild_config(tree, tree)
56 orig_dir = config.orig_dir or default_orig_dir57 orig_dir = config.orig_dir or default_orig_dir
@@ -62,14 +63,16 @@
62 if tarball.endswith(".tar.bz2") or tarball.endswith(".tbz2"):63 if tarball.endswith(".tar.bz2") or tarball.endswith(".tbz2"):
63 format = "bz2"64 format = "bz2"
64 dest_name = util.tarball_name(package_name, version, format=format)65 dest_name = util.tarball_name(package_name, version, format=format)
65 tarball_filename = os.path.join(orig_dir, dest_name)
66 trace.note("Fetching tarball")66 trace.note("Fetching tarball")
67 repack_tarball(tarball, dest_name, target_dir=orig_dir,67 repack_tarball(tarball, dest_name, target_dir=orig_dir,
68 force_gz=not use_v3)68 force_gz=not use_v3)
69 provider = upstream.UpstreamProvider(package_name, version,69 provider = upstream.UpstreamProvider(package_name, version,
70 orig_dir, [])70 orig_dir, [])
71 provider.provide(os.path.join(tree.basedir, ".."))71 orig_files = provider.provide(os.path.join(tree.basedir, ".."))
72 return tarball_filename, util.md5sum_filename(tarball_filename)72 ret = []
73 for filename in orig_files:
74 ret.append((filename, util.md5sum_filename(filename)))
75 return ret
7376
7477
75def import_upstream(tarball, package_name, version, use_v3=False):78def import_upstream(tarball, package_name, version, use_v3=False):
@@ -78,12 +81,15 @@
78 parents = [tree.branch.last_revision()]81 parents = [tree.branch.last_revision()]
79 else:82 else:
80 parents = []83 parents = []
81 tarball_filename, md5sum = _get_tarball(tree, tarball,84 tarball_filenames = _get_tarballs(tree, tarball,
82 package_name, version, use_v3=use_v3)85 package_name, version, use_v3=use_v3)
83 db = import_dsc.DistributionBranch(tree.branch, tree.branch, tree=tree,86 db = import_dsc.DistributionBranch(tree.branch, tree.branch, tree=tree,
84 upstream_tree=tree)87 upstream_tree=tree)
85 dbs = import_dsc.DistributionBranchSet()88 dbs = import_dsc.DistributionBranchSet()
86 dbs.add_branch(db)89 dbs.add_branch(db)
90 if len(tarball_filenames) > 1:
91 raise errors.MultipleUpstreamTarballsNotSupported()
92 (tarball_filename, md5sum) = tarball_filenames[0]
87 db.import_upstream_tarball(tarball_filename, version, parents, md5sum=md5sum)93 db.import_upstream_tarball(tarball_filename, version, parents, md5sum=md5sum)
88 return tree94 return tree
8995
9096
=== modified file 'errors.py'
--- errors.py 2011-06-09 21:43:07 +0000
+++ errors.py 2011-06-14 14:11:23 +0000
@@ -34,10 +34,11 @@
3434
3535
36class MissingUpstreamTarball(BzrError):36class MissingUpstreamTarball(BzrError):
37 _fmt = "Unable to find the needed upstream tarball: %(tarball_name)s."37 _fmt = ("Unable to find the needed upstream tarball for package %(package)s, "
38 "version %(version)s.")
3839
39 def __init__(self, tarball_name):40 def __init__(self, package, version):
40 BzrError.__init__(self, tarball_name=tarball_name)41 BzrError.__init__(self, package=package, version=version)
4142
4243
43class TarFailed(BzrError):44class TarFailed(BzrError):
4445
=== modified file 'source_distiller.py'
--- source_distiller.py 2010-03-11 23:44:57 +0000
+++ source_distiller.py 2011-06-14 14:11:23 +0000
@@ -26,6 +26,7 @@
26from bzrlib import errors as bzr_errors26from bzrlib import errors as bzr_errors
2727
28from bzrlib.plugins.builddeb.errors import (28from bzrlib.plugins.builddeb.errors import (
29 MultipleUpstreamTarballsNotSupported,
29 TarFailed,30 TarFailed,
30 )31 )
31from bzrlib.plugins.builddeb.util import (32from bzrlib.plugins.builddeb.util import (
@@ -121,11 +122,14 @@
121 if parent_dir != '' and not os.path.exists(parent_dir):122 if parent_dir != '' and not os.path.exists(parent_dir):
122 os.makedirs(parent_dir)123 os.makedirs(parent_dir)
123 if not self.use_existing:124 if not self.use_existing:
124 tarball = self.upstream_provider.provide(parent_dir)125 tarballs = self.upstream_provider.provide(parent_dir)
126 if len(tarballs) > 1:
127 raise MultipleUpstreamTarballsNotSupported()
128 tarball = tarballs[0]
125 # Extract it to the right place129 # Extract it to the right place
126 tempdir = tempfile.mkdtemp(prefix='builddeb-merge-')130 tempdir = tempfile.mkdtemp(prefix='builddeb-merge-')
127 try:131 try:
128 ret = subprocess.call(['tar','-C',tempdir,'-xf',tarball],132 ret = subprocess.call(['tar', '-C', tempdir, '-xf', tarball],
129 preexec_fn=subprocess_setup)133 preexec_fn=subprocess_setup)
130 if ret != 0:134 if ret != 0:
131 raise TarFailed("uncompress", tarball)135 raise TarFailed("uncompress", tarball)
132136
=== modified file 'tests/test_upstream.py'
--- tests/test_upstream.py 2011-06-14 00:32:04 +0000
+++ tests/test_upstream.py 2011-06-14 14:11:23 +0000
@@ -186,6 +186,21 @@
186 self.assertEqual("apackage", sources.lookup_package)186 self.assertEqual("apackage", sources.lookup_package)
187 self.assertEqual(0, caller.called)187 self.assertEqual(0, caller.called)
188188
189 def test_apt_provider_multiple_tarballs(self):
190 caller = MockAptCaller(work=True)
191 sources = MockSources(["0.1-1", "0.2-1"],
192 [[("checksum", 0L, "apackage_0.1.orig.tar.gz", "tar")],
193 [("checksum", 0L, "apackage_0.2.orig.tar.bz2", "tar"),
194 ("checksum", 1L, "apackage_0.2.orig-extra.tar.gz", "tar")]])
195 apt_pkg = MockAptPkg(sources)
196 src = AptSource()
197 src._run_apt_source = caller.call
198 paths = src.fetch_tarball("apackage", "0.2", "target",
199 _apt_pkg=apt_pkg)
200 self.assertEquals(paths, [
201 "target/apackage_0.2.orig.tar.bz2",
202 "target/apackage_0.2.orig-extra.tar.gz"])
203
189 def test_apt_provider_right_version_bz2(self):204 def test_apt_provider_right_version_bz2(self):
190 caller = MockAptCaller(work=True)205 caller = MockAptCaller(work=True)
191 sources = MockSources(["0.1-1", "0.2-1"],206 sources = MockSources(["0.1-1", "0.2-1"],
@@ -194,10 +209,9 @@
194 apt_pkg = MockAptPkg(sources)209 apt_pkg = MockAptPkg(sources)
195 src = AptSource()210 src = AptSource()
196 src._run_apt_source = caller.call211 src._run_apt_source = caller.call
197 path = src.fetch_tarball("apackage", "0.2", "target",212 paths = src.fetch_tarball("apackage", "0.2", "target",
198 _apt_pkg=apt_pkg)213 _apt_pkg=apt_pkg)
199 self.assertEquals(path,214 self.assertEquals(paths, ["target/apackage_0.2.orig.tar.bz2"])
200 "target/apackage_0.2.orig.tar.bz2")
201215
202 def test_apt_provider_right_version(self):216 def test_apt_provider_right_version(self):
203 caller = MockAptCaller(work=True)217 caller = MockAptCaller(work=True)
@@ -207,10 +221,9 @@
207 apt_pkg = MockAptPkg(sources)221 apt_pkg = MockAptPkg(sources)
208 src = AptSource()222 src = AptSource()
209 src._run_apt_source = caller.call223 src._run_apt_source = caller.call
210 path = src.fetch_tarball("apackage", "0.2", "target",224 paths = src.fetch_tarball("apackage", "0.2", "target",
211 _apt_pkg=apt_pkg)225 _apt_pkg=apt_pkg)
212 self.assertEquals(path,226 self.assertEquals(paths, ["target/apackage_0.2.orig.tar.gz"])
213 "target/apackage_0.2.orig.tar.gz")
214 self.assertEqual(1, apt_pkg.init_called_times)227 self.assertEqual(1, apt_pkg.init_called_times)
215 self.assertEqual(1, apt_pkg.get_pkg_source_records_called_times)228 self.assertEqual(1, apt_pkg.get_pkg_source_records_called_times)
216 self.assertEqual(1, sources.restart_called_times)229 self.assertEqual(1, sources.restart_called_times)
@@ -276,7 +289,7 @@
276 self._specific_versions.append((package, version, target_dir))289 self._specific_versions.append((package, version, target_dir))
277 if not self._succeed:290 if not self._succeed:
278 raise PackageVersionNotPresent(package, version, self)291 raise PackageVersionNotPresent(package, version, self)
279 return self._tarball_path(package, version, target_dir)292 return [self._tarball_path(package, version, target_dir)]
280293
281 def __repr__(self):294 def __repr__(self):
282 return "%s()" % self.__class__.__name__295 return "%s()" % self.__class__.__name__
@@ -377,7 +390,7 @@
377 source = UpstreamBranchSource(self.tree.branch,390 source = UpstreamBranchSource(self.tree.branch,
378 {"1.0": self.tree.branch.last_revision()})391 {"1.0": self.tree.branch.last_revision()})
379 os.mkdir("mydir")392 os.mkdir("mydir")
380 self.assertEquals("mydir/foo_1.0.orig.tar.gz",393 self.assertEquals(["mydir/foo_1.0.orig.tar.gz"],
381 source.fetch_tarball("foo", "1.0", "mydir"))394 source.fetch_tarball("foo", "1.0", "mydir"))
382 self.assertPathExists("mydir/foo_1.0.orig.tar.gz")395 self.assertPathExists("mydir/foo_1.0.orig.tar.gz")
383396
@@ -443,7 +456,7 @@
443 {"1.0": self.tree.branch.last_revision()})456 {"1.0": self.tree.branch.last_revision()})
444 self.assertIs(None, source._upstream_branch)457 self.assertIs(None, source._upstream_branch)
445 os.mkdir("mydir")458 os.mkdir("mydir")
446 self.assertEquals("mydir/foo_1.0.orig.tar.gz",459 self.assertEquals(["mydir/foo_1.0.orig.tar.gz"],
447 source.fetch_tarball("foo", "1.0", "mydir"))460 source.fetch_tarball("foo", "1.0", "mydir"))
448 self.assertPathExists("mydir/foo_1.0.orig.tar.gz")461 self.assertPathExists("mydir/foo_1.0.orig.tar.gz")
449 self.assertIsNot(None, source._upstream_branch)462 self.assertIsNot(None, source._upstream_branch)
@@ -721,7 +734,7 @@
721 def test_fetch_tarball(self):734 def test_fetch_tarball(self):
722 source = TarfileSource("foo-1.0.tar.gz", "1.0")735 source = TarfileSource("foo-1.0.tar.gz", "1.0")
723 os.mkdir("bar")736 os.mkdir("bar")
724 self.assertEquals("bar/foo_1.0.orig.tar.gz",737 self.assertEquals(["bar/foo_1.0.orig.tar.gz"],
725 source.fetch_tarball("foo", "1.0", "bar"))738 source.fetch_tarball("foo", "1.0", "bar"))
726 self.assertPathExists("bar/foo_1.0.orig.tar.gz")739 self.assertPathExists("bar/foo_1.0.orig.tar.gz")
727740
@@ -731,7 +744,7 @@
731 zf.close()744 zf.close()
732 source = TarfileSource("bla-2.0.zip", "2.0")745 source = TarfileSource("bla-2.0.zip", "2.0")
733 os.mkdir("bar")746 os.mkdir("bar")
734 self.assertEquals("bar/foo_2.0.orig.tar.gz",747 self.assertEquals(["bar/foo_2.0.orig.tar.gz"],
735 source.fetch_tarball("foo", "2.0", "bar"))748 source.fetch_tarball("foo", "2.0", "bar"))
736 self.assertPathExists("bar/foo_2.0.orig.tar.gz")749 self.assertPathExists("bar/foo_2.0.orig.tar.gz")
737750
@@ -748,7 +761,7 @@
748 bz2.BZ2File("foo-1.0.tar.bz2").close()761 bz2.BZ2File("foo-1.0.tar.bz2").close()
749 source = TarfileSource("foo-1.0.tar.bz2", "1.0")762 source = TarfileSource("foo-1.0.tar.bz2", "1.0")
750 os.mkdir("bar")763 os.mkdir("bar")
751 self.assertEquals("bar/foo_1.0.orig.tar.gz",764 self.assertEquals(["bar/foo_1.0.orig.tar.gz"],
752 source.fetch_tarball("foo", "1.0", "bar"))765 source.fetch_tarball("foo", "1.0", "bar"))
753 self.assertPathExists("bar/foo_1.0.orig.tar.gz")766 self.assertPathExists("bar/foo_1.0.orig.tar.gz")
754 gzip.open("bar/foo_1.0.orig.tar.gz").close()767 gzip.open("bar/foo_1.0.orig.tar.gz").close()
@@ -761,7 +774,7 @@
761 pass774 pass
762775
763 def provide(self, target_dir):776 def provide(self, target_dir):
764 raise MissingUpstreamTarball("test_tarball")777 raise MissingUpstreamTarball("test_tarball", "1.0")
765778
766779
767class _TouchUpstreamProvider(UpstreamProvider):780class _TouchUpstreamProvider(UpstreamProvider):
@@ -771,9 +784,11 @@
771 self.desired_tarball_name = desired_tarball_name784 self.desired_tarball_name = desired_tarball_name
772785
773 def provide(self, target_dir):786 def provide(self, target_dir):
774 f = open(os.path.join(target_dir, self.desired_tarball_name), "wb")787 path = os.path.join(target_dir, self.desired_tarball_name)
788 f = open(path, "wb")
775 f.write("I am a tarball, honest\n")789 f.write("I am a tarball, honest\n")
776 f.close()790 f.close()
791 return [path]
777792
778793
779class _SimpleUpstreamProvider(UpstreamProvider):794class _SimpleUpstreamProvider(UpstreamProvider):
@@ -785,11 +800,11 @@
785 self.store_dir = store_dir800 self.store_dir = store_dir
786801
787 def provide(self, target_dir):802 def provide(self, target_dir):
788 path = (self.already_exists_in_target(target_dir)803 paths = (self.already_exists_in_target(target_dir)
789 or self.provide_from_store_dir(target_dir))804 or self.provide_from_store_dir(target_dir))
790 if path is not None:805 if paths is not None:
791 return path806 return paths
792 raise MissingUpstreamTarball(self._tarball_names()[0])807 raise MissingUpstreamTarball(self.package, self.version)
793808
794809
795class ExtractTarballVersionTests(TestCase):810class ExtractTarballVersionTests(TestCase):
796811
=== modified file 'upstream/__init__.py'
--- upstream/__init__.py 2011-06-13 22:10:22 +0000
+++ upstream/__init__.py 2011-06-14 14:11:23 +0000
@@ -85,7 +85,7 @@
85 :param package: Name of the package85 :param package: Name of the package
86 :param version: Version string of the version to fetch86 :param version: Version string of the version to fetch
87 :param target_dir: Directory in which to store the tarball87 :param target_dir: Directory in which to store the tarball
88 :return: Path of the fetched tarball88 :return: Paths of the fetched tarballs
89 """89 """
90 raise NotImplementedError(self.fetch_tarball)90 raise NotImplementedError(self.fetch_tarball)
9191
@@ -126,14 +126,17 @@
126 lookup = get_fn(sources, 'lookup', 'Lookup')126 lookup = get_fn(sources, 'lookup', 'Lookup')
127 while lookup(package):127 while lookup(package):
128 version = get_fn(sources, 'version', 'Version')128 version = get_fn(sources, 'version', 'Version')
129 filenames = []
129 for (checksum, size, filename, filekind) in sources.files:130 for (checksum, size, filename, filekind) in sources.files:
130 if filekind != "tar":131 if filekind != "tar":
131 continue132 continue
132 filename = os.path.basename(filename)133 filename = os.path.basename(filename)
133 if filename.startswith("%s_%s.orig" % (package, upstream_version)):134 if filename.startswith("%s_%s.orig" % (package, upstream_version)):
134 if self._run_apt_source(package, version, target_dir):135 filenames.append(filename)
135 return os.path.join(target_dir, filename)136 if filenames:
136 break137 if self._run_apt_source(package, version, target_dir):
138 return [os.path.join(target_dir, filename)
139 for filename in filenames]
137 note("apt could not find the needed tarball.")140 note("apt could not find the needed tarball.")
138 raise PackageVersionNotPresent(package, upstream_version, self)141 raise PackageVersionNotPresent(package, upstream_version, self)
139142
@@ -157,8 +160,7 @@
157 self.tree = tree160 self.tree = tree
158 self.larstiq = larstiq161 self.larstiq = larstiq
159162
160 def _get_orig_source(self, source_dir, desired_tarball_names,163 def _get_orig_source(self, source_dir, prefix, target_dir):
161 target_dir):
162 note("Trying to use get-orig-source to retrieve needed tarball.")164 note("Trying to use get-orig-source to retrieve needed tarball.")
163 command = ["make", "-f", "debian/rules", "get-orig-source"]165 command = ["make", "-f", "debian/rules", "get-orig-source"]
164 proc = subprocess.Popen(command, cwd=source_dir)166 proc = subprocess.Popen(command, cwd=source_dir)
@@ -166,13 +168,18 @@
166 if ret != 0:168 if ret != 0:
167 note("Trying to run get-orig-source rule failed")169 note("Trying to run get-orig-source rule failed")
168 return None170 return None
169 for desired_tarball_name in desired_tarball_names:171 filenames = []
170 fetched_tarball = os.path.join(source_dir, desired_tarball_name)172 for filename in os.listdir(source_dir):
173 if not filename.startswith(prefix):
174 continue
175 fetched_tarball = os.path.join(source_dir, filename)
171 if os.path.exists(fetched_tarball):176 if os.path.exists(fetched_tarball):
172 repack_tarball(fetched_tarball, desired_tarball_name,177 repack_tarball(fetched_tarball, filename,
173 target_dir=target_dir, force_gz=False)178 target_dir=target_dir, force_gz=False)
174 return fetched_tarball179 filenames.append(os.path.join(target_dir, filename))
175 note("get-orig-source did not create %s", desired_tarball_name)180 if filenames:
181 return filenames
182 note("get-orig-source did not create file with prefix %s", prefix)
176 return None183 return None
177184
178 def fetch_tarball(self, package, version, target_dir):185 def fetch_tarball(self, package, version, target_dir):
@@ -182,9 +189,6 @@
182 rules_name = 'debian/rules'189 rules_name = 'debian/rules'
183 rules_id = self.tree.path2id(rules_name)190 rules_id = self.tree.path2id(rules_name)
184 if rules_id is not None:191 if rules_id is not None:
185 desired_tarball_names = [tarball_name(package, version),
186 tarball_name(package, version, 'bz2'),
187 tarball_name(package, version, 'lzma')]
188 tmpdir = tempfile.mkdtemp(prefix="builddeb-get-orig-source-")192 tmpdir = tempfile.mkdtemp(prefix="builddeb-get-orig-source-")
189 try:193 try:
190 base_export_dir = os.path.join(tmpdir, "export")194 base_export_dir = os.path.join(tmpdir, "export")
@@ -193,11 +197,11 @@
193 os.mkdir(export_dir)197 os.mkdir(export_dir)
194 export_dir = os.path.join(export_dir, "debian")198 export_dir = os.path.join(export_dir, "debian")
195 export(self.tree, export_dir, format="dir")199 export(self.tree, export_dir, format="dir")
196 tarball_path = self._get_orig_source(base_export_dir,200 tarball_paths = self._get_orig_source(base_export_dir,
197 desired_tarball_names, target_dir)201 "%s_%s.orig" % (package, version), target_dir)
198 if tarball_path is None:202 if tarball_paths is None:
199 raise PackageVersionNotPresent(package, version, self)203 raise PackageVersionNotPresent(package, version, self)
200 return tarball_path204 return tarball_paths
201 finally:205 finally:
202 shutil.rmtree(tmpdir)206 shutil.rmtree(tmpdir)
203 note("No debian/rules file to try and use for a get-orig-source rule")207 note("No debian/rules file to try and use for a get-orig-source rule")
@@ -279,7 +283,7 @@
279 if r != 0:283 if r != 0:
280 note("uscan could not find the needed tarball.")284 note("uscan could not find the needed tarball.")
281 raise PackageVersionNotPresent(package, version, self)285 raise PackageVersionNotPresent(package, version, self)
282 return self._tarball_path(package, version, target_dir)286 return [self._tarball_path(package, version, target_dir)]
283287
284288
285class SelfSplitSource(UpstreamSource):289class SelfSplitSource(UpstreamSource):
@@ -307,13 +311,13 @@
307 "to create the tarball")311 "to create the tarball")
308 tarball_path = self._tarball_path(package, version, target_dir)312 tarball_path = self._tarball_path(package, version, target_dir)
309 self._split(package, version, tarball_path)313 self._split(package, version, tarball_path)
310 return tarball_path314 return [tarball_path]
311315
312316
313class StackedUpstreamSource(UpstreamSource):317class StackedUpstreamSource(UpstreamSource):
314 """An upstream source that checks a list of other upstream sources.318 """An upstream source that checks a list of other upstream sources.
315319
316 The first source that can provide a tarball, wins. 320 The first source that can provide a tarball, wins.
317 """321 """
318322
319 def __init__(self, sources):323 def __init__(self, sources):
@@ -325,12 +329,11 @@
325 def fetch_tarball(self, package, version, target_dir):329 def fetch_tarball(self, package, version, target_dir):
326 for source in self._sources:330 for source in self._sources:
327 try:331 try:
328 path = source.fetch_tarball(package, version, target_dir)332 paths = source.fetch_tarball(package, version, target_dir)
329 except PackageVersionNotPresent:333 except PackageVersionNotPresent:
330 pass334 pass
331 else:335 else:
332 assert isinstance(path, basestring)336 return paths
333 return path
334 raise PackageVersionNotPresent(package, version, self)337 raise PackageVersionNotPresent(package, version, self)
335338
336 def get_latest_version(self, package, version):339 def get_latest_version(self, package, version):
@@ -364,7 +367,7 @@
364 self.source = StackedUpstreamSource(sources)367 self.source = StackedUpstreamSource(sources)
365368
366 def provide(self, target_dir):369 def provide(self, target_dir):
367 """Provide the upstream tarball any way possible.370 """Provide the upstream tarball(s) any way possible.
368371
369 Call this to place the correctly named tarball in to target_dir,372 Call this to place the correctly named tarball in to target_dir,
370 through means possible.373 through means possible.
@@ -396,44 +399,45 @@
396 if not os.path.exists(self.store_dir):399 if not os.path.exists(self.store_dir):
397 os.makedirs(self.store_dir)400 os.makedirs(self.store_dir)
398 try:401 try:
399 path = self.source.fetch_tarball(self.package,402 paths = self.source.fetch_tarball(self.package,
400 self.version, self.store_dir)403 self.version, self.store_dir)
401 except PackageVersionNotPresent:404 except PackageVersionNotPresent:
402 raise MissingUpstreamTarball(self._tarball_names()[0])405 raise MissingUpstreamTarball(self.package, self.version)
403 assert isinstance(path, basestring)406 assert isinstance(paths, list)
404 else:407 else:
405 note("Using the upstream tarball that is present in %s" %408 note("Using the upstream tarball that is present in %s" %
406 self.store_dir)409 self.store_dir)
407 path = self.provide_from_store_dir(target_dir)410 paths = self.provide_from_store_dir(target_dir)
408 assert path is not None411 assert paths is not None
409 return path412 return paths
413
414 def _gather_orig_files(self, path):
415 prefix = "%s_%s.orig" % (self.package, self.version)
416 ret = []
417 path = os.path.abspath(path)
418 if not os.path.isdir(path):
419 return None
420 for filename in os.listdir(path):
421 if filename.startswith(prefix):
422 ret.append(os.path.join(path, filename))
423 if ret:
424 return ret
425 return None
410426
411 def already_exists_in_target(self, target_dir):427 def already_exists_in_target(self, target_dir):
412 for tarball_name in self._tarball_names():428 return self._gather_orig_files(target_dir)
413 path = os.path.join(target_dir, tarball_name)
414 if os.path.exists(path):
415 return path
416 return None
417429
418 def already_exists_in_store(self):430 def already_exists_in_store(self):
419 for tarball_name in self._tarball_names():431 return self._gather_orig_files(self.store_dir)
420 path = os.path.join(self.store_dir, tarball_name)
421 if os.path.exists(path):
422 return path
423 return None
424432
425 def provide_from_store_dir(self, target_dir):433 def provide_from_store_dir(self, target_dir):
426 path = self.already_exists_in_store()434 paths = self.already_exists_in_store()
427 if path is not None:435 if paths is None:
436 return None
437 for path in paths:
428 repack_tarball(path, os.path.basename(path),438 repack_tarball(path, os.path.basename(path),
429 target_dir=target_dir, force_gz=False)439 target_dir=target_dir, force_gz=False)
430 return path440 return paths
431 return path
432
433 def _tarball_names(self):
434 return [tarball_name(self.package, self.version),
435 tarball_name(self.package, self.version, format='bz2'),
436 tarball_name(self.package, self.version, format='lzma')]
437441
438442
439def extract_tarball_version(path, packagename):443def extract_tarball_version(path, packagename):
@@ -473,7 +477,7 @@
473 raise PackageVersionNotPresent(package, version, self)477 raise PackageVersionNotPresent(package, version, self)
474 dest_name = tarball_name(package, version)478 dest_name = tarball_name(package, version)
475 repack_tarball(self.path, dest_name, target_dir=target_dir, force_gz=True)479 repack_tarball(self.path, dest_name, target_dir=target_dir, force_gz=True)
476 return os.path.join(target_dir, dest_name)480 return [os.path.join(target_dir, dest_name)]
477481
478 def get_latest_version(self, package, version):482 def get_latest_version(self, package, version):
479 if self.version is not None:483 if self.version is not None:
480484
=== modified file 'upstream/branch.py'
--- upstream/branch.py 2011-04-28 15:46:43 +0000
+++ upstream/branch.py 2011-06-14 14:11:23 +0000
@@ -268,7 +268,7 @@
268 export(rev_tree, target_filename, 'tgz', tarball_base)268 export(rev_tree, target_filename, 'tgz', tarball_base)
269 finally:269 finally:
270 self.upstream_branch.unlock()270 self.upstream_branch.unlock()
271 return target_filename271 return [target_filename]
272272
273 def __repr__(self):273 def __repr__(self):
274 return "<%s for %r>" % (self.__class__.__name__,274 return "<%s for %r>" % (self.__class__.__name__,
275275
=== modified file 'upstream/pristinetar.py'
--- upstream/pristinetar.py 2011-06-03 12:34:57 +0000
+++ upstream/pristinetar.py 2011-06-14 14:11:23 +0000
@@ -145,7 +145,7 @@
145 raise PackageVersionNotPresent(package, version, self)145 raise PackageVersionNotPresent(package, version, self)
146 except PerFileTimestampsNotSupported:146 except PerFileTimestampsNotSupported:
147 raise PackageVersionNotPresent(package, version, self)147 raise PackageVersionNotPresent(package, version, self)
148 return target_filename148 return [target_filename]
149149
150 def _has_version(self, tag_name, md5=None):150 def _has_version(self, tag_name, md5=None):
151 if not self.branch.tags.has_tag(tag_name):151 if not self.branch.tags.has_tag(tag_name):

Subscribers

People subscribed via source and target branches