mod_hgpoll.py

changeset 113
08e9b1c1b324
parent 112
cdafc1a0544e
equal deleted inserted replaced
112:cdafc1a0544e 113:08e9b1c1b324
2 from datetime import datetime 2 from datetime import datetime
3 import hgpoll as HgPoll 3 import hgpoll as HgPoll
4 import re 4 import re
5 import bt as Bt 5 import bt as Bt
6 from configfile import Config 6 from configfile import Config
7 from modulecore import command_error
7 8
8 ModuleData = { 9 ModuleData = {
9 'commands': 10 'commands':
10 [ 11 [
11 { 12 {
39 return '' if a == 1 else 's' 40 return '' if a == 1 else 's'
40 41
41 def cmd_checkhg (bot, **rest): 42 def cmd_checkhg (bot, **rest):
42 HgPoll.force_poll() 43 HgPoll.force_poll()
43 44
44 def cmd_cset (bot, args, replyto, **rest): 45 def cmd_cset (bot, args, reply, **rest):
45 repo = Repo ('zandronum-everything') 46 repo = Repo ('zandronum-everything')
46 data = "" 47 data = ""
47 node = args['key'] 48 node = args['key']
48 49
49 # Possibly we're passed a date version instead. Try find the node for this. 50 # Possibly we're passed a date version instead. Try find the node for this.
56 data = line.replace ('\n', '').split (' ') 57 data = line.replace ('\n', '').split (' ')
57 if data[1] == args['key']: 58 if data[1] == args['key']:
58 node = data[0] 59 node = data[0]
59 break 60 break
60 else: 61 else:
61 bot.privmsg (replyto, 'couldn\'t find changset for date %s' % args['key']) 62 command_error ('couldn\'t find changeset for date %s' % args['key'])
62 return 63 return
63 except ValueError: 64 except ValueError:
64 pass 65 pass
65 66
66 # The sandboxes contain all revisions in zandronum and zandronum-stable. 67 # zandronum-everything contains all zandronum changesets, so look for changesets in that.
67 # Thus we only need to try find the revision in the sandbox repos.
68 try: 68 try:
69 data = repo.hg_command ("log", "-l1", "-r", node, "--template", 69 data = repo.hg_command ("log", "-l1", "-r", node, "--template",
70 "{node|short}@@@@@@@" + 70 "{node|short}@@@@@@@" +
71 "{desc}@@@@@@@" + 71 "{desc}@@@@@@@" +
72 "{author}@@@@@@@" + 72 "{author}@@@@@@@" +
74 "{date|hgdate}@@@@@@@" + 74 "{date|hgdate}@@@@@@@" +
75 "{bookmarks}@@@@@@@" + 75 "{bookmarks}@@@@@@@" +
76 "{latesttagdistance}@@@@@@@" + 76 "{latesttagdistance}@@@@@@@" +
77 "{latesttag}") 77 "{latesttag}")
78 except hgapi.HgException: 78 except hgapi.HgException:
79 bot.privmsg (replyto, 'couldn\'t find changeset %s' % (node)) 79 command_error ('couldn\'t find changeset %s' % (node))
80 return 80 return
81 81
82 try: 82 try:
83 data = data.split ('@@@@@@@') 83 data = data.split ('@@@@@@@')
84 node = data[0] 84 node = data[0]
85 message = data[1] 85 message = data[1]
86 author = data[2] 86 author = data[2]
87 diffstat = data[3] 87 diffstat = data[3]
88 date = datetime.utcfromtimestamp (int (data[4].split (' ')[0])) 88 date = datetime.utcfromtimestamp (int (data[4].split (' ')[0]))
89 bookmarks = data[5] 89 bookmarks = data[5]
90 latesttagdistance = int( data[6] ) 90 latesttagdistance = int (data[6])
91 latesttag = data[7] 91 latesttag = data[7]
92 delta = datetime.utcnow() - date 92 delta = datetime.utcnow() - date
93 datestring = '' 93 datestring = ''
94 94
95 if bookmarks: 95 if bookmarks:
155 if latesttagdistance != 0: 155 if latesttagdistance != 0:
156 versionstring = '%s %s, %d hops from %s' % (zanversion, date.strftime ('%y%m%d-%H%M'), latesttagdistance, latesttag) 156 versionstring = '%s %s, %d hops from %s' % (zanversion, date.strftime ('%y%m%d-%H%M'), latesttagdistance, latesttag)
157 else: 157 else:
158 versionstring = latesttag 158 versionstring = latesttag
159 159
160 bot.privmsg (replyto, 'changeset\0035 %s%s\003 (%s)\003: committed by\0032 %s\003 %s,\0032 %s' % \ 160 reply ('changeset\0035 %s%s\003 (%s)\003: committed by\0032 %s\003 %s,\0032 %s' % \
161 (node, bookmarks, versionstring, author, datestring, diffstat)) 161 (node, bookmarks, versionstring, author, datestring, diffstat))
162 162
163 for line in message.split ('\n'): 163 for line in message.split ('\n'):
164 bot.privmsg (replyto, ' ' + line) 164 reply (' ' + line)
165 except hgapi.HgException as e: 165 except hgapi.HgException as e:
166 result = HgPoll.decipher_hgapi_error (e) 166 result = HgPoll.decipher_hgapi_error (e)
167 167
168 if result[0]: 168 if result[0]:
169 bot.privmsg (replyto, 'error: %s' % result[1]) 169 command_error (result[1])
170 else: 170 else:
171 bot.privmsg (replyto, 'error: %s' % `e`) 171 command_error (`e`)
172 172
173 def cmd_hg (bot, args, **rest): 173 def cmd_hg (bot, args, **rest):
174 try: 174 try:
175 repo = hgapi.Repo (args['repo']) 175 repo = hgapi.Repo (args['repo'])
176 result = repo.hg_command (*args['command']) 176 result = repo.hg_command (*args['command'])
177 self.privmsg (replyto, result) 177 reply (replyto, result)
178 except hgapi.hgapi.HgException as e: 178 except hgapi.hgapi.HgException as e:
179 result = HgPoll.decipher_hgapi_error (e) 179 result = HgPoll.decipher_hgapi_error (e)
180 180
181 if result[0]: 181 if result[0]:
182 self.privmsg (replyto, 'error: %s' % result[1]) 182 command_error (result[1])
183 else: 183 else:
184 self.privmsg (replyto, 'error: %s' % `e`) 184 command_error (`e`)
185 185
186 def cmd_resolves (bot, args, replyto, **rest): 186 def cmd_resolves (bot, args, replyto, **rest):
187 try: 187 try:
188 HgPoll.announce_ticket_resolved (args['ticket'], args['changeset']) 188 HgPoll.announce_ticket_resolved (args['ticket'], args['changeset'])
189 except Exception as e: 189 except Exception as e:
190 bot.privmsg (replyto, 'Error: %s' % e) 190 command_error (str (e))

mercurial