1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#!/usr/bin/python
#
# Copyright (C) 2007, Canonical Ltd.
# Written by Daniel Holbach,
# Stefano Rivera
#
# ##################################################################
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# See file /usr/share/common-licenses/GPL-3 for more details.
#
# ##################################################################
from optparse import OptionParser
import os
import sys
from launchpadlib.launchpad import Launchpad
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)
for arg in args:
try:
number = int(arg)
except ValueError:
parser.error("'%s' is not a valid bug number." % arg)
bug = launchpad.bugs[number]
for attachment in bug.attachments:
f = attachment.data.open()
filename = os.path.join(os.getcwd(), f.filename)
local_file = open(filename, "w")
local_file.write(f.read())
f.close()
local_file.close()
# no LP credentials
except IOError, error:
print error
sys.exit(1)
if __name__ == '__main__':
main()
|