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
|
import os
from log_picker.sending.senderbaseclass import SenderBaseClass
from log_picker.sending.senderbaseclass import SenderError
from report.plugins.bugzilla import filer
from report.plugins.bugzilla.filer import CommunicationError
from report.plugins.bugzilla.filer import LoginError
class BugzillaBaseClass(SenderBaseClass):
_bz_address = ""
_bz_xmlrpc = ""
_description = ""
def __init__(self, *args, **kwargs):
SenderBaseClass.__init__(self, args, kwargs)
self.bzfiler = None
self.bug_id = None
self.comment = None
def connect_and_login(self, username, password):
try:
self.bzfiler = filer.BugzillaFiler(self._bz_xmlrpc, self._bz_address,
filer.getVersion(), filer.getProduct())
self.bzfiler.login(username, password)
except (CommunicationError, LoginError) as e:
raise SenderError("%s. Bad username or password?" % e)
except (ValueError) as e:
raise SenderError("%s" % e)
def set_bug(self, bug_id):
self.bug_id = bug_id
def set_comment(self, comment):
self.comment = comment
def sendfile(self, filename, contenttype):
description = self._get_description(self._description)
dict_args = {'isprivate': False,
'filename': os.path.basename(filename),
'contenttype': contenttype}
if self.comment:
dict_args['comment'] = self.comment
try:
bug = self.bzfiler.getbug(self.bug_id)
bug.attachfile(filename, description, **dict_args)
except (CommunicationError, ValueError) as e:
raise SenderError(e)
class RedHatBugzilla(BugzillaBaseClass):
_bz_address = "http://bugzilla.redhat.com"
_bz_xmlrpc = "https://bugzilla.redhat.com/xmlrpc.cgi"
_description = "LogPicker"
def __init__(self, *args, **kwargs):
BugzillaBaseClass.__init__(self, args, kwargs)
|