/
BugzInterface.py
90 lines (77 loc) · 2.68 KB
/
BugzInterface.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
'''
create a new bug and upload an attachment to http://bugs.gentoo.org.
'''
import urllib
import types
import string
import sys
import os
try:
import ClientForm
from ClientForm import ControlNotFoundError, ItemNotFoundError, \
ItemCountError, ParseError, ParseResponse
import ClientCookie
except:
print __doc__
sys.exit(1)
from urllib2 import urlopen
from cStringIO import StringIO
import options
class HandleForm:
'''Parses bugs.gentoo.org forms, handles cookies and uploads attachments'''
def __init__(self, filename, summary, desc, uri, password, user):
self.filename = filename
self.ebuild = os.path.basename(filename)
self.summary = summary
self.desc = desc
self.uri = uri
self.password = password
self.bugNbr = 0
self.user = user
def Login(self):
url = "http://bugs.gentoo.org/enter_bug.cgi?product=Gentoo%20Linux"
forms = ParseResponse(ClientCookie.urlopen(url))
form = forms[0]
print forms[0]
try:
form["Bugzilla_login"] = self.user
form["Bugzilla_password"] = self.password
response = ClientCookie.urlopen(form.click("GoAheadAndLogIn"))
except:
#Already logged in with coookies
pass
def EnterNewBug(self):
url = "http://bugs.gentoo.org/enter_bug.cgi?product=Gentoo%20Linux"
forms = ParseResponse(ClientCookie.urlopen(url))
form = forms[0]
form["component"] = ["Ebuilds"]
form["bug_severity"] = ["enhancement"]
form["bug_file_loc"] = self.uri
form["short_desc"] = self.summary
form["comment"] = self.desc
request = form.click()
response2 = ClientCookie.urlopen(request)
lines = response2.read()
#print response2.info() web server header info
for l in lines:
if l.find("Submitted") != -1:
self.bugNbr = l.split()[1]
print "Bug number %s created." % self.bugNbr
break
def UploadAttachment(self):
import cgi
url = "http://bugs.gentoo.org/attachment.cgi?bugid=%s&action=enter" % self.bugNbr
forms = ParseResponse(ClientCookie.urlopen(url))
form = forms[0]
print form
form["description"] = self.ebuild
form["contenttypemethod"] = ["list"]
form["contenttypeselection"] = ["text/plain"]
form["comment"] = ""
f = file(self.filename)
form.add_file(f, "text/plain", self.ebuild)
request = form.click()
response2 = ClientCookie.urlopen(request)
print "Attachment uploaded."
print response2.read()
print response2.info()