Merge lp:~laney/ubuntu-archive-tools/queue-fetch-copies into lp:ubuntu-archive-tools

Proposed by Iain Lane
Status: Merged
Merged at revision: 700
Proposed branch: lp:~laney/ubuntu-archive-tools/queue-fetch-copies
Merge into: lp:ubuntu-archive-tools
Diff against target: 68 lines (+29/-13)
1 file modified
queue (+29/-13)
To merge this branch: bzr merge lp:~laney/ubuntu-archive-tools/queue-fetch-copies
Reviewer Review Type Date Requested Status
Colin Watson Approve
Review via email: mp+160503@code.launchpad.net

Description of the change

Now that we can get the source archive for copies, it's fairly straightforward to extend queue to fetch them.

I took a fairly minimal approach and the changes to make urls() work for both SPPH and package_upload objects might be confusing/bad style. If so then some more refactoring could be done.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :

Looks good to me. Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'queue'
2--- queue 2012-12-19 10:20:09 +0000
3+++ queue 2013-04-23 21:09:29 +0000
4@@ -227,12 +227,17 @@
5 return 0
6
7
8+# Get librarian URLs for source_package_publishing_history or package_upload
9+# objects
10 def urls(item):
11 urls = []
12- urls.append(item.changes_file_url)
13+ try:
14+ urls.append(item.changes_file_url)
15+ urls.extend(item.customFileUrls())
16+ except AttributeError: # Copies won't have this
17+ urls.append(item.changesFileUrl())
18 urls.extend(item.sourceFileUrls())
19 urls.extend(item.binaryFileUrls())
20- urls.extend(item.customFileUrls())
21 # On staging we may get None URLs due to missing library files; filter
22 # these out.
23 urls = list(filter(None, urls))
24@@ -246,22 +251,33 @@
25 for item in items:
26 if item.contains_copy:
27 # TODO perhaps fetch from the copy source?
28- print("Cannot fetch %s (copy)" % display_name(item))
29+ print("Fetching %s (copy)" % display_name(item))
30+ archive = item.copy_source_archive
31+ item = archive.getPublishedSources(exact_match=True,
32+ source_name=item.package_name,
33+ version=item.package_version)
34+ if item:
35+ fetch_item(options, item[0])
36+ else:
37+ print("Error: Can't fetch source package")
38 else:
39 print("Fetching %s" % display_name(item))
40- for url in urls(item):
41- path = urlsplit(url)[2]
42- filename = unquote(path.split("/")[-1])
43- exists = os.path.exists(filename)
44- if options.overwrite or not exists:
45- print("Constructing %s (%s)" % (filename, url))
46- urlretrieve(url, filename)
47- elif exists:
48- print("Not overwriting existing %s with %s" %
49- (filename, url))
50+ fetch_item(options, item)
51 ret = 0
52 return ret
53
54+def fetch_item(options, item):
55+ for url in urls(item):
56+ path = urlsplit(url)[2]
57+ filename = unquote(path.split("/")[-1])
58+ exists = os.path.exists(filename)
59+ if options.overwrite or not exists:
60+ print("Constructing %s (%s)" % (filename, url))
61+ urlretrieve(url, filename)
62+ elif exists:
63+ print("Not overwriting existing %s with %s" %
64+ (filename, url))
65+ ret = 0
66
67 def show_urls(options, args):
68 """Show the URLs from which a queue item may be downloaded."""

Subscribers

People subscribed via source and target branches