Merge lp:~jelmer/bzr-builddeb/tarfilesource into lp:bzr-builddeb

Proposed by Jelmer Vernooij
Status: Merged
Merged at revision: 507
Proposed branch: lp:~jelmer/bzr-builddeb/tarfilesource
Merge into: lp:bzr-builddeb
Diff against target: 178 lines (+68/-13)
3 files modified
cmds.py (+8/-11)
tests/test_upstream.py (+41/-1)
upstream.py (+19/-1)
To merge this branch: bzr merge lp:~jelmer/bzr-builddeb/tarfilesource
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+48312@code.launchpad.net

Description of the change

This adds a TarfileSource class which is used for simple tar/zip/etc upstream files. This should make tar files a bit less special in merge-upstream.

TarfileSource does a repack, like merge-upstream. The other UpstreamSource subclasses also already do repacks if necessary. In my next branch I'm going to move the repacks completely into the UpstreamSource classes, to simplify merge-upstream further.

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
1=== modified file 'cmds.py'
2--- cmds.py 2011-01-31 18:47:05 +0000
3+++ cmds.py 2011-02-02 13:35:33 +0000
4@@ -93,7 +93,7 @@
5 GetOrigSourceSource,
6 PristineTarSource,
7 SelfSplitSource,
8- StackedUpstreamSource,
9+ TarfileSource,
10 UScanSource,
11 UpstreamProvider,
12 UpstreamBranchSource,
13@@ -535,7 +535,6 @@
14
15 v3_opt = Option('v3', help='Use dpkg-source format v3.')
16
17-
18 takes_options = [package_opt, version_opt,
19 distribution_opt, directory_opt, last_version_opt,
20 force_opt, v3_opt, 'revision', 'merge-type',
21@@ -566,8 +565,7 @@
22 from bzrlib.plugins.builddeb.repack_tarball import repack_tarball
23 format = None
24 if v3:
25- if (location.endswith(".tar.bz2")
26- or location.endswith(".tbz2")):
27+ if location.endswith(".tar.bz2") or location.endswith(".tbz2"):
28 format = "bz2"
29 dest_name = tarball_name(package, version, format=format)
30 tarball_filename = os.path.join(orig_dir, dest_name)
31@@ -675,12 +673,12 @@
32 primary_upstream_source = UpstreamBranchSource(
33 Branch.open(location), config=config)
34 except NotBranchError:
35- primary_upstream_source = None
36+ primary_upstream_source = TarfileSource(location, version)
37 else:
38 if snapshot:
39 if upstream_branch_source is None:
40- raise BzrCommandError("--snapshot requires an upstream "
41- "branch source")
42+ raise BzrCommandError("--snapshot requires an upstream"
43+ " branch source")
44 primary_upstream_source = upstream_branch_source
45 else:
46 primary_upstream_source = UScanSource(tree, larstiq)
47@@ -705,10 +703,6 @@
48 elif version is None and primary_upstream_source is not None:
49 version = primary_upstream_source.get_latest_version(
50 package, current_version)
51- target_dir = tempfile.mkdtemp() # FIXME: Cleanup?
52- if need_upstream_tarball:
53- location = primary_upstream_source.fetch_tarball(
54- package, version, target_dir)
55 if version is None:
56 raise BzrCommandError("You must specify the version number using --version.")
57 note("Using version string %s." % (version))
58@@ -717,6 +711,9 @@
59 upstream_revision = upstream_branch_source.version_as_revision(
60 package, version)
61 if need_upstream_tarball:
62+ target_dir = tempfile.mkdtemp() # FIXME: Cleanup?
63+ location = primary_upstream_source.fetch_tarball(
64+ package, version, target_dir)
65 tarball_filename = self._get_tarball(config, tree, package,
66 version, upstream_branch, upstream_revision, v3,
67 location)
68
69=== modified file 'tests/test_upstream.py'
70--- tests/test_upstream.py 2011-01-24 05:46:47 +0000
71+++ tests/test_upstream.py 2011-02-02 13:35:33 +0000
72@@ -24,6 +24,8 @@
73
74
75 import os
76+import tarfile
77+import zipfile
78
79 from bzrlib.tests import (
80 TestCase,
81@@ -40,8 +42,10 @@
82 from bzrlib.plugins.builddeb.upstream import (
83 AptSource,
84 StackedUpstreamSource,
85+ TarfileSource,
86 UpstreamBranchSource,
87 UpstreamProvider,
88+ UpstreamSource,
89 UScanSource,
90 Version,
91 )
92@@ -180,7 +184,7 @@
93 self.assertEqual("target", caller.target_dir)
94
95
96-class RecordingSource(object):
97+class RecordingSource(UpstreamSource):
98
99 def __init__(self, succeed, latest=None):
100 self._succeed = succeed
101@@ -194,6 +198,7 @@
102 self._specific_versions.append((package, version, target_dir))
103 if not self._succeed:
104 raise PackageVersionNotPresent(package, version, self)
105+ return self._tarball_path(package, version, target_dir)
106
107 def __repr__(self):
108 return "%s()" % self.__class__.__name__
109@@ -328,6 +333,41 @@
110 self.assertEquals(revid1, source.version_as_revision("foo", "2.1"))
111
112
113+class TarfileSourceTests(TestCaseWithTransport):
114+ """Tests for TarfileSource."""
115+
116+ def setUp(self):
117+ super(TarfileSourceTests, self).setUp()
118+ tar = tarfile.open("foo-1.0.tar.gz", "w:gz")
119+ tar.close()
120+
121+ def test_version(self):
122+ source = TarfileSource("foo-1.0.tar.gz", "1.0")
123+ self.assertEquals("1.0", source.get_latest_version("foo", "0.9"))
124+
125+ def test_fetch_tarball(self):
126+ source = TarfileSource("foo-1.0.tar.gz", "1.0")
127+ os.mkdir("bar")
128+ self.assertEquals("bar/foo_1.0.orig.tar.gz",
129+ source.fetch_tarball("foo", "1.0", "bar"))
130+ self.failUnlessExists("bar/foo_1.0.orig.tar.gz")
131+
132+ def test_fetch_tarball_repack(self):
133+ zf = zipfile.ZipFile("bla-2.0.zip", "w")
134+ zf.close()
135+ source = TarfileSource("bla-2.0.zip", "2.0")
136+ os.mkdir("bar")
137+ self.assertEquals("bar/foo_2.0.orig.tar.gz",
138+ source.fetch_tarball("foo", "2.0", "bar"))
139+ self.failUnlessExists("bar/foo_2.0.orig.tar.gz")
140+
141+ def test_fetch_tarball_not_present(self):
142+ source = TarfileSource("foo-1.0.tar.gz", "1.0")
143+ os.mkdir("bar")
144+ self.assertRaises(PackageVersionNotPresent,
145+ source.fetch_tarball, "foo", "0.9", "bar")
146+
147+
148 class _MissingUpstreamProvider(UpstreamProvider):
149 """For tests"""
150
151
152=== modified file 'upstream.py'
153--- upstream.py 2011-01-31 23:15:42 +0000
154+++ upstream.py 2011-02-02 13:35:33 +0000
155@@ -511,4 +511,22 @@
156 tarball_name(self.package, self.version.upstream_version, format='lzma')]
157
158
159-
160+class TarfileSource(UpstreamSource):
161+ """Source that uses a single local tarball."""
162+
163+ def __init__(self, path, version=None):
164+ self.path = path
165+ # TODO: Parse self.path for version is version is None?
166+ self.version = version
167+
168+ def fetch_tarball(self, package, version, target_dir):
169+ if version != self.version:
170+ raise PackageVersionNotPresent(package, version, self)
171+ dest_name = tarball_name(package, version)
172+ repack_tarball(self.path, dest_name, target_dir=target_dir)
173+ target_filename = self._tarball_path(package, version, target_dir)
174+ shutil.copy(self.path, target_filename)
175+ return target_filename
176+
177+ def get_latest_version(self, package, version):
178+ return self.version

Subscribers

People subscribed via source and target branches