mod_hgpoll.py

changeset 113
08e9b1c1b324
parent 112
cdafc1a0544e
--- a/mod_hgpoll.py	Wed Dec 31 10:27:57 2014 -0500
+++ b/mod_hgpoll.py	Wed Dec 31 11:40:46 2014 -0500
@@ -4,6 +4,7 @@
 import re
 import bt as Bt
 from configfile import Config
+from modulecore import command_error
 
 ModuleData = {
 	'commands':
@@ -41,7 +42,7 @@
 def cmd_checkhg (bot, **rest):
 	HgPoll.force_poll()
 
-def cmd_cset (bot, args, replyto, **rest):
+def cmd_cset (bot, args, reply, **rest):
 	repo = Repo ('zandronum-everything')
 	data = ""
 	node = args['key']
@@ -58,13 +59,12 @@
 				node = data[0]
 				break
 		else:
-			bot.privmsg (replyto, 'couldn\'t find changset for date %s' % args['key'])
+			command_error ('couldn\'t find changeset for date %s' % args['key'])
 			return
 	except ValueError:
 		pass
 
-	# The sandboxes contain all revisions in zandronum and zandronum-stable.
-	# Thus we only need to try find the revision in the sandbox repos.
+	# zandronum-everything contains all zandronum changesets, so look for changesets in that.
 	try:
 		data = repo.hg_command ("log", "-l1", "-r", node, "--template",
 			"{node|short}@@@@@@@" +
@@ -76,7 +76,7 @@
 			"{latesttagdistance}@@@@@@@" +
 			"{latesttag}")
 	except hgapi.HgException:
-		bot.privmsg (replyto, 'couldn\'t find changeset %s' % (node))
+		command_error ('couldn\'t find changeset %s' % (node))
 		return
 
 	try:
@@ -87,7 +87,7 @@
 		diffstat = data[3]
 		date = datetime.utcfromtimestamp (int (data[4].split (' ')[0]))
 		bookmarks = data[5]
-		latesttagdistance = int( data[6] )
+		latesttagdistance = int (data[6])
 		latesttag = data[7]
 		delta = datetime.utcnow() - date
 		datestring = ''
@@ -157,34 +157,34 @@
 		else:
 			versionstring = latesttag
 
-		bot.privmsg (replyto, 'changeset\0035 %s%s\003 (%s)\003: committed by\0032 %s\003 %s,\0032 %s' % \
+		reply ('changeset\0035 %s%s\003 (%s)\003: committed by\0032 %s\003 %s,\0032 %s' % \
 			(node, bookmarks, versionstring, author, datestring, diffstat))
 
 		for line in message.split ('\n'):
-			bot.privmsg (replyto, '    ' + line)
+			reply ('    ' + line)
 	except hgapi.HgException as e:
 		result = HgPoll.decipher_hgapi_error (e)
 
 		if result[0]:
-			bot.privmsg (replyto, 'error: %s' % result[1])
+			command_error (result[1])
 		else:
-			bot.privmsg (replyto, 'error: %s' % `e`)
+			command_error (`e`)
 
 def cmd_hg (bot, args, **rest):
 	try:
 		repo = hgapi.Repo (args['repo'])
 		result = repo.hg_command (*args['command'])
-		self.privmsg (replyto, result)
+		reply (replyto, result)
 	except hgapi.hgapi.HgException as e:
 		result = HgPoll.decipher_hgapi_error (e)
 
 		if result[0]:
-			self.privmsg (replyto, 'error: %s' % result[1])
+			command_error (result[1])
 		else:
-			self.privmsg (replyto, 'error: %s' % `e`)
+			command_error (`e`)
 
 def cmd_resolves (bot, args, replyto, **rest):
 	try:
 		HgPoll.announce_ticket_resolved (args['ticket'], args['changeset'])
 	except Exception as e:
-		bot.privmsg (replyto, 'Error: %s' % e)
+		command_error (str (e))

mercurial