Merge lp:~jelmer/lptools/grab-attachments into lp:lptools

Proposed by Jelmer Vernooij
Status: Merged
Merged at revision: 21
Proposed branch: lp:~jelmer/lptools/grab-attachments
Merge into: lp:lptools
Diff against target: 138 lines (+128/-0)
2 files modified
bin/lp-grab-attachments (+87/-0)
doc/lp-grab-attachments.1 (+41/-0)
To merge this branch: bzr merge lp:~jelmer/lptools/grab-attachments
Reviewer Review Type Date Requested Status
lptools Hackers Pending
Review via email: mp+72563@code.launchpad.net

Description of the change

Import the "lp-grab-attachments" tool from ubuntu-dev-tools.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'bin/lp-grab-attachments'
2--- bin/lp-grab-attachments 1970-01-01 00:00:00 +0000
3+++ bin/lp-grab-attachments 2011-08-23 12:54:23 +0000
4@@ -0,0 +1,87 @@
5+#!/usr/bin/python
6+#
7+# Copyright (C) 2007, Canonical Ltd.
8+# Written by Daniel Holbach,
9+# Stefano Rivera,
10+# Brian Murray
11+#
12+# ##################################################################
13+#
14+# This program is free software; you can redistribute it and/or
15+# modify it under the terms of the GNU General Public License
16+# as published by the Free Software Foundation; version 3.
17+#
18+# This program is distributed in the hope that it will be useful,
19+# but WITHOUT ANY WARRANTY; without even the implied warranty of
20+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+# GNU General Public License for more details.
22+#
23+# See file /usr/share/common-licenses/GPL-3 for more details.
24+#
25+# ##################################################################
26+
27+from optparse import OptionParser
28+import errno
29+import os
30+
31+from lptools import config
32+
33+USAGE = "grab-attachments <bug numbers>"
34+
35+
36+def download_attachments(bug):
37+
38+ bug_folder_name = 'bug-%s' % bug.id
39+
40+ try:
41+ os.mkdir(bug_folder_name)
42+ except OSError, error:
43+ if error.errno == errno.EEXIST:
44+ return
45+
46+ for attachment in bug.attachments:
47+ f = attachment.data.open()
48+ filename = os.path.join(os.getcwd(), bug_folder_name, f.filename)
49+ local_file = open(filename, "w")
50+ local_file.write(f.read())
51+ f.close()
52+ local_file.close()
53+
54+
55+def main():
56+ parser = OptionParser('Usage: %prog [options] <bug numbers>')
57+ parser.add_option('-d', '--duplicates', default=False,
58+ action='store_true',
59+ help='Download attachments from duplicates too')
60+ parser.add_option('-p', '--package',
61+ help='Download attachments from all bugs with a '
62+ 'task for this Ubuntu source package')
63+
64+ opts, args = parser.parse_args()
65+ if len(args) < 1 and not opts.package:
66+ parser.error('No bug numbers provided')
67+ launchpad = config.get_launchpad("grab-attachments")
68+
69+ if opts.package:
70+ ubuntu = launchpad.projects['ubuntu']
71+ src_package = ubuntu.getSourcePackage(name=opts.package)
72+ if src_package is None:
73+ parser.error('Unable to find package %s' % opts.package)
74+ for task in src_package.searchTasks():
75+ args.append(task.bug.id)
76+
77+ for arg in args:
78+ try:
79+ bug_number = int(arg)
80+ except ValueError:
81+ parser.error("'%s' is not a valid bug number." % arg)
82+
83+ bug = launchpad.bugs[bug_number]
84+ download_attachments(bug)
85+
86+ if opts.duplicates is True:
87+ for bug in bug.duplicates:
88+ download_attachments(bug)
89+
90+if __name__ == '__main__':
91+ main()
92
93=== added directory 'doc'
94=== added file 'doc/lp-grab-attachments.1'
95--- doc/lp-grab-attachments.1 1970-01-01 00:00:00 +0000
96+++ doc/lp-grab-attachments.1 2011-08-23 12:54:23 +0000
97@@ -0,0 +1,41 @@
98+.TH GRAB\-ATTACHMENTS "1" "10 August 2008" "lptools"
99+.SH NAME
100+grab\-attachments \- downloads attachments from a Launchpad bug
101+.SH SYNOPSIS
102+.B grab\-attachments\fR [\fIoptions\fR] \fIbug-number\fR...
103+.br
104+.B grab\-attachments \-h
105+.SH DESCRIPTION
106+\fBgrab\-attachments\fR is a script to download all attachments from a
107+Launchpad bug report or bug reports with a source package task into
108+a directory named after the bug e.g. bug-1.
109+
110+.SH OPTIONS
111+Listed below are the command line options for grab\-attachments:
112+.TP
113+.I bug-number
114+Specifies the Launchpad bug number that the script should download
115+attachments from.
116+.TP
117+.BR \-h ", " \-\-help
118+Display a help message and exit.
119+.TP
120+.B \-l \fIINSTANCE\fR, \fB\-\-lpinstance\fR=\fIINSTANCE\fR
121+Use the specified instance of Launchpad (e.g. "staging"), instead of
122+the default of "production".
123+.TP
124+.B \-\-no\-conf
125+Do not read any configuration files, or configuration from environment
126+variables.
127+.TP
128+.BR \-d ", " \-\-duplicates
129+Download attachments from duplicates too.
130+.TP
131+.B \-p \fISRCPACKAGE\fR, \fB\-\-package\fR=\fISRCPACKAGE\fR
132+Download attachments from all bugs with a task for this source
133+package.
134+.SH AUTHOR
135+\fBlp-grab\-attachments\fR was written by Daniel Holbach and this manual page
136+was written by Jonathan Patrick Davies.
137+.PP
138+Both are released under the GNU General Public License, version 3.

Subscribers

People subscribed via source and target branches