214 zanrepo = hgapi.Repo (repo_name) |
215 zanrepo = hgapi.Repo (repo_name) |
215 |
216 |
216 try: |
217 try: |
217 zanrepo.hg_command ('id', '.') |
218 zanrepo.hg_command ('id', '.') |
218 except hgapi.hgapi.HgException: |
219 except hgapi.hgapi.HgException: |
219 # If the repo does not exist, clone it. After cloning, there obviously |
220 # If the repo does not exist, clone it. zandronum-everything can be spawned off other repos though |
220 # are no more updates, so we'll be done. |
221 if repo_name == 'zandronum-everything': |
|
222 if not os.path.exists (repo_name): |
|
223 os.makedirs (repo_name) |
|
224 |
|
225 global g_needCommitsTxtRebuild |
|
226 g_needCommitsTxtRebuild = True |
|
227 print 'Init %s' % repo_name |
|
228 zanrepo.hg_command ('init') |
|
229 print 'Cloning zandronum-sandbox into %s' % repo_name |
|
230 zanrepo.hg_command ('pull', '../zandronum-sandbox') |
|
231 print 'Cloning zandronum-sandbox-stable into %s' % repo_name |
|
232 zanrepo.hg_command ('pull', '../zandronum-sandbox-stable') |
|
233 print 'Done' |
|
234 make_commits_txt() |
|
235 return |
|
236 #fi |
|
237 |
221 try: |
238 try: |
222 print 'Cloning %s...' % repo_name |
239 print 'Cloning %s...' % repo_name |
223 zanrepo.hg_clone (repo_url, repo_name) |
240 zanrepo.hg_clone (repo_url, repo_name) |
224 print 'Cloning done. No update checking needed.' |
241 print 'Cloning done.' |
225 except Exception as e: |
242 except Exception as e: |
226 print 'Unable to clone %s from %s: %s' % (repo_name, repo_url, str (`e`)) |
243 print 'Unable to clone %s from %s: %s' % (repo_name, repo_url, str (`e`)) |
227 quit(1) |
244 quit(1) |
228 #tried |
245 #tried |
229 #enddef |
246 #enddef |
230 |
247 |
231 check_repo_exists ('zandronum', 'Torr_Samaho') |
248 check_repo_exists ('zandronum', 'Torr_Samaho') |
232 check_repo_exists ('zandronum-stable', 'Torr_Samaho') |
249 check_repo_exists ('zandronum-stable', 'Torr_Samaho') |
233 check_repo_exists ('zandronum-sandbox', 'crimsondusk') |
250 check_repo_exists ('zandronum-sandbox', 'crimsondusk') |
234 check_repo_exists ('zandronum-sandbox-stable', 'crimsondusk') |
251 check_repo_exists ('zandronum-sandbox-stable', 'crimsondusk') |
|
252 check_repo_exists ('zandronum-everything', '') |
235 |
253 |
236 repocheck_timeout = {'zandronum':(time.time()) + 15, 'zandronum-stable':(time.time() + 15), 'zandronum-sandbox':(time.time()) + 15, 'zandronum-sandbox-stable':(time.time()) + 15} |
254 repocheck_timeout = {'zandronum':(time.time()) + 15, 'zandronum-stable':(time.time() + 15), 'zandronum-sandbox':(time.time()) + 15, 'zandronum-sandbox-stable':(time.time()) + 15} |
237 |
255 |
238 def get_commit_data (zanrepo, rev, template): |
256 def get_commit_data (zanrepo, rev, template): |
239 return zanrepo.hg_command ('log', '-l', '1', '-r', rev, '--template', template) |
257 return zanrepo.hg_command ('log', '-l', '1', '-r', rev, '--template', template) |
285 #done |
303 #done |
286 |
304 |
287 return '' |
305 return '' |
288 #enddef |
306 #enddef |
289 |
307 |
|
308 def make_commits_txt(): |
|
309 global g_needCommitsTxtRebuild |
|
310 |
|
311 if g_needCommitsTxtRebuild == False: |
|
312 return |
|
313 |
|
314 print 'Building commits.txt...' |
|
315 # Update zandronum-everything |
|
316 repo = hgapi.Repo ('zandronum-everything') |
|
317 repo.hg_command ('pull', '../zandronum-sandbox') |
|
318 repo.hg_command ('pull', '../zandronum-sandbox-stable') |
|
319 |
|
320 data = repo.hg_command ('log', '--template', '{node} {date(date, "%y%m%d-%H%M")}\n') |
|
321 f = open ('commits.txt', 'w') |
|
322 f.write (data) |
|
323 f.close() |
|
324 g_needCommitsTxtRebuild = False |
|
325 #enddef |
|
326 |
290 ' Retrieves and processes commits for zandronum repositories ' |
327 ' Retrieves and processes commits for zandronum repositories ' |
291 ' Ensure both repositories are OK before using this! ' |
328 ' Ensure both repositories are OK before using this! ' |
292 def process_zan_repo_updates (repo_name): |
329 def process_zan_repo_updates (repo_name): |
293 global repocheck_timeout |
330 global repocheck_timeout |
294 global suds_client |
331 global suds_client |
1055 #tried |
1098 #tried |
1056 elif command == 'changeset' or command == 'cset' or command == 'rev': |
1099 elif command == 'changeset' or command == 'cset' or command == 'rev': |
1057 if len(args) != 1: |
1100 if len(args) != 1: |
1058 raise logical_exception ('usage: %s <changeset>' % command) |
1101 raise logical_exception ('usage: %s <changeset>' % command) |
1059 |
1102 |
1060 repo = None |
1103 repo = hgapi.Repo ('zandronum-everything') |
1061 data = "" |
1104 data = "" |
|
1105 node = args[0] |
|
1106 |
|
1107 # Possibly we're passed a date version instead. Try find the node for this. |
|
1108 try: |
|
1109 datetime.strptime (args[0], '%y%m%d-%H%M') |
|
1110 make_commits_txt() |
|
1111 commits_txt = open ('commits.txt', 'r') |
|
1112 |
|
1113 for line in commits_txt: |
|
1114 data = line.replace ('\n', '').split (' ') |
|
1115 if data[1] == args[0]: |
|
1116 node = data[0] |
|
1117 break |
|
1118 else: |
|
1119 self.privmsg (replyto, 'couldn\'t find changset for date %s' % args[0]) |
|
1120 return |
|
1121 #done |
|
1122 except ValueError: |
|
1123 pass |
|
1124 #tried |
1062 |
1125 |
1063 # The sandboxes contain all revisions in zandronum and zandronum-stable. |
1126 # The sandboxes contain all revisions in zandronum and zandronum-stable. |
1064 # Thus we only need to try find the revision in the sandbox repos. |
1127 # Thus we only need to try find the revision in the sandbox repos. |
1065 for reponame in ['zandronum-sandbox', 'zandronum-sandbox-stable']: |
1128 try: |
1066 try: |
1129 repo.hg_command ("log", "-r", node, "--template", " ") |
1067 repo = hgapi.Repo (reponame) |
1130 except hgapi.hgapi.HgException: |
1068 repo.hg_command ("log", "-r", args[0], "--template", " ") |
1131 self.privmsg (replyto, 'couldn\'t find changeset %s' % (node)) |
1069 break |
1132 return |
1070 except hgapi.hgapi.HgException: |
1133 #tried |
1071 pass |
1134 |
1072 else: |
1135 try: |
1073 repo = None |
1136 data = repo.hg_command ("log", "-r", node, "--template", |
1074 #done |
1137 "{node|short}@@@@@@@{desc}@@@@@@@{author}@@@@@@@{diffstat}@@@@@@@{date(date, '%s')}") |
1075 |
1138 data = data.split ('@@@@@@@') |
1076 if repo == None: |
1139 |
1077 self.privmsg (replyto, 'couldn\'t find changeset %s' % (args[0])) |
1140 node = data[0] |
1078 else: |
1141 message = data[1] |
1079 try: |
1142 author = data[2] |
1080 data = repo.hg_command ("log", "-r", args[0], "--template", |
1143 diffstat = data[3] |
1081 "{node|short}@@@@@@@{desc}@@@@@@@{author}@@@@@@@{diffstat}@@@@@@@{date(date, '%s')}") |
1144 date = datetime.fromtimestamp (int (data[4])) |
1082 data = data.split ('@@@@@@@') |
1145 delta = datetime.now() - date |
1083 |
1146 datestring = '' |
1084 node = data[0] |
1147 |
1085 message = data[1] |
1148 # Remove the email address from the author if possible |
1086 author = data[2] |
1149 match = re.compile (r'^(.+) <([^>]+)>$.*').match (author) |
1087 diffstat = data[3] |
1150 if match: |
1088 date = datetime.fromtimestamp (int (data[4])) |
1151 author = match.group (1) |
1089 delta = datetime.now() - date |
1152 email = match.group (2) |
1090 datestring = '' |
1153 |
1091 |
1154 username = find_developer_by_email (email) |
1092 # Remove the email address from the author if possible |
1155 |
1093 match = re.compile (r'^(.+) <([^>]+)>$.*').match (author) |
1156 if username != '': |
1094 if match: |
1157 author = username |
1095 author = match.group (1) |
1158 |
1096 email = match.group (2) |
1159 if delta.days < 4: |
1097 |
1160 if delta.days == 0: |
1098 username = find_developer_by_email (email) |
1161 if delta.seconds < 60: |
1099 |
1162 datestring = 'just now' |
1100 if username != '': |
1163 elif delta.seconds < 3600: |
1101 author = username |
1164 minutes = delta.seconds / 60 |
1102 |
1165 datestring = '%d minute%s ago' % (minutes, plural (minutes)) |
1103 if delta.days < 4: |
|
1104 if delta.days == 0: |
|
1105 if delta.seconds < 60: |
|
1106 datestring = 'just now' |
|
1107 elif delta.seconds < 3600: |
|
1108 minutes = delta.seconds / 60 |
|
1109 datestring = '%d minute%s ago' % (minutes, plural (minutes)) |
|
1110 else: |
|
1111 hours = delta.seconds / 3600 |
|
1112 datestring = '%d hour%s ago' % (hours, plural (hours)) |
|
1113 else: |
1166 else: |
1114 datestring = '%d day%s ago' % (delta.days, plural (delta.days)) |
1167 hours = delta.seconds / 3600 |
|
1168 datestring = '%d hour%s ago' % (hours, plural (hours)) |
1115 else: |
1169 else: |
1116 datestring = 'on %s' % (str (date)) |
1170 datestring = '%d day%s ago' % (delta.days, plural (delta.days)) |
1117 #fi |
1171 else: |
1118 |
1172 datestring = 'on %s' % (str (date)) |
1119 self.privmsg (replyto, 'changeset %s (%s): committed by %s %s (%s)' % \ |
1173 #fi |
1120 (node, date.strftime('%g%m%d-%H%M'), author, datestring, diffstat)) |
1174 |
1121 |
1175 self.privmsg (replyto, 'changeset %s (%s): committed by %s %s (%s)' % \ |
1122 for line in message.split ('\n'): |
1176 (node, date.strftime('%g%m%d-%H%M'), author, datestring, diffstat)) |
1123 self.privmsg (replyto, ' ' + line) |
1177 |
1124 except hgapi.hgapi.HgException as e: |
1178 for line in message.split ('\n'): |
1125 result = decipher_hgapi_error (e) |
1179 self.privmsg (replyto, ' ' + line) |
1126 |
1180 except hgapi.hgapi.HgException as e: |
1127 if result[0]: |
1181 result = decipher_hgapi_error (e) |
1128 self.privmsg (replyto, 'error: %s' % result[1]) |
1182 |
1129 else: |
1183 if result[0]: |
1130 self.privmsg (replyto, 'error: %s' % `e`) |
1184 self.privmsg (replyto, 'error: %s' % result[1]) |
1131 #tried |
1185 else: |
1132 #fi |
1186 self.privmsg (replyto, 'error: %s' % `e`) |
|
1187 #tried |
1133 # else: |
1188 # else: |
1134 # raise logical_exception ("unknown command `.%s`" % command) |
1189 # raise logical_exception ("unknown command `.%s`" % command) |
1135 |
1190 |
1136 # |
1191 # |
1137 # Print a ticket announce to appropriate channels |
1192 # Print a ticket announce to appropriate channels |