mod_hgpoll.py

Mon, 10 Nov 2014 02:10:49 +0200

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Mon, 10 Nov 2014 02:10:49 +0200
changeset 74
9f14fb6995ff
parent 73
d67cc4fbc3f1
child 75
1818d56c8ff5
permissions
-rw-r--r--

- added a missing import..

72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 from hgapi import hgapi, Repo
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
2 from datetime import datetime
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 import hgpoll as HgPoll
74
9f14fb6995ff - added a missing import..
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
4 import re
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 ModuleData = {
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 'commands':
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 [
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 {
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 'name': 'checkhg',
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 'description': 'Polls the zandronum repositories for updates',
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 'args': None,
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 'level': 'admin',
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 },
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 {
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 'name': 'cset',
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 'description': 'Yields changeset information (use a hash or date as key)',
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18 'args': '<key>',
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 'level': 'normal',
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 },
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 {
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 'name': 'hg',
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 'description': 'Executes a hg command',
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 'args': '<repo> <command...>',
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 'level': 'admin',
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 }
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 ]
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 }
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 def cmd_checkhg (bot, **rest):
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 HgPoll.force_poll()
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32
73
d67cc4fbc3f1 - modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 72
diff changeset
33 def cmd_cset (bot, args, **rest):
72
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 repo = Repo ('zandronum-everything')
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 data = ""
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 node = args['key']
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 # Possibly we're passed a date version instead. Try find the node for this.
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 try:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 datetime.strptime (args['key'], '%y%m%d-%H%M')
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 make_commits_txt()
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 commits_txt = open ('commits.txt', 'r')
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 for line in commits_txt:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 data = line.replace ('\n', '').split (' ')
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 if data[1] == args['key']:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 node = data[0]
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 break
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 else:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 bot.privmsg (replyto, 'couldn\'t find changset for date %s' % args['key'])
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 return
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 #done
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 except ValueError:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 pass
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 #tried
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 # The sandboxes contain all revisions in zandronum and zandronum-stable.
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 # Thus we only need to try find the revision in the sandbox repos.
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 try:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 repo.hg_command ("log", "-r", node, "--template", " ")
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 except hgapi.HgException:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 bot.privmsg (replyto, 'couldn\'t find changeset %s' % (node))
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 return
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64 #tried
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 try:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 data = repo.hg_command ("log", "-r", node, "--template",
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 "{node|short}@@@@@@@{desc}@@@@@@@{author}@@@@@@@{diffstat}@@@@@@@{date|hgdate}")
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 data = data.split ('@@@@@@@')
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 node = data[0]
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 message = data[1]
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73 author = data[2]
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 diffstat = data[3]
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 date = datetime.utcfromtimestamp (int (data[4].split (' ')[0]))
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 delta = datetime.now() - date
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
77 datestring = ''
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 # Remove the email address from the author if possible
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 match = re.compile (r'^(.+) <([^>]+)>$.*').match (author)
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 if match:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 author = match.group (1)
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 email = match.group (2)
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 username = find_developer_by_email (email)
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 if username != '':
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 author = username
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 if delta.days < 4:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91 if delta.days == 0:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 if delta.seconds < 60:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 datestring = 'just now'
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 elif delta.seconds < 3600:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 minutes = delta.seconds / 60
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 datestring = '%d minute%s ago' % (minutes, plural (minutes))
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 else:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 hours = delta.seconds / 3600
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 datestring = '%d hour%s ago' % (hours, plural (hours))
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 else:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 datestring = '%d day%s ago' % (delta.days, plural (delta.days))
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 else:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103 datestring = 'on %s' % (str (date))
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 #fi
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106 bot.privmsg (replyto, 'changeset %s (%s): committed by %s %s (%s)' % \
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 (node, date.strftime ('%y%m%d-%H%M'), author, datestring, diffstat))
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 for line in message.split ('\n'):
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110 bot.privmsg (replyto, ' ' + line)
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 except hgapi.HgException as e:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112 result = HgPoll.decipher_hgapi_error (e)
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114 if result[0]:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115 bot.privmsg (replyto, 'error: %s' % result[1])
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116 else:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117 bot.privmsg (replyto, 'error: %s' % `e`)
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118 #tried
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120 def cmd_hg (bot, args, **rest):
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121 try:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122 repo = hgapi.Repo (args['repo'])
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123 result = repo.hg_command (*args['command'])
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124 self.privmsg (replyto, result)
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125 except hgapi.hgapi.HgException as e:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126 result = HgPoll.decipher_hgapi_error (e)
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
127
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
128 if result[0]:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
129 self.privmsg (replyto, 'error: %s' % result[1])
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
130 else:
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131 self.privmsg (replyto, 'error: %s' % `e`)
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132 #fi
2266d6d73de3 - commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
133 #tried

mercurial