mod_hgpoll.py

changeset 111
44d9aea72947
parent 110
b2770c43b752
child 112
cdafc1a0544e
equal deleted inserted replaced
110:b2770c43b752 111:44d9aea72947
49 # Possibly we're passed a date version instead. Try find the node for this. 49 # Possibly we're passed a date version instead. Try find the node for this.
50 try: 50 try:
51 datetime.strptime (args['key'], '%y%m%d-%H%M') 51 datetime.strptime (args['key'], '%y%m%d-%H%M')
52 HgPoll.make_commits_txt() 52 HgPoll.make_commits_txt()
53 commits_txt = open ('commits.txt', 'r') 53 commits_txt = open ('commits.txt', 'r')
54 54
55 for line in commits_txt: 55 for line in commits_txt:
56 data = line.replace ('\n', '').split (' ') 56 data = line.replace ('\n', '').split (' ')
57 if data[1] == args['key']: 57 if data[1] == args['key']:
58 node = data[0] 58 node = data[0]
59 break 59 break
60 else: 60 else:
61 bot.privmsg (replyto, 'couldn\'t find changset for date %s' % args['key']) 61 bot.privmsg (replyto, 'couldn\'t find changset for date %s' % args['key'])
62 return 62 return
63 except ValueError: 63 except ValueError:
64 pass 64 pass
65 65
66 # The sandboxes contain all revisions in zandronum and zandronum-stable. 66 # The sandboxes contain all revisions in zandronum and zandronum-stable.
67 # Thus we only need to try find the revision in the sandbox repos. 67 # Thus we only need to try find the revision in the sandbox repos.
68 try: 68 try:
69 data = repo.hg_command ("log", "-r", node, "--template", 69 data = repo.hg_command ("log", "-r", node, "--template",
70 "{node|short}@@@@@@@{desc}@@@@@@@{author}@@@@@@@{diffstat}@@@@@@@{date|hgdate}") 70 "{node|short}@@@@@@@" +
71 "{desc}@@@@@@@" +
72 "{author}@@@@@@@" +
73 "{diffstat}@@@@@@@" +
74 "{date|hgdate}@@@@@@@" +
75 "{bookmarks}")
71 except hgapi.HgException: 76 except hgapi.HgException:
72 bot.privmsg (replyto, 'couldn\'t find changeset %s' % (node)) 77 bot.privmsg (replyto, 'couldn\'t find changeset %s' % (node))
73 return 78 return
74 79
75 try: 80 try:
76 data = data.split ('@@@@@@@') 81 data = data.split ('@@@@@@@')
77 node = data[0] 82 node = data[0]
78 message = data[1] 83 message = data[1]
79 author = data[2] 84 author = data[2]
80 diffstat = data[3] 85 diffstat = data[3]
81 date = datetime.utcfromtimestamp (int (data[4].split (' ')[0])) 86 date = datetime.utcfromtimestamp (int (data[4].split (' ')[0]))
87 bookmarks = data[5]
82 delta = datetime.utcnow() - date 88 delta = datetime.utcnow() - date
83 datestring = '' 89 datestring = ''
84 90
91 if bookmarks:
92 bookmarks = HgPoll.prettify_bookmarks (bookmarks)
93
85 # Find out the Zandronum version of this changeset 94 # Find out the Zandronum version of this changeset
86 repo.hg_command ('revert', '-r', node, 'src/version.h') 95 repo.hg_command ('revert', '-r', node, 'src/version.h')
87 zanversion = '<unknown zandronum version>' 96 zanversion = '<unknown zandronum version>'
88 97
89 with open ('zandronum-everything/src/version.h') as version_file: 98 with open ('zandronum-everything/src/version.h') as version_file:
90 regexps = [ \ 99 regexps = [ \
91 re.compile (r'#define\s+GAMEVER_STRING\s+"([^"]+)"'), \ 100 re.compile (r'#define\s+GAMEVER_STRING\s+"([^"]+)"'), \
92 re.compile (r'#define\s+DOTVERSIONSTR_NOREV\s+"([^"]+)"'), \ 101 re.compile (r'#define\s+DOTVERSIONSTR_NOREV\s+"([^"]+)"'), \
93 re.compile (r'#define\s+DOTVERSIONSTR\s+"([^"]+)"')] 102 re.compile (r'#define\s+DOTVERSIONSTR\s+"([^"]+)"')]
94 103
95 for line in version_file: 104 for line in version_file:
96 for rex in regexps: 105 for rex in regexps:
97 match = rex.match (line) 106 match = rex.match (line)
98 if match != None: 107 if match != None:
99 zanversion = match.group (1) 108 zanversion = match.group (1)
100 break 109 break
101 110
102 if match != None: 111 if match != None:
103 break 112 break
104 113
105 114
106 repo.hg_command ('revert', '--all') 115 repo.hg_command ('revert', '--all')
107 116
108 # Remove the email address from the author if possible 117 # Remove the email address from the author if possible
109 match = re.compile (r'^(.+) <([^>]+)>$.*').match (author) 118 match = re.compile (r'^(.+) <([^>]+)>$.*').match (author)
110 if match: 119 if match:
111 author = match.group (1) 120 author = match.group (1)
112 email = match.group (2) 121 email = match.group (2)
113 122
114 username = Config.find_developer_by_email (email) 123 username = Config.find_developer_by_email (email)
115 124
116 if username != '': 125 if username != '':
117 author = username 126 author = username
118 127
119 # Try prettify the diffstat 128 # Try prettify the diffstat
120 rex = re.compile (r'^([0-9]+): \+([0-9]+)/-([0-9]+)$') 129 rex = re.compile (r'^([0-9]+): \+([0-9]+)/-([0-9]+)$')
135 datestring = '%d hour%s ago' % (hours, plural (hours)) 144 datestring = '%d hour%s ago' % (hours, plural (hours))
136 else: 145 else:
137 datestring = '%d day%s ago' % (delta.days, plural (delta.days)) 146 datestring = '%d day%s ago' % (delta.days, plural (delta.days))
138 else: 147 else:
139 datestring = 'on %s' % (str (date)) 148 datestring = 'on %s' % (str (date))
140 149
141 bot.privmsg (replyto, 'changeset\0035 %s (%s %s)\003: committed by\0032 %s\003 %s,\0032 %s' % \ 150 bot.privmsg (replyto, 'changeset\0035 %s%s\003 (%s %s)\003: committed by\0032 %s\003 %s,\0032 %s' % \
142 (node, zanversion, date.strftime ('%y%m%d-%H%M'), author, datestring, diffstat)) 151 (node, bookmarks, zanversion, date.strftime ('%y%m%d-%H%M'), author, datestring, diffstat))
143 152
144 for line in message.split ('\n'): 153 for line in message.split ('\n'):
145 bot.privmsg (replyto, ' ' + line) 154 bot.privmsg (replyto, ' ' + line)
146 except hgapi.HgException as e: 155 except hgapi.HgException as e:
147 result = HgPoll.decipher_hgapi_error (e) 156 result = HgPoll.decipher_hgapi_error (e)
148 157
149 if result[0]: 158 if result[0]:
150 bot.privmsg (replyto, 'error: %s' % result[1]) 159 bot.privmsg (replyto, 'error: %s' % result[1])
151 else: 160 else:
152 bot.privmsg (replyto, 'error: %s' % `e`) 161 bot.privmsg (replyto, 'error: %s' % `e`)
153 162
156 repo = hgapi.Repo (args['repo']) 165 repo = hgapi.Repo (args['repo'])
157 result = repo.hg_command (*args['command']) 166 result = repo.hg_command (*args['command'])
158 self.privmsg (replyto, result) 167 self.privmsg (replyto, result)
159 except hgapi.hgapi.HgException as e: 168 except hgapi.hgapi.HgException as e:
160 result = HgPoll.decipher_hgapi_error (e) 169 result = HgPoll.decipher_hgapi_error (e)
161 170
162 if result[0]: 171 if result[0]:
163 self.privmsg (replyto, 'error: %s' % result[1]) 172 self.privmsg (replyto, 'error: %s' % result[1])
164 else: 173 else:
165 self.privmsg (replyto, 'error: %s' % `e`) 174 self.privmsg (replyto, 'error: %s' % `e`)
166 175

mercurial