HMontoliu
Attachment 'upload_comments.py'
Download 1 #! /usr/bin/python
2 # -*- coding: utf-8 -*-
3 # bug_comment.py - <description>
4 # vim:ts=4:sw=4:et:ft=python:
5 # $Id:$
6 # $Source:$
7 # 2007-03-19
8
9 import sys, os, os.path, tempfile, getopt
10 from launchpadBugs.HTMLOperations import Bug
11
12 # Defaults
13 cookiefile="/home/hjmf/.mozilla/firefox/path/to/cookies.txt"
14
15 def submitReport(bugnumber, post_title, post_comment, attach_file=None, attachment_description=None):
16 file_contents = open(attach_file).read()
17 t=tempfile.TemporaryFile()
18 t.write(file_contents)
19 t.flush()
20 t.seek(0)
21
22 bug = Bug(bugnumber, cookie_file=cookiefile)
23 bug.add_comment(post_title, post_comment, attachment=t, description=attachment_description)
24
25 if __name__ == "__main__":
26 shortopts = "b:t:c:a:d:"
27 longopts = ["bugnumber", "title", "comment", "attach", "attachment_description"]
28
29 try:
30 opts, args = getopt.getopt(sys.argv[1:], shortopts, longopts)
31 except getopt.GetoptError:
32 print """Usage:
33 %s -b bugnumber -t "post title" -c "post comment" [ -a "file to attach" -d "attachment description" ]
34 %s --bugnumber bugnumber --titlle "post title" [ --attach "file" --attachment_description "attachment description" ]
35 """ % (sys.argv[0], sys.argv[0])
36 sys.exit(1)
37
38 for o, v in opts:
39 if o in ("-b", "--bugnumber"):
40 BUGNUMBER = v
41 elif o in ("-t", "--title"):
42 POSTTITLE = v
43 elif o in ("-c", "--comment"):
44 POSTCOMMENT = v
45 elif o in ("-a", "--attach"):
46 ATTACHMENT = v # handle errors (TODO)
47 elif o in ("-d", "--attachment_description"):
48 ATTACHMENTDESC = v
49
50 submitReport(BUGNUMBER, POSTTITLE, POSTCOMMENT, ATTACHMENT, ATTACHMENTDESC)
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.