~jelmer/lptools/breezy-python3

« back to all changes in this revision

Viewing changes to bin/lp-grab-attachments

  • Committer: Tarmac
  • Author(s): Brian Murray
  • Date: 2012-05-31 21:31:31 UTC
  • mfrom: (39.1.1 upstream)
  • Revision ID: tarmac-20120531213131-xonupg3h13ip1xxt
lp-grab-attachments: add option to download bug descriptions too

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
# ##################################################################
22
22
 
23
23
from optparse import OptionParser
 
24
import codecs
24
25
import errno
25
26
import os
26
27
 
29
30
USAGE = "lp-grab-attachments <bug numbers>"
30
31
 
31
32
 
32
 
def download_attachments(bug):
 
33
def download_attachments(bug, descriptions):
33
34
 
34
35
    bug_folder_name = 'bug-%s' % bug.id
35
36
 
39
40
        if error.errno == errno.EEXIST:
40
41
            return
41
42
 
 
43
    if descriptions:
 
44
        description = bug.description
 
45
        filename = os.path.join(os.getcwd(), bug_folder_name,
 
46
            'Description.txt')
 
47
        local_file = codecs.open(filename, encoding="utf-8", mode="w")
 
48
        local_file.write(description)
 
49
        local_file.close()
 
50
 
42
51
    for attachment in bug.attachments:
43
52
        f = attachment.data.open()
44
53
        filename = os.path.join(os.getcwd(), bug_folder_name, f.filename)
59
68
    parser.add_option('-P', '--project',
60
69
                      help='Download attachments from all bugs with a '
61
70
                           'open task for this project')
 
71
    parser.add_option('-D', '--descriptions', default=False,
 
72
                      action='store_true',
 
73
                      help='Also download bug descriptions as Description.txt')
62
74
 
63
75
    opts, args = parser.parse_args()
64
76
    if len(args) < 1 and not opts.package and not opts.project:
88
100
            parser.error("'%s' is not a valid bug number." % arg)
89
101
 
90
102
        bug = launchpad.bugs[bug_number]
91
 
        download_attachments(bug)
 
103
        download_attachments(bug, opts.descriptions)
92
104
 
93
105
        if opts.duplicates is True:
94
106
            for bug in bug.duplicates:
95
 
                download_attachments(bug)
 
107
                download_attachments(bug, opts.descriptions)
96
108
 
97
109
if __name__ == '__main__':
98
110
    main()