Merge lp:~gz/langpack-o-matic/fetch_tarballs_urlopen_1043846 into lp:langpack-o-matic

Proposed by Martin Packman
Status: Merged
Merged at revision: 430
Proposed branch: lp:~gz/langpack-o-matic/fetch_tarballs_urlopen_1043846
Merge into: lp:langpack-o-matic
Diff against target: 32 lines (+7/-6)
1 file modified
lib/static_translations.py (+7/-6)
To merge this branch: bzr merge lp:~gz/langpack-o-matic/fetch_tarballs_urlopen_1043846
Reviewer Review Type Date Requested Status
Martin Pitt (community) Approve
Review via email: mp+122086@code.launchpad.net

Description of the change

Raise an exception if when fetching a tarball launchpad gives an error page. This branch basically just switches urlretrieve which ignores errors for urlopen which throws instead.

I've manually tested this with Python 2 and it appears to work, but I'm not sure if the code is exercised by the existing automated testing.

To post a comment you must log in.
Revision history for this message
Martin Pitt (pitti) wrote :

Thanks for this!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/static_translations.py'
2--- lib/static_translations.py 2011-10-10 08:42:17 +0000
3+++ lib/static_translations.py 2012-08-30 15:08:57 +0000
4@@ -5,10 +5,10 @@
5 import tarfile
6
7 try:
8- from urllib.request import urlretrieve
9+ from urllib.request import urlopen
10 except ImportError:
11 # python 2 fallback
12- from urllib import urlretrieve
13+ from urllib2 import urlopen
14
15 from macros import _file_map
16
17@@ -102,10 +102,11 @@
18 logging.debug('fetching tarballs...')
19 for t in tarball_urls:
20 logging.debug(' ' + t)
21- (dest, _) = urlretrieve(t)
22- assert subprocess.call(['tar', '-C', unpack_dir, '-xzf', dest]) == 0
23- if t != dest:
24- os.unlink(dest)
25+ response = urlopen(t)
26+ with tempfile.TemporaryFile() as f:
27+ shutil.copyfileobj(response, f)
28+ f.seek(0)
29+ subprocess.check_call(['tar', '-xzC', unpack_dir], stdin=f)
30
31 # rename to *-langpack
32 logging.debug('renaming to *-langpack...')

Subscribers

People subscribed via source and target branches