Merge lp:~al-maisan/bzr-builddeb/uri-redirect into lp:~bzr-builddeb-hackers/bzr-builddeb/trunk-old

Proposed by Muharem Hrnjadovic
Status: Merged
Merged at revision: not available
Proposed branch: lp:~al-maisan/bzr-builddeb/uri-redirect
Merge into: lp:~bzr-builddeb-hackers/bzr-builddeb/trunk-old
Diff against target: None lines
To merge this branch: bzr merge lp:~al-maisan/bzr-builddeb/uri-redirect
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+11880@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Muharem Hrnjadovic (al-maisan) wrote :

Hello there!

This branch fixes a

    - few instances of files being opened w/o checking for URI redirections
    - a minor glitch when dsc locations are to be read from a file
      (bzr import-dsc --file ..)

Revision history for this message
James Westby (james-w) wrote :

Looks good, 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 2009-09-14 19:04:02 +0000
3+++ cmds.py 2009-09-16 12:47:18 +0000
4@@ -45,7 +45,6 @@
5 from bzrlib.option import Option
6 from bzrlib.revisionspec import RevisionSpec
7 from bzrlib.trace import info, warning
8-from bzrlib.transport import get_transport
9 from bzrlib.workingtree import WorkingTree
10
11 from bzrlib.plugins.builddeb import (
12@@ -68,7 +67,6 @@
13 DistributionBranchSet,
14 DscCache,
15 DscComp,
16- open_file_via_transport,
17 )
18 from bzrlib.plugins.builddeb.merge_package import fix_ancestry_as_needed
19 from bzrlib.plugins.builddeb.source_distiller import (
20@@ -81,13 +79,16 @@
21 UpstreamBranchSource,
22 get_upstream_sources,
23 )
24-from bzrlib.plugins.builddeb.util import (find_changelog,
25+from bzrlib.plugins.builddeb.util import (
26+ dget_changes,
27+ find_changelog,
28+ find_last_distribution,
29 get_export_upstream_revision,
30- find_last_distribution,
31 lookup_distribution,
32+ open_file,
33+ open_file_via_transport,
34 suite_to_distribution,
35 tarball_name,
36- dget_changes,
37 )
38
39 dont_purge_opt = Option('dont-purge',
40@@ -652,8 +653,7 @@
41 takes_args = ['files*']
42
43 filename_opt = Option('file', help="File containing URIs of source "
44- "packages to import.", type=str, argname="filename",
45- short_name='F')
46+ "packages to import.", type=str, short_name='F')
47
48 takes_options = [filename_opt]
49
50@@ -680,7 +680,7 @@
51 get_dsc_part(from_transport, name)
52 db.import_package(os.path.join(orig_target, filename))
53
54- def run(self, files_list, filename=None):
55+ def run(self, files_list, file=None):
56 from bzrlib.plugins.builddeb.errors import MissingChangelogError
57 try:
58 tree = WorkingTree.open_containing('.')[0]
59@@ -694,14 +694,14 @@
60 "command")
61 if files_list is None:
62 files_list = []
63- if filename is not None:
64- if isinstance(filename, unicode):
65- filename = filename.encode('utf-8')
66- base_dir, path = urlutils.split(filename)
67- sources_file = get_transport(base_dir).get(path)
68+ if file is not None:
69+ if isinstance(file, unicode):
70+ file = file.encode('utf-8')
71+ sources_file = open_file(file)
72 for line in sources_file:
73- line.strip()
74- files_list.append(line)
75+ line = line.strip()
76+ if len(line) > 0:
77+ files_list.append(line)
78 if len(files_list) < 1:
79 raise BzrCommandError("You must give the location of at least one "
80 "source package to install, or use the "
81
82=== modified file 'import_dsc.py'
83--- import_dsc.py 2009-09-14 19:04:02 +0000
84+++ import_dsc.py 2009-09-16 12:26:09 +0000
85@@ -62,7 +62,6 @@
86 from bzrlib.trace import warning, info, mutter
87 from bzrlib.transform import TreeTransform, cook_conflicts, resolve_conflicts
88 from bzrlib.transport import (
89- do_catching_redirections,
90 get_transport,
91 )
92
93@@ -77,7 +76,10 @@
94 UpstreamAlreadyImported,
95 UpstreamBranchAlreadyMerged,
96 )
97-from bzrlib.plugins.builddeb.util import get_commit_info_from_changelog, get_snapshot_revision
98+from bzrlib.plugins.builddeb.util import (
99+ get_commit_info_from_changelog, get_snapshot_revision, open_transport,
100+ open_file_via_transport
101+ )
102
103
104 files_to_ignore = set(['.cvsignore', '.arch-inventory', '.bzrignore',
105@@ -295,26 +297,6 @@
106 tt.apply()
107
108
109-def open_transport(path):
110- """Obtain an appropriate transport instance for the given path."""
111- base_dir, path = urlutils.split(path)
112- transport = get_transport(base_dir)
113- return (path, transport)
114-
115-
116-def open_file_via_transport(filename, transport):
117- """Open a file using the transport, follow redirects as necessary."""
118- def open_file(transport):
119- return transport.get(filename)
120- def follow_redirection(transport, e, redirection_notice):
121- mutter(redirection_notice)
122- _filename, redirected_transport = open_transport(e.target)
123- return redirected_transport
124-
125- result = do_catching_redirections(open_file, transport, follow_redirection)
126- return result
127-
128-
129 class DscCache(object):
130
131 def __init__(self, transport=None):
132
133=== modified file 'repack_tarball.py'
134--- repack_tarball.py 2009-03-08 23:28:22 +0000
135+++ repack_tarball.py 2009-09-16 12:47:18 +0000
136@@ -42,6 +42,7 @@
137 from bzrlib import urlutils
138
139 from bzrlib.plugins.builddeb.errors import UnsupportedRepackFormat
140+from bzrlib.plugins.builddeb.util import open_file, open_file_via_transport
141
142
143 class TgzRepacker(object):
144@@ -138,21 +139,15 @@
145 return None
146
147
148-def _get_file_from_location(location):
149- base_dir, path = urlutils.split(location)
150- transport = get_transport(base_dir)
151- return transport.get(path)
152-
153-
154 def _error_if_exists(target_transport, new_name, source_name):
155 if not source_name.endswith('.tar.gz'):
156 raise FileExists(new_name)
157- source_f = _get_file_from_location(source_name)
158+ source_f = open_file(source_name)
159 try:
160 source_sha = new_sha(source_f.read()).hexdigest()
161 finally:
162 source_f.close()
163- target_f = target_transport.get(new_name)
164+ target_f = open_file_via_transport(new_name, target_transport)
165 try:
166 target_sha = new_sha(target_f.read()).hexdigest()
167 finally:
168@@ -181,7 +176,7 @@
169 target_transport.ensure_base()
170 target_f = target_transport.open_write_stream(new_name)
171 try:
172- source_f = _get_file_from_location(source_name)
173+ source_f = open_file(source_name)
174 try:
175 repacker = repacker_cls(source_f)
176 repacker.repack(target_f)
177
178=== modified file 'util.py'
179--- util.py 2009-07-15 18:17:12 +0000
180+++ util.py 2009-09-16 12:26:09 +0000
181@@ -37,7 +37,9 @@
182 errors,
183 urlutils,
184 )
185-from bzrlib.transport import get_transport
186+from bzrlib.transport import (
187+ do_catching_redirections, get_transport
188+ )
189 from bzrlib.plugins.builddeb.errors import (
190 MissingChangelogError,
191 AddChangelogError,
192@@ -288,12 +290,36 @@
193 f_f.close()
194
195
196+def open_file(path):
197+ filename, transport = open_transport(path)
198+ return open_file_via_transport(filename, transport)
199+
200+
201+def open_transport(path):
202+ """Obtain an appropriate transport instance for the given path."""
203+ base_dir, path = urlutils.split(path)
204+ transport = get_transport(base_dir)
205+ return (path, transport)
206+
207+
208+def open_file_via_transport(filename, transport):
209+ """Open a file using the transport, follow redirects as necessary."""
210+ def open_file(transport):
211+ return transport.get(filename)
212+ def follow_redirection(transport, e, redirection_notice):
213+ mutter(redirection_notice)
214+ _filename, redirected_transport = open_transport(e.target)
215+ return redirected_transport
216+
217+ result = do_catching_redirections(open_file, transport, follow_redirection)
218+ return result
219+
220+
221 def _dget(cls, dsc_location, target_dir):
222 if not os.path.isdir(target_dir):
223 raise errors.NotADirectory(target_dir)
224- base_dir, path = urlutils.split(dsc_location)
225- dsc_t = get_transport(base_dir)
226- dsc_contents = dsc_t.get_bytes(path)
227+ path, dsc_t = open_transport(dsc_location)
228+ dsc_contents = open_file_via_transport(path, dsc_t).read()
229 dsc = cls(dsc_contents)
230 for file_details in dsc['files']:
231 name = file_details['name']

Subscribers

People subscribed via source and target branches