Merge lp:~jelmer/bzr-builddeb/fetch-tarball into lp:bzr-builddeb

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: 501
Merged at revision: 497
Proposed branch: lp:~jelmer/bzr-builddeb/fetch-tarball
Merge into: lp:bzr-builddeb
Prerequisite: lp:~jelmer/bzr-builddeb/get-export-upstream-revision-version
Diff against target: 339 lines (+79/-44)
4 files modified
cmds.py (+1/-1)
merge_upstream.py (+0/-1)
tests/test_upstream.py (+45/-16)
upstream.py (+33/-26)
To merge this branch: bzr merge lp:~jelmer/bzr-builddeb/fetch-tarball
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+47209@code.launchpad.net

Description of the change

Another refactoring branch. The main change this makes is to rename get_specific_version to fetch_tarball and to make the new method return the path to the tarball (instead of not specifying the behaviour).

To post a comment you must log in.
501. By Jelmer Vernooij

Tests.

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-01-24 03:08:28 +0000
+++ cmds.py 2011-01-24 03:08:28 +0000
@@ -563,7 +563,7 @@
563 tarball_filename = os.path.join(orig_dir, dest_name)563 tarball_filename = os.path.join(orig_dir, dest_name)
564 upstream = UpstreamBranchSource(upstream_branch,564 upstream = UpstreamBranchSource(upstream_branch,
565 {version: upstream_revision})565 {version: upstream_revision})
566 upstream.get_specific_version(package, version, orig_dir)566 upstream.fetch_tarball(package, version, orig_dir)
567 return tarball_filename567 return tarball_filename
568568
569 def _fetch_tarball(self, package, version, orig_dir, location, v3):569 def _fetch_tarball(self, package, version, orig_dir, location, v3):
570570
=== modified file 'merge_upstream.py'
--- merge_upstream.py 2011-01-17 22:18:44 +0000
+++ merge_upstream.py 2011-01-24 03:08:28 +0000
@@ -26,7 +26,6 @@
26# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA26# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27#27#
2828
29import itertools
30import subprocess29import subprocess
3130
32try:31try:
3332
=== modified file 'tests/test_upstream.py'
--- tests/test_upstream.py 2010-03-04 14:26:13 +0000
+++ tests/test_upstream.py 2011-01-24 03:08:28 +0000
@@ -20,18 +20,24 @@
20# We have a bit of a problem with testing the actual uscan etc. integration,20# We have a bit of a problem with testing the actual uscan etc. integration,
21# so just mock them.21# so just mock them.
2222
23"""Tests for the upstream module."""
24
25
26import os
27
23from bzrlib.tests import (28from bzrlib.tests import (
24 TestCase,29 TestCase,
25 TestCaseWithTransport,30 TestCaseWithTransport,
26 )31 )
27from bzrlib.plugins.builddeb.errors import (32from bzrlib.plugins.builddeb.errors import (
28 PackageVersionNotPresent,33 PackageVersionNotPresent,
29 )34 )
30from bzrlib.plugins.builddeb.upstream import (35from bzrlib.plugins.builddeb.upstream import (
31 AptSource,36 AptSource,
32 StackedUpstreamSource,37 StackedUpstreamSource,
33 UScanSource,38 UpstreamBranchSource,
34 )39 UScanSource,
40 )
3541
3642
37class MockSources(object):43class MockSources(object):
@@ -103,7 +109,7 @@
103 apt_pkg = MockAptPkg(sources)109 apt_pkg = MockAptPkg(sources)
104 src = AptSource()110 src = AptSource()
105 src._run_apt_source = caller.call111 src._run_apt_source = caller.call
106 self.assertRaises(PackageVersionNotPresent, src.get_specific_version,112 self.assertRaises(PackageVersionNotPresent, src.fetch_tarball,
107 "apackage", "0.2", "target", _apt_pkg=apt_pkg)113 "apackage", "0.2", "target", _apt_pkg=apt_pkg)
108 self.assertEqual(1, apt_pkg.init_called_times)114 self.assertEqual(1, apt_pkg.init_called_times)
109 self.assertEqual(1, apt_pkg.get_pkg_source_records_called_times)115 self.assertEqual(1, apt_pkg.get_pkg_source_records_called_times)
@@ -118,7 +124,7 @@
118 apt_pkg = MockAptPkg(sources)124 apt_pkg = MockAptPkg(sources)
119 src = AptSource()125 src = AptSource()
120 src._run_apt_source = caller.call126 src._run_apt_source = caller.call
121 self.assertRaises(PackageVersionNotPresent, src.get_specific_version,127 self.assertRaises(PackageVersionNotPresent, src.fetch_tarball,
122 "apackage", "0.2", "target", _apt_pkg=apt_pkg)128 "apackage", "0.2", "target", _apt_pkg=apt_pkg)
123 self.assertEqual(1, apt_pkg.init_called_times)129 self.assertEqual(1, apt_pkg.init_called_times)
124 self.assertEqual(1, apt_pkg.get_pkg_source_records_called_times)130 self.assertEqual(1, apt_pkg.get_pkg_source_records_called_times)
@@ -133,7 +139,7 @@
133 apt_pkg = MockAptPkg(sources)139 apt_pkg = MockAptPkg(sources)
134 src = AptSource()140 src = AptSource()
135 src._run_apt_source = caller.call141 src._run_apt_source = caller.call
136 src.get_specific_version("apackage", "0.2", "target", 142 src.fetch_tarball("apackage", "0.2", "target",
137 _apt_pkg=apt_pkg)143 _apt_pkg=apt_pkg)
138 self.assertEqual(1, apt_pkg.init_called_times)144 self.assertEqual(1, apt_pkg.init_called_times)
139 self.assertEqual(1, apt_pkg.get_pkg_source_records_called_times)145 self.assertEqual(1, apt_pkg.get_pkg_source_records_called_times)
@@ -152,7 +158,7 @@
152 apt_pkg = MockAptPkg(sources)158 apt_pkg = MockAptPkg(sources)
153 src = AptSource()159 src = AptSource()
154 src._run_apt_source = caller.call160 src._run_apt_source = caller.call
155 self.assertRaises(PackageVersionNotPresent, src.get_specific_version,161 self.assertRaises(PackageVersionNotPresent, src.fetch_tarball,
156 "apackage", "0.2", "target", 162 "apackage", "0.2", "target",
157 _apt_pkg=apt_pkg)163 _apt_pkg=apt_pkg)
158 self.assertEqual(1, apt_pkg.init_called_times)164 self.assertEqual(1, apt_pkg.init_called_times)
@@ -173,7 +179,7 @@
173 self._succeed = succeed179 self._succeed = succeed
174 self._specific_versions = []180 self._specific_versions = []
175181
176 def get_specific_version(self, package, version, target_dir):182 def fetch_tarball(self, package, version, target_dir):
177 self._specific_versions.append((package, version, target_dir))183 self._specific_versions.append((package, version, target_dir))
178 if not self._succeed:184 if not self._succeed:
179 raise PackageVersionNotPresent(package, version, self)185 raise PackageVersionNotPresent(package, version, self)
@@ -189,7 +195,7 @@
189 b = RecordingSource(True)195 b = RecordingSource(True)
190 c = RecordingSource(False)196 c = RecordingSource(False)
191 stack = StackedUpstreamSource([a, b, c])197 stack = StackedUpstreamSource([a, b, c])
192 stack.get_specific_version("mypkg", "1.0", "bla")198 stack.fetch_tarball("mypkg", "1.0", "bla")
193 self.assertEquals([("mypkg", "1.0", "bla")], b._specific_versions)199 self.assertEquals([("mypkg", "1.0", "bla")], b._specific_versions)
194 self.assertEquals([("mypkg", "1.0", "bla")], a._specific_versions)200 self.assertEquals([("mypkg", "1.0", "bla")], a._specific_versions)
195 self.assertEquals([], c._specific_versions)201 self.assertEquals([], c._specific_versions)
@@ -205,7 +211,7 @@
205 b = RecordingSource(False)211 b = RecordingSource(False)
206 stack = StackedUpstreamSource([a, b])212 stack = StackedUpstreamSource([a, b])
207 self.assertRaises(PackageVersionNotPresent, 213 self.assertRaises(PackageVersionNotPresent,
208 stack.get_specific_version, "pkg", "1.0", "bla")214 stack.fetch_tarball, "pkg", "1.0", "bla")
209 self.assertEquals([("pkg", "1.0", "bla")], b._specific_versions)215 self.assertEquals([("pkg", "1.0", "bla")], b._specific_versions)
210 self.assertEquals([("pkg", "1.0", "bla")], a._specific_versions)216 self.assertEquals([("pkg", "1.0", "bla")], a._specific_versions)
211217
@@ -233,3 +239,26 @@
233 self.assertEquals(None, src._export_watchfile())239 self.assertEquals(None, src._export_watchfile())
234 self.tree.smart_add(['debian/watch'])240 self.tree.smart_add(['debian/watch'])
235 self.assertTrue(src._export_watchfile() is not None)241 self.assertTrue(src._export_watchfile() is not None)
242
243
244class UpstreamBranchSourceTests(TestCaseWithTransport):
245
246 def setUp(self):
247 super(UpstreamBranchSourceTests, self).setUp()
248 self.tree = self.make_branch_and_tree('.')
249
250 def test_fetch_tarball(self):
251 self.tree.commit("msg")
252 self.tree.branch.tags.set_tag("1.0", self.tree.branch.last_revision())
253 source = UpstreamBranchSource(self.tree.branch,
254 {"1.0": self.tree.branch.last_revision()})
255 os.mkdir("mydir")
256 self.assertEquals("mydir/foo_1.0.orig.tar.gz",
257 source.fetch_tarball("foo", "1.0", "mydir"))
258 self.failUnlessExists("mydir/foo_1.0.orig.tar.gz")
259
260 def test_fetch_tarball_not_found(self):
261 source = UpstreamBranchSource(self.tree.branch)
262 self.tree.commit("msg")
263 self.assertRaises(PackageVersionNotPresent,
264 source.fetch_tarball, "foo", "1.0", "mydir")
236265
=== modified file 'upstream.py'
--- upstream.py 2010-05-28 20:45:50 +0000
+++ upstream.py 2011-01-24 03:08:28 +0000
@@ -62,14 +62,15 @@
62 """62 """
63 raise NotImplementedError(self.get_latest_version)63 raise NotImplementedError(self.get_latest_version)
6464
65 def get_specific_version(self, package, version, target_dir):65 def fetch_tarball(self, package, version, target_dir):
66 """Fetch the source tarball for a particular version.66 """Fetch the source tarball for a particular version.
6767
68 :param package: Name of the package68 :param package: Name of the package
69 :param version: Version string of the version to fetch69 :param version: Version string of the version to fetch
70 :param target_dir: Directory in which to store the tarball70 :param target_dir: Directory in which to store the tarball
71 :return: Path of the fetched tarball
71 """72 """
72 raise NotImplementedError(self.get_specific_version)73 raise NotImplementedError(self.fetch_tarball)
7374
74 def _tarball_path(self, package, version, target_dir, format=None):75 def _tarball_path(self, package, version, target_dir, format=None):
75 return os.path.join(target_dir, tarball_name(package, version,76 return os.path.join(target_dir, tarball_name(package, version,
@@ -83,7 +84,7 @@
83 self.branch = branch84 self.branch = branch
84 self.tree = tree85 self.tree = tree
8586
86 def get_specific_version(self, package, version, target_dir):87 def fetch_tarball(self, package, version, target_dir):
87 db = DistributionBranch(self.branch, None, tree=self.tree)88 db = DistributionBranch(self.branch, None, tree=self.tree)
88 if not db.has_upstream_version_in_packaging_branch(version):89 if not db.has_upstream_version_in_packaging_branch(version):
89 raise PackageVersionNotPresent(package, version, self)90 raise PackageVersionNotPresent(package, version, self)
@@ -102,12 +103,13 @@
102 raise PackageVersionNotPresent(package, version, self)103 raise PackageVersionNotPresent(package, version, self)
103 except PerFileTimestampsNotSupported:104 except PerFileTimestampsNotSupported:
104 raise PackageVersionNotPresent(package, version, self)105 raise PackageVersionNotPresent(package, version, self)
106 return target_filename
105107
106108
107class AptSource(UpstreamSource):109class AptSource(UpstreamSource):
108 """Upstream source that uses apt-source."""110 """Upstream source that uses apt-source."""
109111
110 def get_specific_version(self, package, upstream_version, target_dir, 112 def fetch_tarball(self, package, upstream_version, target_dir,
111 _apt_pkg=None):113 _apt_pkg=None):
112 if _apt_pkg is None:114 if _apt_pkg is None:
113 import apt_pkg115 import apt_pkg
@@ -138,7 +140,7 @@
138 version = get_fn(sources, 'version', 'Version')140 version = get_fn(sources, 'version', 'Version')
139 if upstream_version == Version(version).upstream_version:141 if upstream_version == Version(version).upstream_version:
140 if self._run_apt_source(package, version, target_dir):142 if self._run_apt_source(package, version, target_dir):
141 return143 return self._tarball_path(package, version, target_dir)
142 break144 break
143 note("apt could not find the needed tarball.")145 note("apt could not find the needed tarball.")
144 raise PackageVersionNotPresent(package, upstream_version, self)146 raise PackageVersionNotPresent(package, upstream_version, self)
@@ -158,7 +160,7 @@
158160
159class UpstreamBranchSource(UpstreamSource):161class UpstreamBranchSource(UpstreamSource):
160 """Upstream source that uses the upstream branch.162 """Upstream source that uses the upstream branch.
161 163
162 :ivar upstream_branch: Branch with upstream sources164 :ivar upstream_branch: Branch with upstream sources
163 :ivar upstream_version_map: Map from version strings to revids165 :ivar upstream_version_map: Map from version strings to revids
164 """166 """
@@ -179,7 +181,7 @@
179 revspec).as_revision_id(self.upstream_branch)181 revspec).as_revision_id(self.upstream_branch)
180 return None182 return None
181183
182 def get_specific_version(self, package, version, target_dir):184 def fetch_tarball(self, package, version, target_dir):
183 self.upstream_branch.lock_read()185 self.upstream_branch.lock_read()
184 try:186 try:
185 revid = self._get_revision_id(version)187 revid = self._get_revision_id(version)
@@ -193,6 +195,11 @@
193 export(rev_tree, target_filename, 'tgz', tarball_base)195 export(rev_tree, target_filename, 'tgz', tarball_base)
194 finally:196 finally:
195 self.upstream_branch.unlock()197 self.upstream_branch.unlock()
198 return target_filename
199
200 def __repr__(self):
201 return "<%s for %r>" % (self.__class__.__name__,
202 self.upstream_branch.base)
196203
197204
198class GetOrigSourceSource(UpstreamSource):205class GetOrigSourceSource(UpstreamSource):
@@ -216,11 +223,11 @@
216 if os.path.exists(fetched_tarball):223 if os.path.exists(fetched_tarball):
217 repack_tarball(fetched_tarball, desired_tarball_name,224 repack_tarball(fetched_tarball, desired_tarball_name,
218 target_dir=target_dir, force_gz=False)225 target_dir=target_dir, force_gz=False)
219 return True226 return fetched_tarball
220 note("get-orig-source did not create %s", desired_tarball_name)227 note("get-orig-source did not create %s", desired_tarball_name)
221 return False228 return None
222229
223 def get_specific_version(self, package, version, target_dir):230 def fetch_tarball(self, package, version, target_dir):
224 if self.larstiq:231 if self.larstiq:
225 rules_name = 'rules'232 rules_name = 'rules'
226 else:233 else:
@@ -238,10 +245,11 @@
238 os.mkdir(export_dir)245 os.mkdir(export_dir)
239 export_dir = os.path.join(export_dir, "debian")246 export_dir = os.path.join(export_dir, "debian")
240 export(self.tree, export_dir, format="dir")247 export(self.tree, export_dir, format="dir")
241 if not self._get_orig_source(base_export_dir,248 tarball_path = self._get_orig_source(base_export_dir,
242 desired_tarball_names, target_dir):249 desired_tarball_names, target_dir)
250 if tarball_path is None:
243 raise PackageVersionNotPresent(package, version, self)251 raise PackageVersionNotPresent(package, version, self)
244 return252 return tarball_path
245 finally:253 finally:
246 shutil.rmtree(tmpdir)254 shutil.rmtree(tmpdir)
247 note("No debian/rules file to try and use for a get-orig-source rule")255 note("No debian/rules file to try and use for a get-orig-source rule")
@@ -285,7 +293,7 @@
285 tmp.close()293 tmp.close()
286 return tempfilename294 return tempfilename
287295
288 def get_specific_version(self, package, version, target_dir):296 def fetch_tarball(self, package, version, target_dir):
289 tempfilename = self._export_watchfile()297 tempfilename = self._export_watchfile()
290 if tempfilename is None:298 if tempfilename is None:
291 raise PackageVersionNotPresent(package, version, self)299 raise PackageVersionNotPresent(package, version, self)
@@ -295,9 +303,7 @@
295 raise PackageVersionNotPresent(package, version, self)303 raise PackageVersionNotPresent(package, version, self)
296 finally:304 finally:
297 os.unlink(tempfilename)305 os.unlink(tempfilename)
298306 return self._tarball_path(package, version, target_dir)
299 def get_latest_version(self, package, version, target_dir):
300 pass
301307
302308
303class SelfSplitSource(UpstreamSource):309class SelfSplitSource(UpstreamSource):
@@ -320,16 +326,17 @@
320 finally:326 finally:
321 shutil.rmtree(tmpdir)327 shutil.rmtree(tmpdir)
322328
323 def get_specific_version(self, package, version, target_dir):329 def fetch_tarball(self, package, version, target_dir):
324 note("Using the current branch without the 'debian' directory "330 note("Using the current branch without the 'debian' directory "
325 "to create the tarball")331 "to create the tarball")
326 self._split(package, version, 332 tarball_path = self._tarball_path(package, version, target_dir)
327 self._tarball_path(package, version, target_dir))333 self._split(package, version, tarball_path)
334 return tarball_path
328335
329336
330class StackedUpstreamSource(UpstreamSource):337class StackedUpstreamSource(UpstreamSource):
331 """An upstream source that checks a list of other upstream sources.338 """An upstream source that checks a list of other upstream sources.
332 339
333 The first source that can provide a tarball, wins. 340 The first source that can provide a tarball, wins.
334 """341 """
335342
@@ -339,10 +346,10 @@
339 def __repr__(self):346 def __repr__(self):
340 return "%s(%r)" % (self.__class__.__name__, self._sources)347 return "%s(%r)" % (self.__class__.__name__, self._sources)
341348
342 def get_specific_version(self, package, version, target_dir):349 def fetch_tarball(self, package, version, target_dir):
343 for source in self._sources:350 for source in self._sources:
344 try:351 try:
345 return source.get_specific_version(package, version, target_dir)352 return source.fetch_tarball(package, version, target_dir)
346 except PackageVersionNotPresent:353 except PackageVersionNotPresent:
347 pass354 pass
348 raise PackageVersionNotPresent(package, version, self)355 raise PackageVersionNotPresent(package, version, self)
@@ -410,13 +417,13 @@
410 if not os.path.exists(self.store_dir):417 if not os.path.exists(self.store_dir):
411 os.makedirs(self.store_dir)418 os.makedirs(self.store_dir)
412 try:419 try:
413 self.source.get_specific_version(self.package,420 self.source.fetch_tarball(self.package,
414 self.version.upstream_version, self.store_dir)421 self.version.upstream_version, self.store_dir)
415 except PackageVersionNotPresent:422 except PackageVersionNotPresent:
416 raise MissingUpstreamTarball(self._tarball_names()[0])423 raise MissingUpstreamTarball(self._tarball_names()[0])
417 else:424 else:
418 note("Using the upstream tarball that is present in "425 note("Using the upstream tarball that is present in %s" %
419 "%s" % self.store_dir)426 self.store_dir)
420 path = self.provide_from_store_dir(target_dir)427 path = self.provide_from_store_dir(target_dir)
421 assert path is not None428 assert path is not None
422 return path429 return path

Subscribers

People subscribed via source and target branches