Initial commit
Benjamin Renard authored 13 years ago
|
1) #!/usr/bin/python
2)
3) import suds
4) import logging
5) import re
6) import MantisMail
|
Mail & WS : Decode base64 a...
Benjamin Renard authored 12 years ago
|
7) import base64
|
Initial commit
Benjamin Renard authored 13 years ago
|
8)
9) class MantisWS(object):
10)
11) _options = {}
12) _options['default_category']='other'
13) _options['mail_from']='postmaster-mantis@example.net'
14) _options['smtp_host']='127.0.0.1'
15) _options['smtp_port']='25'
16)
17) def __init__(self,url,user,password):
18) self.url = url
19) self.user = user
20) self.password = password
21)
22) try:
23) self.client = suds.client.Client(url)
24) except:
25) logging.error('Error connecting to Mantis WS with URL %s' % url)
26)
27) def add_issue_to_project(self,reporter_email,project_infos,summary,description):
28) issue = self.client.factory.create('IssueData')
29) issue.reporter.email = reporter_email
30) issue.project.name = project_infos['project']
31) issue.project.id = 0 # Auto-detect
32)
33) if 'category' in project_infos:
34) issue.category = project_infos['category']
35) else:
36) issue.category = self._options['default_category']
37) issue.summary = summary
38) issue.description = description
39) try:
40) res = self.client.service.mc_issue_add(self.user,self.password,issue)
41) return res
|
MantisWS : Increase error l...
Benjamin Renard authored 12 years ago
|
42) except Exception, e:
43) logging.error('Problem adding issue : %s' % e)
|
Initial commit
Benjamin Renard authored 13 years ago
|
44) return None
45)
46) def add_note_to_issue(self,issue_id,text):
47) note = self.client.factory.create('IssueNoteData')
48) note.text=text
49)
50) try:
51) res = self.client.service.mc_issue_note_add(self.user,self.password,issue_id,note)
52) return res
|
MantisWS : improve error lo...
Benjamin Renard authored 12 years ago
|
53) except suds.WebFault, e:
54) logging.error('Problem adding note to issue %s : %s' % (issue_id,e))
55) err=str(e)
56) if re.search('Issue .* does not exist.',err):
57) logging.error('The issue %s does not exists' % issue_id)
58) raise MantisWSError('unknown_issue_note_add','The issue %s does not exists' % issue_id)
59) else:
60) raise MantisWSError('general_note_add','Problem adding note to issue %s : e' % (issue_id,e))
|
Initial commit
Benjamin Renard authored 13 years ago
|
61) return None
|
MantisWS : improve error lo...
Benjamin Renard authored 12 years ago
|
62) except Exception, e:
63) logging.error('Problem adding note to issue %s : %s' % (issue_id,e))
64) raise MantisWSError('general_note_add','Problem adding note to issue %s : e' % (issue_id,e))
65) return None
66)
|
Initial commit
Benjamin Renard authored 13 years ago
|
67) def add_attachment_to_issue(self,issue_id,attachment):
68) try:
69) res = self.client.service.mc_issue_attachment_add(
70) self.user,
71) self.password,
72) issue_id,
73) attachment['filename'],
74) attachment['type'],
|
Mail & WS : Decode base64 a...
Benjamin Renard authored 12 years ago
|
75) base64.b64encode(attachment['content'])
|