Merge lp:~jelmer/bzr-builddeb/no-force-gz into lp:bzr-builddeb

Proposed by Jelmer Vernooij
Status: Merged
Approved by: James Westby
Approved revision: 583
Merged at revision: 583
Proposed branch: lp:~jelmer/bzr-builddeb/no-force-gz
Merge into: lp:bzr-builddeb
Diff against target: 232 lines (+53/-50)
6 files modified
cmds.py (+1/-2)
dh_make.py (+1/-2)
repack_tarball.py (+39/-38)
tests/test_repack_tarball.py (+7/-1)
tests/test_repack_tarball_extra.py (+1/-2)
upstream/__init__.py (+4/-5)
To merge this branch: bzr merge lp:~jelmer/bzr-builddeb/no-force-gz
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+68167@code.launchpad.net

Description of the change

Remove the force_gz argument to the repacker; instead, use the target name to determine what to generate.

This prevents us from generating .tar.bz2 files that actually have gz compression and vice versa.

To post a comment you must log in.
Revision history for this message
James Westby (james-w) wrote :

Good idea.

Thanks,

James

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-06-28 08:41:44 +0000
3+++ cmds.py 2011-07-17 06:08:40 +0000
4@@ -578,8 +578,7 @@
5 dest_name = tarball_name(package, version, None, format=format)
6 tarball_filename = os.path.join(orig_dir, dest_name)
7 try:
8- repack_tarball(location, dest_name, target_dir=orig_dir,
9- force_gz=not v3)
10+ repack_tarball(location, dest_name, target_dir=orig_dir)
11 except FileExists:
12 raise BzrCommandError("The target file %s already exists, and is either "
13 "different to the new upstream tarball, or they "
14
15=== modified file 'dh_make.py'
16--- dh_make.py 2011-06-28 08:41:44 +0000
17+++ dh_make.py 2011-07-17 06:08:40 +0000
18@@ -66,8 +66,7 @@
19 format = "lzma"
20 dest_name = util.tarball_name(package_name, version, None, format=format)
21 trace.note("Fetching tarball")
22- repack_tarball(tarball, dest_name, target_dir=orig_dir,
23- force_gz=not use_v3)
24+ repack_tarball(tarball, dest_name, target_dir=orig_dir)
25 provider = upstream.UpstreamProvider(package_name, version,
26 orig_dir, [])
27 orig_files = provider.provide(os.path.join(tree.basedir, ".."))
28
29=== modified file 'repack_tarball.py'
30--- repack_tarball.py 2011-06-24 13:23:49 +0000
31+++ repack_tarball.py 2011-07-17 06:08:40 +0000
32@@ -141,39 +141,37 @@
33
34
35 def get_filetype(filename):
36- types = [".tar.gz", ".tgz", ".tar.bz2", ".tar.xz", ".tar.lzma", ".tbz2",
37- ".tar", ".zip"]
38- for filetype in types:
39+ types = {
40+ ".tar.gz": "gz",
41+ ".tgz": "gz",
42+ ".tar.bz2": "bz2",
43+ ".tar.xz": "xz",
44+ ".tar.lzma": "lzma",
45+ ".tbz2": "bz2",
46+ ".tar": "tar",
47+ ".zip": "zip"
48+ }
49+ for filetype, name in types.iteritems():
50 if filename.endswith(filetype):
51- return filetype
52-
53-
54-def get_repacker_class(source_filename, force_gz=True):
55+ return name
56+
57+
58+def get_repacker_class(source_format, target_format):
59 """Return the appropriate repacker based on the file extension."""
60- filetype = get_filetype(source_filename)
61- if (filetype == ".tar.gz" or filetype == ".tgz"):
62- return CopyRepacker
63- if (filetype == ".tar.bz2" or filetype == ".tbz2"):
64- if force_gz:
65- return Tbz2TgzRepacker
66- return CopyRepacker
67- if filetype == ".tar.lzma":
68- if force_gz:
69- return TarLzma2TgzRepacker
70- return CopyRepacker
71- if filetype == ".tar.xz":
72- return TarLzma2TgzRepacker
73- if filetype == ".tar":
74- return TarTgzRepacker
75- if filetype == ".zip":
76- return ZipTgzRepacker
77- return None
78-
79-
80-def _error_if_exists(target_transport, new_name, source_name, force_gz=True):
81+ if source_format == target_format:
82+ return CopyRepacker
83+ known_formatters = {
84+ ("bz2", "gz"): Tbz2TgzRepacker,
85+ ("lzma", "gz"): TarLzma2TgzRepacker,
86+ ("xz", "gz"): TarLzma2TgzRepacker,
87+ ("tar", "gz"): TarTgzRepacker,
88+ ("zip", "gz"): ZipTgzRepacker,
89+ }
90+ return known_formatters.get((source_format, target_format))
91+
92+
93+def _error_if_exists(target_transport, new_name, source_name):
94 source_filetype = get_filetype(source_name)
95- if force_gz and source_filetype != ".tar.gz":
96- raise FileExists(new_name)
97 source_f = open_file(source_name)
98 try:
99 source_sha = new_sha(source_f.read()).hexdigest()
100@@ -201,8 +199,10 @@
101 target_f.close()
102
103
104-def _repack_other(target_transport, new_name, source_name, force_gz=True):
105- repacker_cls = get_repacker_class(source_name, force_gz=force_gz)
106+def _repack_other(target_transport, new_name, source_name):
107+ source_filetype = get_filetype(source_name)
108+ target_filetype = get_filetype(new_name)
109+ repacker_cls = get_repacker_class(source_filetype, target_filetype)
110 if repacker_cls is None:
111 raise UnsupportedRepackFormat(source_name)
112 target_transport.ensure_base()
113@@ -218,7 +218,7 @@
114 target_f.close()
115
116
117-def repack_tarball(source_name, new_name, target_dir=None, force_gz=True):
118+def repack_tarball(source_name, new_name, target_dir=None):
119 """Repack the file/dir named to a .tar.gz with the chosen name.
120
121 This function takes a named file of either .tar.gz, .tar .tgz .tar.bz2
122@@ -239,7 +239,6 @@
123 :keyword target_dir: the directory to consider new_name relative to, and
124 will be created if non-existant.
125 :type target_dir: string
126- :param force_gz: whether to repack other .tar files to .tar.gz.
127 :return: None
128 :throws NoSuchFile: if source_name doesn't exist.
129 :throws FileExists: if the target filename (after considering target_dir)
130@@ -257,11 +256,13 @@
131 extra, new_name = os.path.split(new_name)
132 target_transport = get_transport(os.path.join(target_dir, extra))
133 if target_transport.has(new_name):
134- _error_if_exists(target_transport, new_name, source_name,
135- force_gz=force_gz)
136+ source_format = get_filetype(source_name)
137+ target_format = get_filetype(new_name)
138+ if source_format != target_format:
139+ raise FileExists(new_name)
140+ _error_if_exists(target_transport, new_name, source_name)
141 return
142 if os.path.isdir(source_name):
143 _repack_directory(target_transport, new_name, source_name)
144 else:
145- _repack_other(target_transport, new_name, source_name,
146- force_gz=force_gz)
147+ _repack_other(target_transport, new_name, source_name)
148
149=== modified file 'tests/test_repack_tarball.py'
150--- tests/test_repack_tarball.py 2011-06-24 13:23:49 +0000
151+++ tests/test_repack_tarball.py 2011-07-17 06:08:40 +0000
152@@ -27,6 +27,7 @@
153 from bzrlib.plugins.builddeb.errors import UnsupportedRepackFormat
154 from bzrlib.plugins.builddeb.repack_tarball import (
155 repack_tarball,
156+ get_filetype,
157 get_repacker_class,
158 )
159 from bzrlib.plugins.builddeb.tests import TestCaseInTempDir
160@@ -69,7 +70,9 @@
161
162 def test_repack_tarball_non_extant(self):
163 error = NoSuchFile
164- if (get_repacker_class(self.old_tarball) is None):
165+ old_format = get_filetype(self.old_tarball)
166+ new_format = get_filetype(self.new_tarball)
167+ if (get_repacker_class(old_format, new_format) is None):
168 # directory, can't really be detected remotely, so we have a
169 # error that could mean two things
170 error = UnsupportedRepackFormat
171@@ -132,3 +135,6 @@
172 self.assertPathDoesNotExist(self.new_tarball)
173 self.assertPathDoesNotExist(os.path.join(target_dir, self.new_tarball))
174 self.assertPathExists(target_dir)
175+
176+
177+
178
179=== modified file 'tests/test_repack_tarball_extra.py'
180--- tests/test_repack_tarball_extra.py 2011-06-24 13:23:49 +0000
181+++ tests/test_repack_tarball_extra.py 2011-07-17 06:08:40 +0000
182@@ -118,8 +118,7 @@
183 bz2_tarball_name = 'package-0.2.tar.bz2'
184 create_basedir('package-0.2/', files=['README'])
185 make_new_upstream_tarball_bz2(bz2_tarball_name)
186- repack_tarball(bz2_tarball_name, bz2_tarball_name, target_dir=".",
187- force_gz=False)
188+ repack_tarball(bz2_tarball_name, bz2_tarball_name, target_dir=".")
189 self.assertPathExists(bz2_tarball_name)
190
191 def test_exists_different_bz2(self):
192
193=== modified file 'upstream/__init__.py'
194--- upstream/__init__.py 2011-06-28 08:41:44 +0000
195+++ upstream/__init__.py 2011-07-17 06:08:40 +0000
196@@ -177,7 +177,7 @@
197 fetched_tarball = os.path.join(source_dir, filename)
198 if os.path.exists(fetched_tarball):
199 repack_tarball(fetched_tarball, filename,
200- target_dir=target_dir, force_gz=False)
201+ target_dir=target_dir)
202 filenames.append(os.path.join(target_dir, filename))
203 if filenames:
204 return filenames
205@@ -441,7 +441,7 @@
206 return None
207 for path in paths:
208 repack_tarball(path, os.path.basename(path),
209- target_dir=target_dir, force_gz=False)
210+ target_dir=target_dir)
211 return paths
212
213
214@@ -482,7 +482,7 @@
215 if version != self.version:
216 raise PackageVersionNotPresent(package, version, self)
217 dest_name = tarball_name(package, version)
218- repack_tarball(self.path, dest_name, target_dir=target_dir, force_gz=True)
219+ repack_tarball(self.path, dest_name, target_dir=target_dir)
220 return [os.path.join(target_dir, dest_name)]
221
222 def get_latest_version(self, package, version):
223@@ -556,8 +556,7 @@
224 outf.close()
225 finally:
226 inf.close()
227- repack_tarball(tmppath, dest_name, target_dir=target_dir,
228- force_gz=True)
229+ repack_tarball(tmppath, dest_name, target_dir=target_dir)
230 return os.path.join(target_dir, dest_name)
231 finally:
232 shutil.rmtree(tmpdir)

Subscribers

People subscribed via source and target branches