* grab-attachments, doc/grab-attachments.1:

- add in download attachments from duplicates
  - add in download attachments from all bugs about a package
  - document new options in the manpage
This commit is contained in:
Brian Murray 2011-06-16 12:02:04 -07:00
parent 0d3b618c0b
commit 146b1619f1
3 changed files with 61 additions and 22 deletions

8
debian/changelog vendored
View File

@ -22,7 +22,13 @@ ubuntu-dev-tools (0.125) UNRELEASED; urgency=low
* lp-project-upload: * lp-project-upload:
- fix a bug when new milestone wasn't specified (LP: #797170) - fix a bug when new milestone wasn't specified (LP: #797170)
-- Benjamin Drung <bdrung@debian.org> Sat, 28 May 2011 19:43:10 +0200 [ Brian Murray ]
* grab-attachments, doc/grab-attachments.1:
- add in download attachments from duplicates
- add in download attachments from all bugs about a package
- document new options in the manpage
-- Brian Murray <brian@ubuntu.com> Thu, 16 Jun 2011 11:59:18 -0700
ubuntu-dev-tools (0.124) unstable; urgency=low ubuntu-dev-tools (0.124) unstable; urgency=low

View File

@ -7,7 +7,8 @@ grab\-attachments \- downloads attachments from a Launchpad bug
.B grab\-attachments \-h .B grab\-attachments \-h
.SH DESCRIPTION .SH DESCRIPTION
\fBgrab\-attachments\fR is a script to download all attachments from a \fBgrab\-attachments\fR is a script to download all attachments from a
Launchpad bug report into the a directory named after the bug e.g. bug-1. Launchpad bug report or bug reports with a source package task into
a directory named after the bug e.g. bug-1.
.SH OPTIONS .SH OPTIONS
Listed below are the command line options for grab\-attachments: Listed below are the command line options for grab\-attachments:
@ -26,6 +27,13 @@ the default of "production".
.B \-\-no\-conf .B \-\-no\-conf
Do not read any configuration files, or configuration from environment Do not read any configuration files, or configuration from environment
variables. variables.
.TP
.BR \-d ", " \-\-duplicates
Download attachments from duplicates too.
.TP
.B \-p \fISRCPACKAGE\fR, \fB\-\-package\fR=\fISRCPACKAGE\fR
Download attachments from all bugs with a task for this source
package.
.SH ENVIRONMENT .SH ENVIRONMENT
All of the \fBCONFIGURATION VARIABLES\fR below are also supported as All of the \fBCONFIGURATION VARIABLES\fR below are also supported as
environment variables. environment variables.

View File

@ -2,7 +2,8 @@
# #
# Copyright (C) 2007, Canonical Ltd. # Copyright (C) 2007, Canonical Ltd.
# Written by Daniel Holbach, # Written by Daniel Holbach,
# Stefano Rivera # Stefano Rivera,
# Brian Murray
# #
# ################################################################## # ##################################################################
# #
@ -30,6 +31,27 @@ from ubuntutools.config import UDTConfig
USAGE = "grab-attachments <bug numbers>" USAGE = "grab-attachments <bug numbers>"
def download_attachments(bug):
bug_folder_name = 'bug-%s' % bug.id
try:
os.mkdir(bug_folder_name)
except OSError, error:
if error.errno == errno.EEXIST:
return
for attachment in bug.attachments:
f = attachment.data.open()
filename = os.path.join(os.getcwd(), bug_folder_name,
f.filename)
local_file = open(filename, "w")
local_file.write(f.read())
f.close()
local_file.close()
def main(): def main():
parser = OptionParser('Usage: %prog [options] <bug numbers>') parser = OptionParser('Usage: %prog [options] <bug numbers>')
parser.add_option('-l', '--lpinstance', metavar='INSTANCE', parser.add_option('-l', '--lpinstance', metavar='INSTANCE',
@ -39,8 +61,15 @@ def main():
parser.add_option('--no-conf', parser.add_option('--no-conf',
dest='no_conf', default=False, action='store_true', dest='no_conf', default=False, action='store_true',
help="Don't read config files or environment variables") help="Don't read config files or environment variables")
parser.add_option('-d', '--duplicates', default=False,
action='store_true',
help='Download attachments from duplicates too')
parser.add_option('-p', '--package',
help='Download attachments from all bugs with a '
'task for this source package')
opts, args = parser.parse_args() opts, args = parser.parse_args()
if len(args) < 1: if len(args) < 1 and not opts.package:
parser.error('No bug numbers provided') parser.error('No bug numbers provided')
config = UDTConfig(opts.no_conf) config = UDTConfig(opts.no_conf)
if opts.lpinstance is None: if opts.lpinstance is None:
@ -49,30 +78,26 @@ def main():
try: try:
launchpad = Launchpad.login_with("ubuntu-dev-tools", opts.lpinstance) launchpad = Launchpad.login_with("ubuntu-dev-tools", opts.lpinstance)
if opts.package:
ubuntu = launchpad.projects['ubuntu']
src_package = ubuntu.getSourcePackage(name=opts.package)
if src_package is None:
parser.error('Unable to find package %s' % opts.package)
for task in src_package.searchTasks():
args.append(task.bug.id)
for arg in args: for arg in args:
try: try:
number = int(arg) bug_number = int(arg)
except ValueError: except ValueError:
parser.error("'%s' is not a valid bug number." % arg) parser.error("'%s' is not a valid bug number." % arg)
bug = launchpad.bugs[number] bug = launchpad.bugs[bug_number]
download_attachments(bug)
bug_folder_name = 'bug-%s' % number if opts.duplicates is True:
for bug in bug.duplicates:
try: download_attachments(bug)
os.mkdir(bug_folder_name)
except OSError, error:
if error.errno == errno.EEXIST:
continue
for attachment in bug.attachments:
f = attachment.data.open()
filename = os.path.join(os.getcwd(), bug_folder_name,
f.filename)
local_file = open(filename, "w")
local_file.write(f.read())
f.close()
local_file.close()
# no LP credentials # no LP credentials
except IOError, error: except IOError, error: