hgpoll.py

changeset 120
9880bb697149
parent 115
2bb5c4578ee1
child 121
ac07779f788d
equal deleted inserted replaced
119:0f96e3157b7f 120:9880bb697149
4 import bt as Bt 4 import bt as Bt
5 import irc as Irc 5 import irc as Irc
6 import os 6 import os
7 from datetime import datetime 7 from datetime import datetime
8 from configfile import Config 8 from configfile import Config
9 import utility
9 g_needCommitsTxtRebuild = True 10 g_needCommitsTxtRebuild = True
10 11
11 def color_for_repo (repo_name): 12 def color_for_repo (repo_name):
13 repo_name = repo_name.lower()
14
12 if repo_name == 'zandronum': 15 if repo_name == 'zandronum':
13 color = 4 16 color = 4
14 elif repo_name == 'zandronum-stable': 17 elif repo_name == 'zandronum-stable':
15 color = 2 18 color = 2
16 elif repo_name == 'zandronum-sandbox': 19 elif repo_name == 'zandronum-sandbox':
17 color = 7 20 color = 7
18 elif repo_name == 'zandronum-sandbox-stable': 21 elif repo_name == 'zandronum-sandbox-stable':
19 color = 3 22 color = 3
20 elif repo_name == 'zfc9000': 23 elif repo_name == 'zfc9000':
21 color = 6 24 color = 6
25 elif repo_name == 'doomseeker':
26 color = 5
22 else: 27 else:
23 color = 0 28 color = 0
24 return color 29 return color
25 30
26 def prettify_bookmarks (bookmarks): 31 def prettify_bookmarks (bookmarks):
205 check_repo_exists ('zandronum-stable', 'Torr_Samaho') 210 check_repo_exists ('zandronum-stable', 'Torr_Samaho')
206 check_repo_exists ('zandronum-sandbox', 'crimsondusk') 211 check_repo_exists ('zandronum-sandbox', 'crimsondusk')
207 check_repo_exists ('zandronum-sandbox-stable', 'crimsondusk') 212 check_repo_exists ('zandronum-sandbox-stable', 'crimsondusk')
208 check_repo_exists ('zandronum-everything', '') 213 check_repo_exists ('zandronum-everything', '')
209 check_repo_exists ('zfc9000', 'crimsondusk') 214 check_repo_exists ('zfc9000', 'crimsondusk')
215 check_repo_exists ('doomseeker', 'Blzut3')
210 global repocheck_timeout 216 global repocheck_timeout
211 repocheck_timeout = (time.time()) + 15 217 repocheck_timeout = (time.time()) + 15
212 218
213 def get_commit_data (zanrepo, rev, template): 219 def get_commit_data (zanrepo, rev, template):
214 return zanrepo.hg_command ('log', '-l', '1', '-r', rev, '--template', template) 220 return zanrepo.hg_command ('log', '-l', '1', '-r', rev, '--template', template)
243 def poll(): 249 def poll():
244 global repocheck_timeout 250 global repocheck_timeout
245 if time.time() < repocheck_timeout: 251 if time.time() < repocheck_timeout:
246 return 252 return
247 253
248 for n in ['zandronum-stable', 'zandronum', 'zandronum-sandbox', 'zandronum-sandbox-stable', 'zfc9000']: 254 for n in ['zandronum-stable', 'zandronum', 'zandronum-sandbox', 'zandronum-sandbox-stable', 'zfc9000', 'doomseeker']:
249 poll_one_repo (n) 255 poll_one_repo (n)
250 256
251 hgns = Config.get_node ('hg') 257 hgns = Config.get_node ('hg')
252 repocheck_timeout = time.time() + hgns.get_value ('checkinterval', default=15) * 60 258 repocheck_timeout = time.time() + hgns.get_value ('checkinterval', default=15) * 60
259
260 def get_repo_owner (repo_name):
261 usesandbox = repo_name == 'zandronum-sandbox' or repo_name == 'zandronum-sandbox-stable'
262 repo_name = repo_name.lower()
263 if repo_name[:9] == 'zandronum':
264 repo_owner = 'Torr_Samaho' if (not usesandbox) else 'crimsondusk'
265 elif repo_name == 'zfc9000':
266 repo_owner = 'crimsondusk'
267 elif repo_name == 'doomseeker':
268 repo_owner = 'Blzut3'
269 return repo_owner
253 270
254 def poll_one_repo (repo_name): 271 def poll_one_repo (repo_name):
255 global repocheck_timeout 272 global repocheck_timeout
256 hgns = Config.get_node ('hg') 273 hgns = Config.get_node ('hg')
257 274
258 if not hgns.get_value ('track', default=True): 275 if not hgns.get_value ('track', default=True):
259 return 276 return
260 277
261 usesandbox = repo_name == 'zandronum-sandbox' or repo_name == 'zandronum-sandbox-stable' 278 usesandbox = repo_name == 'zandronum-sandbox' or repo_name == 'zandronum-sandbox-stable'
262 repo_owner = 'Torr_Samaho' if (not usesandbox and repo_name != 'zfc9000') else 'crimsondusk' 279 repo_owner = get_repo_owner (repo_name)
263 zanrepo = hgapi.Repo (repo_name) 280 zanrepo = hgapi.Repo (repo_name)
264 commit_data = [] 281 commit_data = []
265 delimeter = '@@@@@@@@@@' 282 delimeter = '@@@@@@@@@@'
266 # print 'Checking %s for updates' % repo_name 283 # print 'Checking %s for updates' % repo_name
267 284
299 316
300 def process_new_commits (repo_name, commit_data): 317 def process_new_commits (repo_name, commit_data):
301 if len (commit_data) == 0: 318 if len (commit_data) == 0:
302 return 319 return
303 320
321 repo_name = repo_name.lower()
304 usestable = repo_name == 'zandronum-stable' 322 usestable = repo_name == 'zandronum-stable'
305 usesandbox = repo_name == 'zandronum-sandbox' or repo_name == 'zandronum-sandbox-stable' 323 usesandbox = repo_name == 'zandronum-sandbox' or repo_name == 'zandronum-sandbox-stable'
306 repo_owner = 'Torr_Samaho' if (not usesandbox and repo_name != 'zfc9000') else 'crimsondusk' 324 repo_owner = get_repo_owner (repo_name)
307 repo_url = 'https://bitbucket.org/%s/%s' % (repo_owner, repo_name) 325 repo_url = 'https://bitbucket.org/%s/%s' % (repo_owner, repo_name)
308 num_commits = 0 326 num_commits = 0
309 zanrepo = hgapi.Repo (repo_name) 327 zanrepo = hgapi.Repo (repo_name)
310 print '%d new commits on %s' % (len (commit_data), repo_name) 328 print '%d new commits on %s' % (len (commit_data), repo_name)
311 329
380 398
381 if (not usesandbox and repo_name != 'zfc9000') or channel.get_value ('btprivate', False): 399 if (not usesandbox and repo_name != 'zfc9000') or channel.get_value ('btprivate', False):
382 irc_client.privmsg (channel.get_value ('name'), 400 irc_client.privmsg (channel.get_value ('name'),
383 "\003%d%s\003: new commit\0035 %s%s\003 by\0032 %s\003: %s" 401 "\003%d%s\003: new commit\0035 %s%s\003 by\0032 %s\003: %s"
384 % (color_for_repo (repo_name), repo_name, commit_node, commit_bookmarks, 402 % (color_for_repo (repo_name), repo_name, commit_node, commit_bookmarks,
385 committer, commit_url)) 403 committer, utility.shorten_link (commit_url)))
386 404
387 for line in commit_message.split ('\n'): 405 for line in commit_message.split ('\n'):
388 irc_client.privmsg (channel.get_value ('name'), line) 406 irc_client.privmsg (channel.get_value ('name'), line)
389 407
390 if not usesandbox: 408 if not usesandbox:

mercurial