- Encode messages in the hgpoll module so that joining them won't result in an error if they cannot be coded to ascii

Mon, 03 Aug 2015 19:45:57 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Mon, 03 Aug 2015 19:45:57 +0300
changeset 145
588aff83bb87
parent 144
b3d1b356e544
child 146
c17b82b1f573

- Encode messages in the hgpoll module so that joining them won't result in an error if they cannot be coded to ascii
- Support for Doomseeker's VERSION_STRING in version string parsing

hgpoll.py file | annotate | diff | comparison | revisions
mod_hg.py file | annotate | diff | comparison | revisions
--- a/hgpoll.py	Sun Aug 02 17:15:00 2015 +0300
+++ b/hgpoll.py	Mon Aug 03 19:45:57 2015 +0300
@@ -439,6 +439,11 @@
 			Irc.broadcast ('Error while processing %s: %s' % (commit_node, e))
 			continue
 
+	# Encode messages
+	for messagelist in messages:
+		for i in range (0, len (messagelist)):
+			messagelist[i] = messagelist[i].decode ("utf-8", "ignore").encode("ascii", "ignore")
+
 	fullMessageLength = len (''.join (messages[2]))
 
 	if fullMessageLength > 3000:
--- a/mod_hg.py	Sun Aug 02 17:15:00 2015 +0300
+++ b/mod_hg.py	Mon Aug 03 19:45:57 2015 +0300
@@ -109,6 +109,30 @@
 
 	return (node, reponame)
 
+def get_version_string (reponame, node):
+	try:
+		data = subprocess.check_output (['hg', '--cwd', reponame, 'cat',
+			'--rev', node, 'src/version.h'])
+
+		regexps = [ \
+			re.compile (r'#define\s+GAMEVER_STRING\s+"([^"]+)"'), \
+			re.compile (r'#define\s+DOTVERSIONSTR_NOREV\s+"([^"]+)"'), \
+			re.compile (r'#define\s+DOTVERSIONSTR\s+"([^"]+)"')]
+	except subprocess.CalledProcessError:
+		try:
+			data = subprocess.check_output (['hg', '--cwd', reponame, 'cat',
+				'--rev', node, 'src/core/versiondefs.h'])
+			regexps = [re.compile (r'#define\s+VERSION_STRING\s+"([^"]+)"')]
+		except subprocess.CalledProcessError:
+			return ''
+
+	for line in data.splitlines():
+		for rex in regexps:
+			match = rex.match (line)
+
+			if match:
+				return match.group (1)
+
 def cmd_cset (bot, args, reply, **rest):
 	data = ""
 	node, reponame = resolve_node (args['key'])
@@ -146,27 +170,8 @@
 	if bookmarks:
 		bookmarks = HgPoll.prettify_bookmarks (bookmarks)
 
-	# Find out the Zandronum version of this changeset
-	data = subprocess.check_output (['hg', '--cwd', reponame, 'cat', '--rev', node, 'src/version.h'])
-	zanversion = '<unknown version>'
-
-	try:
-		regexps = [ \
-			re.compile (r'#define\s+GAMEVER_STRING\s+"([^"]+)"'), \
-			re.compile (r'#define\s+DOTVERSIONSTR_NOREV\s+"([^"]+)"'), \
-			re.compile (r'#define\s+DOTVERSIONSTR\s+"([^"]+)"')]
-
-		for line in data.splitlines():
-			for rex in regexps:
-				match = rex.match (line)
-				if match != None:
-					zanversion = match.group (1)
-					break
-
-			if match != None:
-				break
-	except IOError:
-		pass
+	# Find out the version string of this changeset
+	versionstring = get_version_string (reponame, node)
 
 	subprocess.call (['hg', '--cwd', reponame, 'revert', '--all'])
 	username = Config.find_developer_by_email (email)
@@ -195,15 +200,19 @@
 	else:
 		datestring = 'on %s' % (str (date))
 
-	versionstring = ""
 	if latesttagdistance != 0:
-		versionstring = '%s %s, %d hops from %s' % (zanversion, date.strftime ('%y%m%d-%H%M'),
+		versionblurb = ""
+
+		if versionstring:
+			versionblurb = versionstring + ' '
+
+		versionblurb += '%s, %d hops from %s' % (date.strftime ('%y%m%d-%H%M'),
 			latesttagdistance, latesttag)
 	else:
-		versionstring = latesttag
+		versionblurb = latesttag
 
 	reply ('changeset\0035 %s%s\003 (%s)\003: committed by\0032 %s\003 %s,\0032 %s' % \
-		(node, bookmarks, versionstring, author, datestring, diffstat))
+		(node, bookmarks, versionblurb, author, datestring, diffstat))
 
 	for line in message.split ('\n'):
 		reply ('    ' + line)

mercurial