Sun, 30 Nov 2014 03:55:47 +0200
- add more decimals to the mathematical constants
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
1 | import hgapi |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
2 | import time |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
3 | import re |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
4 | import bt as Bt |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
5 | import irc as Irc |
86
6337540fb44b
- fixed missing import os
Teemu Piippo <crimsondusk64@gmail.com>
parents:
85
diff
changeset
|
6 | import os |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
7 | from datetime import datetime |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | from configfile import Config |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | g_needCommitsTxtRebuild = True |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | def make_commits_txt(): |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | global g_needCommitsTxtRebuild |
87 | 13 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | if g_needCommitsTxtRebuild == False: |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | return |
87 | 16 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | print 'Building commits.txt...' |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | # Update zandronum-everything |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | repo = hgapi.Repo ('zandronum-everything') |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | repo.hg_command ('pull', '../zandronum-sandbox') |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | repo.hg_command ('pull', '../zandronum-sandbox-stable') |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | data = repo.hg_command ('log', '--template', '{node} {date|hgdate}\n') |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | f = open ('commits.txt', 'w') |
87 | 24 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | for line in data.split ('\n'): |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | if line == '': |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | continue |
87 | 28 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | words = line.split (' ') |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | timestamp = int (words[1]) |
87 | 31 | f.write ('%s %s\n' % (words[0], datetime.utcfromtimestamp (timestamp).strftime |
32 | ('%y%m%d-%H%M'))) | |
33 | ||
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | f.close() |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | g_needCommitsTxtRebuild = False |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | ' Check if a repository exists ' |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | def check_repo_exists (repo_name, repo_owner): |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | print 'Checking that %s exists...' % repo_name |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | repo_url = 'https://bitbucket.org/%s/%s' % (repo_owner, repo_name) |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | zanrepo = hgapi.Repo (repo_name) |
87 | 42 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | try: |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | zanrepo.hg_command ('id', '.') |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | except hgapi.hgapi.HgException: |
87 | 46 | # If the repo does not exist, clone it. zandronum-everything can be spawned |
47 | # off other repos though | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | if repo_name == 'zandronum-everything': |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | if not os.path.exists (repo_name): |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | os.makedirs (repo_name) |
87 | 51 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | global g_needCommitsTxtRebuild |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | g_needCommitsTxtRebuild = True |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | print 'Init %s' % repo_name |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | zanrepo.hg_command ('init') |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | print 'Cloning zandronum-sandbox into %s' % repo_name |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | zanrepo.hg_command ('pull', '../zandronum-sandbox') |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | print 'Cloning zandronum-sandbox-stable into %s' % repo_name |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | zanrepo.hg_command ('pull', '../zandronum-sandbox-stable') |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | print 'Done' |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | make_commits_txt() |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | return |
87 | 63 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | try: |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | print 'Cloning %s...' % repo_name |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | zanrepo.hg_clone (repo_url, repo_name) |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | print 'Cloning done.' |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | except Exception as e: |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | print 'Unable to clone %s from %s: %s' % (repo_name, repo_url, str (`e`)) |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
70 | quit (1) |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | |
88 | 72 | |
73 | class HgProcessError (Exception): | |
74 | def __init__ (self, value): | |
75 | self.message = value | |
76 | def __str__ (self): | |
77 | return self.message | |
78 | ||
87 | 79 | def announce_ticket_resolved (ticket_id, commit_node): |
91 | 80 | ticket_id = int (ticket_id) |
81 | ||
89 | 82 | try: |
83 | repo_name = 'zandronum-stable' | |
84 | zanrepo = hgapi.Repo (repo_name) | |
85 | zanrepo.hg_command ('log', '-r', commit_node) | |
86 | except hgapi.hgapi.HgException: | |
87 | try: | |
88 | repo_name = 'zandronum' | |
89 | zanrepo = hgapi.Repo (repo_name) | |
90 | zanrepo.hg_command ('log', '-r', commit_node) | |
91 | except hgapi.hgapi.HgException: | |
92 | raise HgProcessError ('unknown commit %s' % commit_node) | |
93 | ||
94 | repo_url = 'https://bitbucket.org/Torr_Samaho/%s' % repo_name | |
87 | 95 | |
96 | # Acquire additional data | |
97 | moredata = get_commit_data (zanrepo, commit_node, | |
98 | '{author|nonempty}\n{date(date, \'%A %d %B %Y %T\')}').split('\n') | |
99 | ||
100 | if len (moredata) != 2: | |
88 | 101 | raise HgProcessError ('malformed hg data while processing %s' % commit_node) |
87 | 102 | |
103 | commit_author = moredata[0] | |
104 | commit_date = moredata[1] | |
105 | commit_email = "" | |
90 | 106 | commit_message = zanrepo.hg_command ('log', '-r', commit_node, '--template', '{desc}') |
87 | 107 | |
108 | try: | |
109 | ticket_data = Bt.get_issue (ticket_id) | |
110 | except Exception as e: | |
88 | 111 | raise HgProcessError ("error while processing %s: %s" % (commit_node, e)) |
87 | 112 | |
113 | # Remove the email address from the author if possible | |
114 | rex = re.compile (r'^(.+) <([^>]+)>$.*') | |
115 | match = rex.match (commit_author) | |
116 | if match: | |
117 | commit_author = match.group (1) | |
118 | commit_email = match.group (2) | |
119 | ||
120 | commit_diffstat = zanrepo.hg_command ('diff', '--change', commit_node, '--stat') | |
121 | ||
122 | if len(commit_diffstat) > 0: | |
123 | # commit_diffstat = 'Changes in files:\n[code]\n' + commit_diffstat + '\n[/code]' | |
124 | commit_diffstat = 'Changes in files:\n' + bbcodify(commit_diffstat) | |
125 | else: | |
126 | commit_diffstat = 'No changes in files.' | |
127 | ||
128 | # Compare the email addresses against known developer usernames | |
129 | commit_trackeruser = Config.find_developer_by_email (commit_email) | |
130 | ||
131 | if commit_trackeruser != '': | |
132 | commit_author += ' [%s]' % commit_trackeruser | |
133 | ||
134 | message = 'Issue addressed by commit %s: [b][url=%s/commits/%s]%s[/url][/b]' \ | |
135 | % (commit_node, repo_url, commit_node, commit_message) | |
136 | message += "\nCommitted by %s on %s\n\n%s" \ | |
137 | % (commit_author, commit_date, commit_diffstat) | |
138 | ||
139 | need_update = False | |
140 | ||
141 | # If not already set, set handler | |
142 | if not 'handler' in ticket_data: | |
143 | ticket_data['handler'] = {'name': commit_trackeruser} | |
144 | need_update = True | |
145 | ||
146 | # Find out the status level of the ticket | |
147 | needs_testing_level = 70 | |
148 | ||
149 | if ticket_data['status']['id'] < needs_testing_level: | |
150 | ticket_data.status['id'] = needs_testing_level | |
151 | need_update = True | |
152 | ||
153 | # Set target version if not set | |
154 | if not 'target_version' in ticket_data: | |
155 | ticket_data['target_version'] = '1.4' if repo_name == 'zandronum-stable' else '2.0' | |
156 | need_update = True | |
157 | elif (ticket_data['target_version'] == '2.0' or ticket_data['target_version'] == '2.0-beta') \ | |
158 | and repo_name == 'zandronum-stable': | |
159 | # Target version was 2.0 but this was just committed to zandronum-stable, adjust | |
160 | ticket_data['target_version'] = '1.4' | |
161 | need_update = True | |
162 | elif ticket_data['target_version'] == '2.0-beta': | |
163 | # Fix target version from 2.0-beta to 2.0 | |
164 | ticket_data['target_version'] = '2.0' | |
165 | need_update = True | |
166 | ||
167 | # Announce on IRC | |
168 | for irc_client in Irc.all_clients: | |
169 | for channel in irc_client.channels: | |
170 | if channel.get_value ('btannounce', default=True): | |
171 | irc_client.privmsg (channel.get_value ('name'), | |
101
5e32ab7ae823
- no need to post the commit message on FIXES irc notifications since the commit is posted anyway
Teemu Piippo <crimsondusk64@gmail.com>
parents:
100
diff
changeset
|
172 | "%s: commit %s FIXES issue %d" % (repo_name, commit_node, ticket_id)) |
87 | 173 | irc_client.privmsg (channel.get_value ('name'), |
174 | "Read all about it here: " + Bt.get_ticket_url (ticket_id)) | |
175 | ||
176 | if need_update: | |
177 | # We need to remove the note data, otherwise the ticket notes | |
178 | # will get unnecessary updates. WTF, MantisBT? | |
179 | ticket_data.notes = [] | |
180 | Bt.update_issue (ticket_id, ticket_data) | |
181 | ||
182 | Bt.post_note (ticket_id, message) | |
183 | ||
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
184 | def init(): |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
185 | check_repo_exists ('zandronum', 'Torr_Samaho') |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
186 | check_repo_exists ('zandronum-stable', 'Torr_Samaho') |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
187 | check_repo_exists ('zandronum-sandbox', 'crimsondusk') |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
188 | check_repo_exists ('zandronum-sandbox-stable', 'crimsondusk') |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
189 | check_repo_exists ('zandronum-everything', '') |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
190 | global repocheck_timeout |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
191 | repocheck_timeout = (time.time()) + 15 |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
192 | |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
193 | def get_commit_data (zanrepo, rev, template): |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
194 | return zanrepo.hg_command ('log', '-l', '1', '-r', rev, '--template', template) |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
195 | |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
196 | def decipher_hgapi_error (e): |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
197 | # Blah, hgapi, why must your error messages be so mangled? |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
198 | try: |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
199 | rawmsg = e.message.replace('\n', '').replace('" +','').replace('\t','') |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
200 | errmsg = re.compile (r'.*: tErr: (.*)Out:.*').match (rawmsg).group (1) |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
201 | return [True, errmsg] |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
202 | except: |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
203 | return [False, ''] |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
204 | |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
205 | def bbcodify (commit_diffstat): |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
206 | result = '' |
87 | 207 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
208 | for line in commit_diffstat.split('\n'): |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
209 | rex = re.compile (r'^(.*)\|(.*) (\+*)(-*)(.*)$') |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
210 | match = rex.match (line) |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
211 | if match: |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
212 | line = '%s|%s [color=#5F7]%s[/color][color=#F53]%s[/color]%s\n' \ |
87 | 213 | % (match.group (1), match.group (2), match.group (3), match.group (4), match.group |
214 | (5)) | |
215 | ||
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
216 | # Tracker doesn't seem to like empty color tags |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
217 | line = line.replace ('[color=#5F7][/color]', '').replace ('[color=#F53][/color]', '') |
87 | 218 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
219 | result += line |
87 | 220 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
221 | return result |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
222 | |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
223 | def poll(): |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
224 | global repocheck_timeout |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
225 | if time.time() < repocheck_timeout: |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
226 | return |
87 | 227 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
228 | for n in ['zandronum-stable', 'zandronum', 'zandronum-sandbox', 'zandronum-sandbox-stable']: |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
229 | poll_one_repo (n) |
87 | 230 | |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
231 | hgns = Config.get_node ('hg') |
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
232 | repocheck_timeout = time.time() + hgns.get_value ('checkinterval', default=15) * 60 |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
233 | |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
234 | def poll_one_repo (repo_name): |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
235 | global repocheck_timeout |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
236 | hgns = Config.get_node ('hg') |
87 | 237 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
238 | if not hgns.get_value ('track', default=True): |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
239 | return |
87 | 240 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
241 | usesandbox = repo_name == 'zandronum-sandbox' or repo_name == 'zandronum-sandbox-stable' |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
242 | repo_owner = 'Torr_Samaho' if not usesandbox else 'crimsondusk' |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
243 | zanrepo = hgapi.Repo (repo_name) |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
244 | commit_data = [] |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
245 | delimeter = '@@@@@@@@@@' |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
246 | print 'Checking %s for updates' % repo_name |
87 | 247 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
248 | try: |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
249 | data = zanrepo.hg_command ('incoming', '--quiet', '--template', |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
250 | '{node|short} {desc}' + delimeter) |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
251 | except hgapi.hgapi.HgException as e: |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
252 | deciphered = decipher_hgapi_error (e) |
87 | 253 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
254 | if deciphered[0] and len(deciphered[1]) > 0: |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
255 | Irc.broadcast ("error while using hg import on %s: %s" % (repo_name, deciphered[1])) |
87 | 256 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
257 | return |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
258 | except Exception as e: |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
259 | Irc.broadcast ("%s" % `e`) |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
260 | return |
87 | 261 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
262 | for line in data.split (delimeter): |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
263 | if line == '': |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
264 | continue |
87 | 265 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
266 | rex = re.compile (r'([^ ]+) (.+)') |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
267 | match = rex.match (line) |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
268 | failed = False |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
269 | |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
270 | if not match: |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
271 | Irc.broadcast ('malformed hg data: %s' % line) |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
272 | continue |
87 | 273 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
274 | commit_node = match.group (1) |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
275 | commit_message = match.group (2) |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
276 | commit_data.append ([commit_node, commit_message]) |
87 | 277 | |
97 | 278 | process_new_commits (repo_name, commit_data) |
279 | ||
280 | def process_new_commits (repo_name, commit_data): | |
98
4edbdf390bd1
- fix previous commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
97
diff
changeset
|
281 | usestable = repo_name == 'zandronum-stable' |
4edbdf390bd1
- fix previous commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
97
diff
changeset
|
282 | usesandbox = repo_name == 'zandronum-sandbox' or repo_name == 'zandronum-sandbox-stable' |
4edbdf390bd1
- fix previous commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
97
diff
changeset
|
283 | repo_owner = 'Torr_Samaho' if not usesandbox else 'crimsondusk' |
4edbdf390bd1
- fix previous commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
97
diff
changeset
|
284 | repo_url = 'https://bitbucket.org/%s/%s' % (repo_owner, repo_name) |
4edbdf390bd1
- fix previous commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
97
diff
changeset
|
285 | num_commits = 0 |
4edbdf390bd1
- fix previous commit
Teemu Piippo <crimsondusk64@gmail.com>
parents:
97
diff
changeset
|
286 | zanrepo = hgapi.Repo (repo_name) |
97 | 287 | Irc.broadcast ('%d new commits on %s' % (len (commit_data), repo_name)) |
87 | 288 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
289 | if len (commit_data) > 0: |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
290 | pull_args = []; |
87 | 291 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
292 | for commit in commit_data: |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
293 | pull_args.append ('-r'); |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
294 | pull_args.append (commit[0]); |
87 | 295 | |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
296 | print 'Pulling new commits...' |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
297 | try: |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
298 | zanrepo.hg_command ('pull', *pull_args) |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
299 | |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
300 | # Also pull these commits to the zandronum main repository |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
301 | if usestable: |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
302 | devrepo = hgapi.Repo ('zandronum') |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
303 | devrepo.hg_command ('pull', '../zandronum-stable', *pull_args) |
87 | 304 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
305 | # Pull everything into sandboxes too |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
306 | if not usesandbox: |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
307 | devrepo = hgapi.Repo ('zandronum-sandbox') |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
308 | devrepo.hg_command ('pull', '../%s' % repo_name, *pull_args) |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
309 | |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
310 | devrepo = hgapi.Repo ('zandronum-sandbox-stable') |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
311 | devrepo.hg_command ('pull', '../%s' % repo_name, *pull_args) |
87 | 312 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
313 | devrepo = hgapi.Repo ('zandronum-everything') |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
314 | devrepo.hg_command ('pull', '../%s' % repo_name, *pull_args) |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
315 | |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
316 | global g_needCommitsTxtRebuild |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
317 | g_needCommitsTxtRebuild = True |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
318 | except Exception as e: |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
319 | Irc.broadcast ('Warning: unable to pull: %s' % `e`) |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
320 | return |
87 | 321 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
322 | for commit in commit_data: |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
323 | commit_node = commit[0] |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
324 | commit_message = commit[1] |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
325 | print 'Processing new commit %s...' % commit_node |
87 | 326 | |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
327 | try: |
100
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
328 | commit_author = get_commit_data (zanrepo, commit_node, '{author}') |
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
329 | commit_url = '%s/commits/%s' % (repo_url, commit_node) |
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
330 | commit_email = '' |
87 | 331 | |
100
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
332 | # Remove the email address from the author if possible |
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
333 | rex = re.compile (r'^(.+) <([^>]+)>$.*') |
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
334 | match = rex.match (commit_author) |
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
335 | if match: |
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
336 | commit_author = match.group (1) |
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
337 | commit_email = match.group (2) |
87 | 338 | |
100
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
339 | commit_trackeruser = Config.find_developer_by_email (commit_email) |
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
340 | committer = commit_trackeruser if commit_trackeruser != '' else commit_author |
87 | 341 | |
100
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
342 | for irc_client in Irc.all_clients: |
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
343 | for channel in irc_client.channels: |
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
344 | if not usesandbox or channel.get_value ('btprivate', False): |
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
345 | irc_client.privmsg (channel.get_value ('name'), |
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
346 | "%s: new commit %s by %s: %s" |
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
347 | % (repo_name, commit_node, committer, commit_url)) |
87 | 348 | |
100
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
349 | for line in commit_message.split ('\n'): |
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
350 | irc_client.privmsg (channel.get_value ('name'), line) |
87 | 351 | |
100
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
352 | if not usesandbox: |
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
353 | rex = re.compile (r'^.*(fixes|resolves|addresses|should fix) ([0-9]+).*$') |
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
354 | match = rex.match (commit_message) |
87 | 355 | |
100
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
356 | if match: |
2a56ccf67782
- be more liberal on posting commit messages to IRC
Teemu Piippo <crimsondusk64@gmail.com>
parents:
98
diff
changeset
|
357 | announce_ticket_resolved (match.group (2), commit_node) |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
358 | |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
359 | num_commits += 1 |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
360 | except Exception as e: |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
361 | Irc.broadcast ('Error while processing %s: %s' % (commit_node, e)) |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
362 | continue |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
363 | |
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
364 | def force_poll(): |
73
d67cc4fbc3f1
- modularization complete!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
72
diff
changeset
|
365 | global repocheck_timeout |
72
2266d6d73de3
- commit work done on splitting bt/hg
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
366 | repocheck_timeout = 0 |
85
302e2bec51d8
- fixed bad find_developer_by_email call
Teemu Piippo <crimsondusk64@gmail.com>
parents:
76
diff
changeset
|
367 | poll() |