3
# Copyright (C) 2007, Canonical Ltd.
4
# Written by Daniel Holbach,
8
# ##################################################################
10
# This program is free software; you can redistribute it and/or
11
# modify it under the terms of the GNU General Public License
12
# as published by the Free Software Foundation; version 3.
14
# This program is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU General Public License for more details.
19
# See file /usr/share/common-licenses/GPL-3 for more details.
21
# ##################################################################
23
from optparse import OptionParser
27
from lptools import config
29
USAGE = "lp-grab-attachments <bug numbers>"
32
def download_attachments(bug):
34
bug_folder_name = 'bug-%s' % bug.id
37
os.mkdir(bug_folder_name)
38
except OSError, error:
39
if error.errno == errno.EEXIST:
42
for attachment in bug.attachments:
43
f = attachment.data.open()
44
filename = os.path.join(os.getcwd(), bug_folder_name, f.filename)
45
local_file = open(filename, "w")
46
local_file.write(f.read())
52
parser = OptionParser('Usage: %prog [options] <bug numbers>')
53
parser.add_option('-d', '--duplicates', default=False,
55
help='Download attachments from duplicates too')
56
parser.add_option('-p', '--package',
57
help='Download attachments from all bugs with a '
58
'task for this Ubuntu source package')
60
opts, args = parser.parse_args()
61
if len(args) < 1 and not opts.package:
62
parser.error('No bug numbers provided')
63
launchpad = config.get_launchpad("grab-attachments")
66
ubuntu = launchpad.projects['ubuntu']
67
src_package = ubuntu.getSourcePackage(name=opts.package)
68
if src_package is None:
69
parser.error('Unable to find package %s' % opts.package)
70
for task in src_package.searchTasks():
71
args.append(task.bug.id)
77
parser.error("'%s' is not a valid bug number." % arg)
79
bug = launchpad.bugs[bug_number]
80
download_attachments(bug)
82
if opts.duplicates is True:
83
for bug in bug.duplicates:
84
download_attachments(bug)
86
if __name__ == '__main__':