Merge lp:~maxb/bzr-builddeb/better-error-multiple-upstream-tarballs into lp:bzr-builddeb

Proposed by Max Bowsher
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: 566
Merged at revision: 566
Proposed branch: lp:~maxb/bzr-builddeb/better-error-multiple-upstream-tarballs
Merge into: lp:bzr-builddeb
Diff against target: 124 lines (+57/-3)
4 files modified
errors.py (+6/-0)
import_dsc.py (+2/-2)
tests/__init__.py (+29/-1)
tests/test_import_dsc.py (+20/-0)
To merge this branch: bzr merge lp:~maxb/bzr-builddeb/better-error-multiple-upstream-tarballs
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+64090@code.launchpad.net

Description of the change

When attempting to import a package with multiple upstream tarballs, raise
MultipleUpstreamTarballsNotSupported rather than AssertionError.

The primary motivation is so that the UDD failures categorization will automatically split this case from other kinds of unpack failure.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

On Thu, 2011-06-09 at 21:46 +0000, Max Bowsher wrote:
> Max Bowsher has proposed merging lp:~maxb/bzr-builddeb/better-error-multiple-upstream-tarballs into lp:bzr-builddeb.
>
> Requested reviews:
> Bzr-builddeb-hackers (bzr-builddeb-hackers)
>
> For more details, see:
> https://code.launchpad.net/~maxb/bzr-builddeb/better-error-multiple-upstream-tarballs/+merge/64090
>
> When attempting to import a package with multiple upstream tarballs, raise
> MultipleUpstreamTarballsNotSupported rather than AssertionError.
>
> The primary motivation is so that the UDD failures categorization will automatically split this case from other kinds of unpack failure.
It would be nice to have a test that verifies that the exception is
raised when there are multiple upstream tarballs.

Other than that, looks good:

  review needsfixing
  merge approve

Cheers,

Jelmer

review: Needs Fixing
567. By Max Bowsher

Add test.

Revision history for this message
Max Bowsher (maxb) wrote :

Alright, I guess the work writing the test will pay off once we actually implement support.

How's this?

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

Thanks :)

That last bit seems shorter as:

self.addCleanup(extractor.cleanup)
self.assertRaises(MultipleUpstreamTarballsNotSupported, extractor.extract)

rather than:

+ try:
124 + try:
125 + extractor.extract()
126 + self.fail("Expected exception not thrown")
127 + except MultipleUpstreamTarballsNotSupported:
128 + pass # Expected
129 + finally:
130 + extractor.cleanup()

review: Approve
568. By Max Bowsher

Write test in a shorter style using suggestion from Jelmer.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'errors.py'
2--- errors.py 2011-06-03 12:17:42 +0000
3+++ errors.py 2011-06-10 11:49:31 +0000
4@@ -224,3 +224,9 @@
5
6 def __init__(self, error):
7 BzrError.__init__(self, error=error)
8+
9+
10+class MultipleUpstreamTarballsNotSupported(BzrError):
11+
12+ _fmt = ("Importing packages using source format 3.0 multiple tarballs "
13+ "is not yet supported.")
14
15=== modified file 'import_dsc.py'
16--- import_dsc.py 2011-06-05 00:12:43 +0000
17+++ import_dsc.py 2011-06-10 11:49:31 +0000
18@@ -62,6 +62,7 @@
19
20 from bzrlib.plugins.builddeb.bzrtools_import import import_dir
21 from bzrlib.plugins.builddeb.errors import (
22+ MultipleUpstreamTarballsNotSupported,
23 TarFailed,
24 UpstreamAlreadyImported,
25 UpstreamBranchAlreadyMerged,
26@@ -1560,8 +1561,7 @@
27 "0000", "-exec", "chmod", "644", "{}", ";"])
28 for part in self.dsc['files']:
29 if (re.search("\.orig-[^.]+\.tar\.(gz|bz2|lzma)$", part['name'])):
30- raise AssertionError("Can't import packages with multiple "
31- "upstream tarballs yet")
32+ raise MultipleUpstreamTarballsNotSupported()
33 if (part['name'].endswith(".orig.tar.gz")
34 or part['name'].endswith(".orig.tar.bz2")):
35 assert self.unextracted_upstream is None, "Two .orig.tar.(gz|bz2)?"
36
37=== modified file 'tests/__init__.py'
38--- tests/__init__.py 2011-05-08 07:39:35 +0000
39+++ tests/__init__.py 2011-06-10 11:49:31 +0000
40@@ -239,13 +239,27 @@
41 >>> builder.dsc_name()
42 """
43
44- def __init__(self, name, version, native=False, version3=False):
45+ def __init__(self, name, version, native=False, version3=False,
46+ multiple_upstream_tarballs=None):
47+ """
48+ :param name: Package name
49+ :param version: Package version
50+ :param native: Whether to build a native source package
51+ :param version3: Whether to build a version 3.0 source package
52+ :param multiple_upstream_tarballs: A list of each top-level directory
53+ within the upstream tree which is to be packed as a source format
54+ 3.0 (quilt) additional upstream tarball
55+ """
56 self.upstream_files = {}
57 self.upstream_symlinks = {}
58 self.debian_files = {}
59 self.name = name
60 self.native = native
61 self.version3 = version3
62+ self.multiple_upstream_tarballs = multiple_upstream_tarballs
63+ if multiple_upstream_tarballs and not (version3 and not native):
64+ raise AssertionError("Multiple upstream tarballs are only "
65+ "possible with 3.0 (quilt) format")
66 self._cl = Changelog()
67 self.new_version(version)
68
69@@ -356,6 +370,20 @@
70 cmd = ["dpkg-source", "-sn", "-b", basedir]
71 else:
72 if not self.native:
73+ if self.multiple_upstream_tarballs:
74+ for part in self.multiple_upstream_tarballs:
75+ tar_path = "%s_%s.orig-%s.tar.%s" % (self.name,
76+ self._cl.version.upstream_version,
77+ part, tar_format)
78+ if os.path.exists(tar_path):
79+ os.unlink(tar_path)
80+ tar = tarfile.open(tar_path, 'w:%s' % tar_format)
81+ part_basedir = os.path.join(basedir, part)
82+ try:
83+ tar.add(part_basedir, arcname=part)
84+ finally:
85+ tar.close()
86+ shutil.rmtree(part_basedir)
87 tar_path = "%s_%s.orig.tar.%s" % (self.name,
88 self._cl.version.upstream_version, tar_format)
89 if os.path.exists(tar_path):
90
91=== modified file 'tests/test_import_dsc.py'
92--- tests/test_import_dsc.py 2011-06-04 08:52:53 +0000
93+++ tests/test_import_dsc.py 2011-06-10 11:49:31 +0000
94@@ -35,6 +35,9 @@
95 tests,
96 )
97
98+from bzrlib.plugins.builddeb.errors import (
99+ MultipleUpstreamTarballsNotSupported,
100+ )
101 from bzrlib.plugins.builddeb.import_dsc import (
102 DistributionBranch,
103 DistributionBranchSet,
104@@ -1917,3 +1920,20 @@
105 finally:
106 extractor.cleanup()
107
108+ def test_extract_format3_quilt_multiple_upstream_tarballs(self):
109+ version = Version("0.1-1")
110+ name = "package"
111+ builder = SourcePackageBuilder(name, version, version3=True,
112+ multiple_upstream_tarballs=("foo", "bar"))
113+ builder.add_upstream_file("README", "Hi\n")
114+ builder.add_upstream_file("BUGS")
115+ builder.add_upstream_file("foo/wibble")
116+ builder.add_upstream_file("bar/xyzzy")
117+ builder.add_default_control()
118+ builder.build(tar_format='bz2')
119+ dsc = deb822.Dsc(open(builder.dsc_name()).read())
120+ self.assertEqual(ThreeDotZeroQuiltSourceExtractor,
121+ SOURCE_EXTRACTORS[dsc['Format']])
122+ extractor = ThreeDotZeroQuiltSourceExtractor(builder.dsc_name(), dsc)
123+ self.addCleanup(extractor.cleanup)
124+ self.assertRaises(MultipleUpstreamTarballsNotSupported, extractor.extract)

Subscribers

People subscribed via source and target branches