# HG changeset patch # User Teemu Piippo # Date 1415113462 -7200 # Node ID 577cecfea94effd04fd4253818aa18bb8008e99d # Parent 947ec64aa2f4f4a6f281bdc1954872cc63b73c86 - now able to get changeset by date diff -r 947ec64aa2f4 -r 577cecfea94e cobalt.py --- a/cobalt.py Tue Nov 04 16:07:19 2014 +0200 +++ b/cobalt.py Tue Nov 04 17:04:22 2014 +0200 @@ -63,6 +63,7 @@ g_idgamesSearchURL = 'http://www.doomworld.com/idgames/api/api.php?action=search&query=%s&type=title&sort=date&out=json' g_BotActive = False +g_needCommitsTxtRebuild = True # # SOAP stuff @@ -216,12 +217,28 @@ try: zanrepo.hg_command ('id', '.') except hgapi.hgapi.HgException: - # If the repo does not exist, clone it. After cloning, there obviously - # are no more updates, so we'll be done. + # If the repo does not exist, clone it. zandronum-everything can be spawned off other repos though + if repo_name == 'zandronum-everything': + if not os.path.exists (repo_name): + os.makedirs (repo_name) + + global g_needCommitsTxtRebuild + g_needCommitsTxtRebuild = True + print 'Init %s' % repo_name + zanrepo.hg_command ('init') + print 'Cloning zandronum-sandbox into %s' % repo_name + zanrepo.hg_command ('pull', '../zandronum-sandbox') + print 'Cloning zandronum-sandbox-stable into %s' % repo_name + zanrepo.hg_command ('pull', '../zandronum-sandbox-stable') + print 'Done' + make_commits_txt() + return + #fi + try: print 'Cloning %s...' % repo_name zanrepo.hg_clone (repo_url, repo_name) - print 'Cloning done. No update checking needed.' + print 'Cloning done.' except Exception as e: print 'Unable to clone %s from %s: %s' % (repo_name, repo_url, str (`e`)) quit(1) @@ -232,6 +249,7 @@ check_repo_exists ('zandronum-stable', 'Torr_Samaho') check_repo_exists ('zandronum-sandbox', 'crimsondusk') check_repo_exists ('zandronum-sandbox-stable', 'crimsondusk') +check_repo_exists ('zandronum-everything', '') repocheck_timeout = {'zandronum':(time.time()) + 15, 'zandronum-stable':(time.time() + 15), 'zandronum-sandbox':(time.time()) + 15, 'zandronum-sandbox-stable':(time.time()) + 15} @@ -287,6 +305,25 @@ return '' #enddef +def make_commits_txt(): + global g_needCommitsTxtRebuild + + if g_needCommitsTxtRebuild == False: + return + + print 'Building commits.txt...' + # Update zandronum-everything + repo = hgapi.Repo ('zandronum-everything') + repo.hg_command ('pull', '../zandronum-sandbox') + repo.hg_command ('pull', '../zandronum-sandbox-stable') + + data = repo.hg_command ('log', '--template', '{node} {date(date, "%y%m%d-%H%M")}\n') + f = open ('commits.txt', 'w') + f.write (data) + f.close() + g_needCommitsTxtRebuild = False +#enddef + ' Retrieves and processes commits for zandronum repositories ' ' Ensure both repositories are OK before using this! ' def process_zan_repo_updates (repo_name): @@ -369,6 +406,12 @@ devrepo = hgapi.Repo ('zandronum-sandbox-stable') devrepo.hg_command ('pull', '../%s' % repo_name, *pull_args) #fi + + devrepo = hgapi.Repo ('zandronum-everything') + devrepo.hg_command ('pull', '../%s' % repo_name, *pull_args) + + global g_needCommitsTxtRebuild + g_needCommitsTxtRebuild = True except Exception as e: chanlog ('Warning: unable to pull: %s' % `e`) return @@ -1057,79 +1100,91 @@ if len(args) != 1: raise logical_exception ('usage: %s ' % command) - repo = None + repo = hgapi.Repo ('zandronum-everything') data = "" + node = args[0] + + # Possibly we're passed a date version instead. Try find the node for this. + try: + datetime.strptime (args[0], '%y%m%d-%H%M') + make_commits_txt() + commits_txt = open ('commits.txt', 'r') + + for line in commits_txt: + data = line.replace ('\n', '').split (' ') + if data[1] == args[0]: + node = data[0] + break + else: + self.privmsg (replyto, 'couldn\'t find changset for date %s' % args[0]) + return + #done + except ValueError: + pass + #tried # The sandboxes contain all revisions in zandronum and zandronum-stable. # Thus we only need to try find the revision in the sandbox repos. - for reponame in ['zandronum-sandbox', 'zandronum-sandbox-stable']: - try: - repo = hgapi.Repo (reponame) - repo.hg_command ("log", "-r", args[0], "--template", " ") - break - except hgapi.hgapi.HgException: - pass - else: - repo = None - #done + try: + repo.hg_command ("log", "-r", node, "--template", " ") + except hgapi.hgapi.HgException: + self.privmsg (replyto, 'couldn\'t find changeset %s' % (node)) + return + #tried + + try: + data = repo.hg_command ("log", "-r", node, "--template", + "{node|short}@@@@@@@{desc}@@@@@@@{author}@@@@@@@{diffstat}@@@@@@@{date(date, '%s')}") + data = data.split ('@@@@@@@') - if repo == None: - self.privmsg (replyto, 'couldn\'t find changeset %s' % (args[0])) - else: - try: - data = repo.hg_command ("log", "-r", args[0], "--template", - "{node|short}@@@@@@@{desc}@@@@@@@{author}@@@@@@@{diffstat}@@@@@@@{date(date, '%s')}") - data = data.split ('@@@@@@@') + node = data[0] + message = data[1] + author = data[2] + diffstat = data[3] + date = datetime.fromtimestamp (int (data[4])) + delta = datetime.now() - date + datestring = '' - node = data[0] - message = data[1] - author = data[2] - diffstat = data[3] - date = datetime.fromtimestamp (int (data[4])) - delta = datetime.now() - date - datestring = '' + # Remove the email address from the author if possible + match = re.compile (r'^(.+) <([^>]+)>$.*').match (author) + if match: + author = match.group (1) + email = match.group (2) - # Remove the email address from the author if possible - match = re.compile (r'^(.+) <([^>]+)>$.*').match (author) - if match: - author = match.group (1) - email = match.group (2) + username = find_developer_by_email (email) - username = find_developer_by_email (email) - - if username != '': - author = username + if username != '': + author = username - if delta.days < 4: - if delta.days == 0: - if delta.seconds < 60: - datestring = 'just now' - elif delta.seconds < 3600: - minutes = delta.seconds / 60 - datestring = '%d minute%s ago' % (minutes, plural (minutes)) - else: - hours = delta.seconds / 3600 - datestring = '%d hour%s ago' % (hours, plural (hours)) + if delta.days < 4: + if delta.days == 0: + if delta.seconds < 60: + datestring = 'just now' + elif delta.seconds < 3600: + minutes = delta.seconds / 60 + datestring = '%d minute%s ago' % (minutes, plural (minutes)) else: - datestring = '%d day%s ago' % (delta.days, plural (delta.days)) + hours = delta.seconds / 3600 + datestring = '%d hour%s ago' % (hours, plural (hours)) else: - datestring = 'on %s' % (str (date)) - #fi + datestring = '%d day%s ago' % (delta.days, plural (delta.days)) + else: + datestring = 'on %s' % (str (date)) + #fi - self.privmsg (replyto, 'changeset %s (%s): committed by %s %s (%s)' % \ - (node, date.strftime('%g%m%d-%H%M'), author, datestring, diffstat)) + self.privmsg (replyto, 'changeset %s (%s): committed by %s %s (%s)' % \ + (node, date.strftime('%g%m%d-%H%M'), author, datestring, diffstat)) - for line in message.split ('\n'): - self.privmsg (replyto, ' ' + line) - except hgapi.hgapi.HgException as e: - result = decipher_hgapi_error (e) + for line in message.split ('\n'): + self.privmsg (replyto, ' ' + line) + except hgapi.hgapi.HgException as e: + result = decipher_hgapi_error (e) - if result[0]: - self.privmsg (replyto, 'error: %s' % result[1]) - else: - self.privmsg (replyto, 'error: %s' % `e`) - #tried - #fi + if result[0]: + self.privmsg (replyto, 'error: %s' % result[1]) + else: + self.privmsg (replyto, 'error: %s' % `e`) + #tried # else: # raise logical_exception ("unknown command `.%s`" % command)