2008-03-10 11:36:17 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
#
|
2008-08-11 20:06:35 +02:00
|
|
|
# Copyright (C) 2007, Canonical Ltd.
|
|
|
|
# Written by Daniel Holbach
|
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.
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
2009-01-19 22:37:27 +00:00
|
|
|
from ubuntutools.lp.libsupport import get_launchpad
|
2008-03-10 11:36:17 +01:00
|
|
|
|
|
|
|
USAGE = "grab-attachments <bug numbers>"
|
|
|
|
|
|
|
|
def main():
|
|
|
|
if len(sys.argv) == 1:
|
|
|
|
print >> sys.stderr, USAGE
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if sys.argv[1] in ["--help", "-h"]:
|
|
|
|
print USAGE
|
|
|
|
sys.exit(0)
|
2009-01-21 10:50:26 +00:00
|
|
|
|
2009-11-07 19:34:59 +00:00
|
|
|
try:
|
|
|
|
launchpad = get_launchpad("ubuntu-dev-tools")
|
|
|
|
|
|
|
|
for arg in sys.argv[1:]:
|
|
|
|
try:
|
|
|
|
number = int(arg)
|
|
|
|
except:
|
|
|
|
print >> sys.stderr, "'%s' is not a valid bug number." % arg
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
b = launchpad.bugs[number]
|
|
|
|
|
|
|
|
for a in b.attachments:
|
|
|
|
f = a.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, e:
|
|
|
|
print e
|
|
|
|
sys.exit(1)
|
2008-03-10 11:36:17 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|
|
|
|
|