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