da78a575abf00dcecccd80fd29fe28eb3f8854ed
Benjamin Renard Initial commit

Benjamin Renard authored 12 years ago

1) #!/usr/bin/python
2) 
3) import suds
4) import logging
5) import re
6) import MantisMail
Benjamin Renard Mail & WS : Decode base64 a...

Benjamin Renard authored 12 years ago

7) import base64
Benjamin Renard Initial commit

Benjamin Renard authored 12 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
Benjamin Renard MantisWS : Increase error l...

Benjamin Renard authored 12 years ago

42) 		except Exception, e:
43) 			logging.error('Problem adding issue : %s' % e)
Benjamin Renard Initial commit

Benjamin Renard authored 12 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
53) 		except:
54) 			logging.error('Problem adding note to issue %s' % issue_id)
55) 			return None
56) 	def add_attachment_to_issue(self,issue_id,attachment):
57) 		try:
58) 			res = self.client.service.mc_issue_attachment_add(
59) 				self.user,
60) 				self.password,
61) 				issue_id,
62) 				attachment['filename'],
63) 				attachment['type'],
Benjamin Renard Mail & WS : Decode base64 a...

Benjamin Renard authored 12 years ago

64) 				base64.b64encode(attachment['content'])