diff --git a/debian/changelog b/debian/changelog index a51ae45..65547a1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -7,6 +7,10 @@ ubuntu-dev-tools (0.122) UNRELEASED; urgency=low [ Benjamin Drung ] * data/ubuntu.csv: Update end-of-life dates. + [ Brian Murray ] + * grab-attachments: download the attachments to a folder named after the bug + number e.g. bug-1 + -- Benjamin Drung Wed, 20 Apr 2011 00:25:03 +0200 ubuntu-dev-tools (0.121) unstable; urgency=low diff --git a/doc/grab-attachments.1 b/doc/grab-attachments.1 index 97a71bc..aa833c7 100644 --- a/doc/grab-attachments.1 +++ b/doc/grab-attachments.1 @@ -7,7 +7,7 @@ grab\-attachments \- downloads attachments from a Launchpad bug .B grab\-attachments \-h .SH DESCRIPTION \fBgrab\-attachments\fR is a script to download all attachments from a -Launchpad bug report into the current directory. +Launchpad bug report into the a directory named after the bug e.g. bug-1. .SH OPTIONS Listed below are the command line options for grab\-attachments: diff --git a/grab-attachments b/grab-attachments index 51771cc..139efaf 100755 --- a/grab-attachments +++ b/grab-attachments @@ -20,6 +20,7 @@ # ################################################################## from optparse import OptionParser +import errno import os import sys @@ -56,9 +57,18 @@ def main(): bug = launchpad.bugs[number] + bug_folder_name = 'bug-%s' % number + + try: + os.mkdir(bug_folder_name) + except OSError, error: + if error.errno == errno.EEXIST: + continue + for attachment in bug.attachments: f = attachment.data.open() - filename = os.path.join(os.getcwd(), f.filename) + filename = os.path.join(os.getcwd(), bug_folder_name, + f.filename) local_file = open(filename, "w") local_file.write(f.read()) f.close()