From d0aa685788ec2071b220ee6c9065a56dc51efd56 Mon Sep 17 00:00:00 2001 From: Brian Murray Date: Mon, 18 Apr 2011 11:16:16 -0700 Subject: [PATCH 1/4] grab-attachments: put attachments in a folder named after the bug number which prevents clobbering of attachments if multiple bugs have the same attachment name --- grab-attachments | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/grab-attachments b/grab-attachments index 51771cc..71ca344 100755 --- a/grab-attachments +++ b/grab-attachments @@ -56,6 +56,9 @@ def main(): bug = launchpad.bugs[number] + os.mkdir('bug-%s' % number) + os.chdir('bug-%s' % number) + for attachment in bug.attachments: f = attachment.data.open() filename = os.path.join(os.getcwd(), f.filename) @@ -64,6 +67,8 @@ def main(): f.close() local_file.close() + os.chdir('../') + # no LP credentials except IOError, error: print error From 66a1d334812f3b2a8e987536b9431aa448830adf Mon Sep 17 00:00:00 2001 From: Brian Murray Date: Mon, 18 Apr 2011 11:28:22 -0700 Subject: [PATCH 2/4] no need to change directories --- grab-attachments | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/grab-attachments b/grab-attachments index 71ca344..8d52b03 100755 --- a/grab-attachments +++ b/grab-attachments @@ -56,19 +56,23 @@ def main(): bug = launchpad.bugs[number] - os.mkdir('bug-%s' % number) - os.chdir('bug-%s' % number) + bug_folder_name = 'bug-%s' % number + + try: + os.mkdir(bug_folder_name) + except OSError, error: + if 'file exists' in error: + 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() local_file.close() - os.chdir('../') - # no LP credentials except IOError, error: print error From 1d36de0fbb0a6f2ae234ce2f10df53e1f2ba4d43 Mon Sep 17 00:00:00 2001 From: Brian Murray Date: Tue, 19 Apr 2011 12:43:25 -0700 Subject: [PATCH 3/4] make changes based on reviewer feedback --- debian/changelog | 6 +++++- doc/grab-attachments.1 | 2 +- grab-attachments | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/debian/changelog b/debian/changelog index 756398f..3008fd2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -4,7 +4,11 @@ ubuntu-dev-tools (0.122) UNRELEASED; urgency=low * lp-project-upload: Add an optional parameter for creating a new milestone to add future bugs to. - -- Ted Gould Tue, 19 Apr 2011 17:32:03 +0200 + [ Brian Murray ] + * grab-attachments: download the attachments to a folder named after the bug + number e.g. bug-1 + + -- Brian Murray Tue, 19 Apr 2011 12:41:41 -0700 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 8d52b03..65ded09 100755 --- a/grab-attachments +++ b/grab-attachments @@ -61,7 +61,7 @@ def main(): try: os.mkdir(bug_folder_name) except OSError, error: - if 'file exists' in error: + if error.errno == 17: continue for attachment in bug.attachments: From 96381b0ff3543c2d58578a2d01dc2ea8fc8d2143 Mon Sep 17 00:00:00 2001 From: Brian Murray Date: Tue, 19 Apr 2011 14:55:27 -0700 Subject: [PATCH 4/4] use errno and errno.EEXIST --- grab-attachments | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/grab-attachments b/grab-attachments index 65ded09..139efaf 100755 --- a/grab-attachments +++ b/grab-attachments @@ -20,6 +20,7 @@ # ################################################################## from optparse import OptionParser +import errno import os import sys @@ -61,7 +62,7 @@ def main(): try: os.mkdir(bug_folder_name) except OSError, error: - if error.errno == 17: + if error.errno == errno.EEXIST: continue for attachment in bug.attachments: