bt.py

Sun, 19 Apr 2015 22:46:39 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sun, 19 Apr 2015 22:46:39 +0300
changeset 130
c82cef747008
parent 124
7b2cd8b1ba86
child 138
d0184734320e
permissions
-rw-r--r--

- reverted previous commit (now that was a bad idea)

124
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
1 '''
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
2 Copyright 2014-2015 Teemu Piippo
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
3 All rights reserved.
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
4
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
5 Redistribution and use in source and binary forms, with or without
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
6 modification, are permitted provided that the following conditions
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
7 are met:
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
8
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
9 1. Redistributions of source code must retain the above copyright
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
10 notice, this list of conditions and the following disclaimer.
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
11 2. Redistributions in binary form must reproduce the above copyright
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
12 notice, this list of conditions and the following disclaimer in the
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
13 documentation and/or other materials provided with the distribution.
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
14 3. The name of the author may not be used to endorse or promote products
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
15 derived from this software without specific prior written permission.
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
16
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
17 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
18 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
19 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
20 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
21 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
22 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
23 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
24 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
26 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
27 '''
7b2cd8b1ba86 - now with extra license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 123
diff changeset
28
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 import suds
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
30 import sys
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
31 import time
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
32 import re
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
33 import irc as Irc
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
34 from configfile import Config
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 suds_active = False
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 btannounce_active = False
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 btannounce_timeout = 0
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 def is_active():
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 return suds_active
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
43 def get_ticket_data (bot, replyto, ticket, withlink):
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
44 if suds_active == False:
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
45 print "suds is not active"
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
46 return
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
47
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
48 data = {}
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
49 try:
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
50 data = get_issue (ticket)
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
51 except Exception, e:
78
afc0fc2a57e4 - prettier formatting for .ticket error
Teemu Piippo <crimsondusk64@gmail.com>
parents: 77
diff changeset
52 bot.privmsg (replyto, "Failed to get info for issue %s: %s" % (ticket, e))
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
53
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
54 if data:
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
55 if data['view_state']['name'] == 'private':
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
56 allowprivate = False
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
57
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
58 for channel in bot.channels:
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
59 if channel.get_value ('name') == replyto and channel.get_value ('btprivate', False):
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
60 allowprivate = True
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
61 break
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
62
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
63 if not allowprivate:
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
64 bot.privmsg (replyto, 'Error: ticket %s is private' % ticket)
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
65 return
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
66
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
67 bot.privmsg (replyto, "Issue %s: %s: Reporter: %s, assigned to: %s, status: %s (%s)" % \
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
68 (ticket, \
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
69 data.summary, \
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
70 data.reporter.name if hasattr (data.reporter, 'name') else "<unknown>", \
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
71 data.handler.name if hasattr (data, 'handler') else "nobody", \
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
72 data.status.name, \
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
73 data.resolution.name))
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
74
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
75 if withlink:
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
76 bot.privmsg (replyto, "Read all about it here: " + get_ticket_url (ticket))
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
77
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
78 def process_message (bot, line, replyto):
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
79 # Check for tracker url in the message
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
80 url = Config.get_node ('bt').get_value ('url')
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
81 http_regex = re.compile (r'.*http(s?)://%s/view\.php\?id=([0-9]+).*' % url)
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
82 http_match = http_regex.match (line)
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
83
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
84 if http_match:
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
85 get_ticket_data (bot, replyto, http_match.group (2), False)
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
86
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 def init():
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
88 global suds_active
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
89 global suds_client
77
8f45af91a4f3 - added missing global statement
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
90 global btannounce_id
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
91
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 try:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 print 'Initializing MantisBT connection...'
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 suds_import = suds.xsd.doctor.Import ('http://schemas.xmlsoap.org/soap/encoding/', 'http://schemas.xmlsoap.org/soap/encoding/')
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 suds_client = suds.client.Client ('https://zandronum.com/tracker/api/soap/mantisconnect.php?wsdl', plugins=[suds.xsd.doctor.ImportDoctor (suds_import)])
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 suds_active = True
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 except Exception as e:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 print 'Failed to establish MantisBT connection: ' + `e`
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 pass
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 if suds_active:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 sys.stdout.write ('Retrieving latest tracker ticket... ')
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
103 user, password = credentials()
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 btannounce_id = suds_client.service.mc_issue_get_biggest_id (user, password, 0)
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 btannounce_active = True
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
106 update_checktimeout()
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 print btannounce_id
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 def update_checktimeout():
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110 global btannounce_timeout
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 btannounce_timeout = time.time() + (Config.get_node ('bt').get_value ('checkinterval', default=5) * 60)
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113 def credentials():
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114 bt = Config.get_node ('bt')
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115 user = bt.get_value ('username', '')
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116 password = bt.get_value ('password', '')
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117 return [user, password]
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
119 def get_issue (ticket):
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120 global suds_client
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
121 user, password = credentials()
115
2bb5c4578ee1 - more fixes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 84
diff changeset
122 print "get_issue: Retrieving issue data for %s" % ticket
2bb5c4578ee1 - more fixes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 84
diff changeset
123 result = suds_client.service.mc_issue_get (user, password, ticket)
2bb5c4578ee1 - more fixes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 84
diff changeset
124 print "Issue data recieved."
2bb5c4578ee1 - more fixes
Teemu Piippo <crimsondusk64@gmail.com>
parents: 84
diff changeset
125 return result
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
127 def poll():
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
128 global btannounce_timeout
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129 global btannounce_id
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130
123
aeb0d0788869 - added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents: 115
diff changeset
131 if not suds_active:
aeb0d0788869 - added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents: 115
diff changeset
132 return
aeb0d0788869 - added commits.db and mercurial support restructure
Teemu Piippo <crimsondusk64@gmail.com>
parents: 115
diff changeset
133
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
134 if time.time() >= btannounce_timeout:
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
135 update_checktimeout()
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
136 newid = btannounce_id
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
137 try:
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
138 user, password = credentials()
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139 newid = suds_client.service.mc_issue_get_biggest_id (user, password, 0)
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
140 except Exception as e:
83
3dab1fd47d51 - slight rework on bt poll
Teemu Piippo <crimsondusk64@gmail.com>
parents: 78
diff changeset
141 Irc.broadcast ("Error while polling: %s" % e)
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
142 pass
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
143
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
144 while newid > btannounce_id:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
145 try:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
146 btannounce_id += 1
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
147 data = get_issue (btannounce_id)
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
148
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
149 for client in Irc.all_clients:
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
150 announce_new_issue (client, data)
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
151 except Exception as e:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
152 pass
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
153
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
154 def get_ticket_url (ticket):
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
155 url = Config.get_node ('bt').get_value ('url')
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
156 return 'https://%s/view.php?id=%s' % (url, ticket)
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
157
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
158 #
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
159 # Print a ticket announce to appropriate channels
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
160 #
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
161 def announce_new_issue (bot, data):
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
162 idstring = "%d" % data.id
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
163 while len(idstring) < 7:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
164 idstring = "0" + idstring
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
165
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
166 isprivate = data['view_state']['name'] == 'private'
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
167 reporter = data['reporter']['name'] if hasattr (data['reporter'], 'name') else '<nobody>'
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
168
84
247f4a927835 - work on fixing bt poll
Teemu Piippo <crimsondusk64@gmail.com>
parents: 83
diff changeset
169 for channel in bot.channels:
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
170 if channel.get_value ('btannounce', False):
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
171 if not isprivate or (channel.get_value ('btprivate', False)):
84
247f4a927835 - work on fixing bt poll
Teemu Piippo <crimsondusk64@gmail.com>
parents: 83
diff changeset
172 bot.write ("PRIVMSG %s :[%s] New issue %s, reported by %s: %s: %s" % \
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
173 (channel.get_value ('name'),
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
174 data['project']['name'],
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
175 idstring,
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
176 reporter,
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
177 data['summary'],
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
178 get_ticket_url (idstring)))
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
179
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
180 def update_issue (ticket_id, ticket_data):
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
181 btuser, btpassword = credentials()
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
182 suds_client.service.mc_issue_update (btuser, btpassword, ticket_id, ticket_data)
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
183
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
184 def post_note (ticket_id, message):
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
185 btuser, btpassword = credentials()
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
186 suds_client.service.mc_issue_note_add (btuser, btpassword, ticket_id, { 'text': message })

mercurial