bt.py

changeset 72
2266d6d73de3
child 73
d67cc4fbc3f1
equal deleted inserted replaced
67:f8cc57c608e2 72:2266d6d73de3
1 import suds
2 import cobalt
3
4 suds_active = False
5 btannounce_active = False
6 btannounce_timeout = 0
7
8 def is_active():
9 return suds_active
10
11 def init():
12 try:
13 print 'Initializing MantisBT connection...'
14 suds_import = suds.xsd.doctor.Import ('http://schemas.xmlsoap.org/soap/encoding/', 'http://schemas.xmlsoap.org/soap/encoding/')
15 suds_client = suds.client.Client ('https://zandronum.com/tracker/api/soap/mantisconnect.php?wsdl', plugins=[suds.xsd.doctor.ImportDoctor (suds_import)])
16 suds_active = True
17 except Exception as e:
18 print 'Failed to establish MantisBT connection: ' + `e`
19 pass
20
21 if suds_active:
22 sys.stdout.write ('Retrieving latest tracker ticket... ')
23 user, password = bt_credentials()
24 btannounce_id = suds_client.service.mc_issue_get_biggest_id (user, password, 0)
25 btannounce_active = True
26 bt_updatechecktimeout()
27 print btannounce_id
28
29 def update_checktimeout():
30 global btannounce_timeout
31 btannounce_timeout = time.time() + (Config.get_node ('bt').get_value ('checkinterval', default=5) * 60)
32
33 def credentials():
34 bt = Config.get_node ('bt')
35 user = bt.get_value ('username', '')
36 password = bt.get_value ('password', '')
37 return [user, password]
38
39 def get_issue(ticket):
40 global suds_client
41 user, password = bt_credentials()
42 return suds_client.service.mc_issue_get (user, password, ticket)
43
44 def poll():
45 global btannounce_timeout
46 global btannounce_id
47
48 if time.time() >= btannounce_timeout:
49 bt_updatechecktimeout()
50 newid = btannounce_id
51 try:
52 user, password = bt_credentials()
53 newid = suds_client.service.mc_issue_get_biggest_id (user, password, 0)
54 except Exception as e:
55 pass
56
57 while newid > btannounce_id:
58 try:
59 btannounce_id += 1
60 data = bt_getissue (btannounce_id)
61
62 for client in cobalt.all_clients:
63 announce_new_ticket (client, data)
64 except Exception as e:
65 pass
66
67 def get_ticket_url (ticket):
68 url = Config.get_node ('bt').get_value ('url')
69 return 'https://%s/view.php?id=%s' % (url, ticket)
70
71
72 #
73 # Print a ticket announce to appropriate channels
74 #
75 def announce_new_issue (bot, data):
76 idstring = "%d" % data.id
77 while len(idstring) < 7:
78 idstring = "0" + idstring
79
80 isprivate = data['view_state']['name'] == 'private'
81 reporter = data['reporter']['name'] if hasattr (data['reporter'], 'name') else '<nobody>'
82
83 for channel in self.channels:
84 if channel.get_value ('btannounce', False):
85 if not isprivate or (channel.get_value ('btprivate', False)):
86 self.write ("PRIVMSG %s :[%s] New issue %s, reported by %s: %s: %s" % \
87 (channel['name'], data['project']['name'], idstring, reporter,
88 data['summary'], self.get_ticket_url (idstring)))
89 #fi
90 #fi
91 #done

mercurial