#!/usr/bin/python # # Copyright (C) 2007, Canonical Ltd. # Written by Daniel Holbach # # ################################################################## # # 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. # # ################################################################## import os import sys import urllib import launchpadbugs.connector as Connector USAGE = "grab-attachments " 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) Bug = Connector.ConnectBug(method="Text") 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 = Bug(number) for a in b.attachments: filename = os.path.join(os.getcwd(), a.url.split("/")[-1]) urllib.urlretrieve(a.url, filename) if __name__ == '__main__': main()