* 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:
- 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

View File

@ -7,7 +7,8 @@ grab\-attachments \- downloads attachments from a Launchpad bug
.B grab\-attachments \-h
.SH DESCRIPTION
\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
Listed below are the command line options for grab\-attachments:
@ -26,6 +27,13 @@ the default of "production".
.B \-\-no\-conf
Do not read any configuration files, or configuration from environment
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
All of the \fBCONFIGURATION VARIABLES\fR below are also supported as
environment variables.

View File

@ -2,7 +2,8 @@
#
# Copyright (C) 2007, Canonical Ltd.
# Written by Daniel Holbach,
# Stefano Rivera
# Stefano Rivera,
# Brian Murray
#
# ##################################################################
#
@ -30,40 +31,16 @@ from ubuntutools.config import UDTConfig
USAGE = "grab-attachments <bug numbers>"
def main():
parser = OptionParser('Usage: %prog [options] <bug numbers>')
parser.add_option('-l', '--lpinstance', metavar='INSTANCE',
dest='lpinstance', default=None,
help='Launchpad instance to connect to '
'(default: production)')
parser.add_option('--no-conf',
dest='no_conf', default=False, action='store_true',
help="Don't read config files or environment variables")
opts, args = parser.parse_args()
if len(args) < 1:
parser.error('No bug numbers provided')
config = UDTConfig(opts.no_conf)
if opts.lpinstance is None:
opts.lpinstance = config.get_value('LPINSTANCE')
try:
launchpad = Launchpad.login_with("ubuntu-dev-tools", opts.lpinstance)
def download_attachments(bug):
for arg in args:
try:
number = int(arg)
except ValueError:
parser.error("'%s' is not a valid bug number." % arg)
bug = launchpad.bugs[number]
bug_folder_name = 'bug-%s' % number
bug_folder_name = 'bug-%s' % bug.id
try:
os.mkdir(bug_folder_name)
except OSError, error:
if error.errno == errno.EEXIST:
continue
return
for attachment in bug.attachments:
f = attachment.data.open()
@ -74,6 +51,54 @@ def main():
f.close()
local_file.close()
def main():
parser = OptionParser('Usage: %prog [options] <bug numbers>')
parser.add_option('-l', '--lpinstance', metavar='INSTANCE',
dest='lpinstance', default=None,
help='Launchpad instance to connect to '
'(default: production)')
parser.add_option('--no-conf',
dest='no_conf', default=False, action='store_true',
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()
if len(args) < 1 and not opts.package:
parser.error('No bug numbers provided')
config = UDTConfig(opts.no_conf)
if opts.lpinstance is None:
opts.lpinstance = config.get_value('LPINSTANCE')
try:
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:
try:
bug_number = int(arg)
except ValueError:
parser.error("'%s' is not a valid bug number." % arg)
bug = launchpad.bugs[bug_number]
download_attachments(bug)
if opts.duplicates is True:
for bug in bug.duplicates:
download_attachments(bug)
# no LP credentials
except IOError, error:
print error