2008-03-10 11:36:17 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
#
|
2008-08-11 20:06:35 +02:00
|
|
|
# Copyright (C) 2007, Canonical Ltd.
|
2010-12-21 22:42:29 +02:00
|
|
|
# Written by Daniel Holbach,
|
|
|
|
# Stefano Rivera
|
2008-03-10 11:36:17 +01:00
|
|
|
#
|
2008-08-11 20:06:35 +02:00
|
|
|
# ##################################################################
|
2008-03-10 11:36:17 +01:00
|
|
|
#
|
2008-08-11 20:06:35 +02:00
|
|
|
# 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.
|
2010-12-03 00:06:43 +01:00
|
|
|
#
|
2008-08-11 20:06:35 +02:00
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# ##################################################################
|
2008-03-10 11:36:17 +01:00
|
|
|
|
2010-12-21 22:33:53 +02:00
|
|
|
from optparse import OptionParser
|
2008-03-10 11:36:17 +01:00
|
|
|
import os
|
|
|
|
import sys
|
2010-12-21 22:33:53 +02:00
|
|
|
|
2011-03-01 00:30:54 +02:00
|
|
|
from launchpadlib.launchpad import Launchpad
|
|
|
|
|
2010-12-21 22:42:29 +02:00
|
|
|
from ubuntutools.config import UDTConfig
|
2008-03-10 11:36:17 +01:00
|
|
|
|
|
|
|
USAGE = "grab-attachments <bug numbers>"
|
|
|
|
|
|
|
|
def main():
|
2010-12-27 21:54:31 +01:00
|
|
|
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()
|
2010-12-21 22:33:53 +02:00
|
|
|
if len(args) < 1:
|
2010-12-27 21:54:31 +01:00
|
|
|
parser.error('No bug numbers provided')
|
2010-12-21 22:42:29 +02:00
|
|
|
config = UDTConfig(opts.no_conf)
|
|
|
|
if opts.lpinstance is None:
|
|
|
|
opts.lpinstance = config.get_value('LPINSTANCE')
|
2009-01-21 10:50:26 +00:00
|
|
|
|
2009-11-07 19:34:59 +00:00
|
|
|
try:
|
2011-03-01 00:30:54 +02:00
|
|
|
launchpad = Launchpad.login_with("ubuntu-dev-tools", opts.lpinstance)
|
2009-11-07 19:34:59 +00:00
|
|
|
|
2010-12-21 22:33:53 +02:00
|
|
|
for arg in args:
|
2009-11-07 19:34:59 +00:00
|
|
|
try:
|
|
|
|
number = int(arg)
|
2010-12-27 21:54:31 +01:00
|
|
|
except ValueError:
|
|
|
|
parser.error("'%s' is not a valid bug number." % arg)
|
2010-12-03 00:06:43 +01:00
|
|
|
|
2010-12-27 21:54:31 +01:00
|
|
|
bug = launchpad.bugs[number]
|
2010-12-03 00:06:43 +01:00
|
|
|
|
2011-04-18 11:16:16 -07:00
|
|
|
os.mkdir('bug-%s' % number)
|
|
|
|
os.chdir('bug-%s' % number)
|
|
|
|
|
2010-12-27 21:54:31 +01:00
|
|
|
for attachment in bug.attachments:
|
|
|
|
f = attachment.data.open()
|
2009-11-07 19:34:59 +00:00
|
|
|
filename = os.path.join(os.getcwd(), f.filename)
|
|
|
|
local_file = open(filename, "w")
|
|
|
|
local_file.write(f.read())
|
|
|
|
f.close()
|
|
|
|
local_file.close()
|
|
|
|
|
2011-04-18 11:16:16 -07:00
|
|
|
os.chdir('../')
|
|
|
|
|
2009-11-07 19:34:59 +00:00
|
|
|
# no LP credentials
|
2010-12-27 21:54:31 +01:00
|
|
|
except IOError, error:
|
|
|
|
print error
|
2009-11-07 19:34:59 +00:00
|
|
|
sys.exit(1)
|
2008-03-10 11:36:17 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|