Remove more manifests

Mon, 17 Aug 2015 02:05:16 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Mon, 17 Aug 2015 02:05:16 +0300
changeset 155
5a9b5065f53f
parent 154
df862cca1773
child 156
5747c959c293

Remove more manifests

mod_bt.py file | annotate | diff | comparison | revisions
mod_hg.py file | annotate | diff | comparison | revisions
mod_util.py file | annotate | diff | comparison | revisions
modulecore.py file | annotate | diff | comparison | revisions
--- a/mod_bt.py	Sun Aug 16 23:30:11 2015 +0300
+++ b/mod_bt.py	Mon Aug 17 02:05:16 2015 +0300
@@ -28,50 +28,26 @@
 
 from __future__ import print_function
 import bt
-
-ModuleData = {
-	'commands':
-	[
-		{
-			'name': 'ticket',
-			'description': 'Gets ticket info',
-			'args': '<ticket>',
-			'level': 'normal',
-		},
+import modulecore
 
-		{
-			'name': 'testannounce',
-			'description': 'Tests the ticket announcer',
-			'args': '<ticket>',
-			'level': 'admin',
-		},
-		
-		{
-			'name': 'checkbt',
-			'description': 'Polls the bug tracker for new tickets',
-			'args': None,
-			'level': 'admin',
-		},
-		
-		{
-			'name': 'btsoap',
-			'description': 'Sends a custom SOAP query',
-			'args': '<func> [args...]',
-			'level': 'admin',
-		},
-	]
-}
-
-def cmd_ticket (bot, args, replyto, **rest):
+@modulecore.irc_command (args='<ticket>')
+def ticket (bot, args, replyto, **rest):
+	'''Gets information about a MantisBT ticket.'''
 	bt.get_ticket_data (bot, replyto, args['ticket'], True)
 
-def cmd_testannounce (bot, args, **rest):
+@modulecore.irc_command (args='<ticket>', level='admin')
+def testannounce (bot, args, **rest):
+	'''Tests the ticket announcer.'''
 	bt.announce_new_issue (bot, bt.get_issue (args['ticket']))
 
-def cmd_checkbt (bot, **rest):
+@modulecore.irc_command (level='admin')
+def checkbt (bot, **rest):
+	'''Polls the bug tracker for new tickets.'''
 	bt.poll()
 
-def cmd_btsoap (bot, args, reply, **rest):
+@modulecore.irc_command (args='<func> [args...]', level='admin')
+def btsoap (bot, args, reply, **rest):
+	'''Sends a custom SOAP query'''
 	result = bt.custom_query (args['func'], args['args'].split (' ') if 'args' in args else [])
 
 	for line in result.splitlines():
--- a/mod_hg.py	Sun Aug 16 23:30:11 2015 +0300
+++ b/mod_hg.py	Mon Aug 17 02:05:16 2015 +0300
@@ -32,41 +32,12 @@
 import re
 import subprocess
 from configfile import Config
-from modulecore import command_error
+import modulecore
 from hgdb import HgCommitsDatabase
 
-ModuleData = {
-	'commands':
-	[
-		{
-			'name': 'checkhg',
-			'description': 'Polls the zandronum repositories for updates',
-			'args': None,
-			'level': 'admin',
-		},
-
-		{
-			'name': 'cset',
-			'description': 'Yields changeset information (use a hash or date as key)',
-			'args': '<key>',
-			'level': 'normal',
-		},
-
-		{
-			'name': 'resolves',
-			'description': '''Manually cause a ticket to be resolved by a changeset''',
-			'args': '<ticket> <changeset>',
-			'level': 'admin', # TODO
-		},
-	]
-}
-
 def plural (a):
 	return '' if a == 1 else 's'
 
-def cmd_checkhg (bot, **rest):
-	hgpoll.force_poll()
-
 def is_dateversion (key):
 	try:
 		datetime.strptime (key, '%y%m%d-%H%M')
@@ -84,14 +55,14 @@
 		try:
 			repo = hgpoll.RepositoriesByName[reponame]
 		except KeyError:
-			command_error ('''unknown repository %s''' % reponame)
+			modulecore.command_error ('''unknown repository %s''' % reponame)
 
 	# Possibly we're passed a date version instead. Try find the node for this.
 	if is_dateversion (node):
 		node = db.find_commit_by_dateversion (node)
 
 		if node == None:
-			command_error ('''couldn't find changeset for date %s''' % node)
+			modulecore.command_error ('''couldn't find changeset for date %s''' % node)
 			return
 
 		node = node[0:7]
@@ -100,7 +71,7 @@
 
 	if repo == None:
 		if not noderepos:
-			command_error ('''couldn't find changeset %s''' % node)
+			modulecore.command_error ('''couldn't find changeset %s''' % node)
 
 		repo = noderepos[0]
 
@@ -128,7 +99,13 @@
 			if match:
 				return match.group (1)
 
-def cmd_cset (bot, args, reply, **rest):
+@modulecore.irc_command (level='admin')
+def checkhg (bot, **rest):
+	'''Polls the zandronum repositories for updates'''
+	hgpoll.force_poll()
+
+@modulecore.irc_command (args='<key>')
+def cset (bot, args, reply, **rest):
 	node, repo = resolve_node (args['key'])
 	commit = repo.get_commit_data (rev=node,
 		node='node|short',
@@ -196,5 +173,6 @@
 
 	reply ('url: %s/commits/%s' % (repo.url, commit['node']))
 
-def cmd_resolves (bot, args, **rest):
-	hgpoll.announce_ticket_resolved (args['ticket'], args['changeset'])
\ No newline at end of file
+@modulecore.irc_command (args='<ticket> <changeset>', level='admin')
+def resolves (bot, args, **rest):
+	hgpoll.announce_ticket_resolved (args['ticket'], args['changeset'], HgCommitsDatabase())
\ No newline at end of file
--- a/mod_util.py	Sun Aug 16 23:30:11 2015 +0300
+++ b/mod_util.py	Mon Aug 17 02:05:16 2015 +0300
@@ -35,82 +35,9 @@
 import calc
 import urllib.parse
 
-ModuleData = {
-	'commands':
-	[
-		{
-			'name': 'convert',
-			'description': 'Performs numeric conversion',
-			'args': '<value> as <valuetype>',
-			'level': 'normal',
-		},
-		
-		{
-			'name': 'ud',
-			'description': 'Looks up a term in urban dictionary',
-			'args': '<term...>',
-			'level': 'normal',
-		},
-
-		{
-			'name': 'commands',
-			'description': 'Lists commands available to the calling user',
-			'args': None,
-			'level': 'normal',
-		},
-
-		{
-			'name': 'help',
-			'description': 'Prints help about a given command',
-			'args': '<command>',
-			'level': 'normal',
-		},
-
-		{
-			'name': 'calc',
-			'description': 'Calculates a mathematical expression using apcalc',
-			'args': '<expression...>',
-			'level': 'normal',
-		},
-
-		{
-			'name': 'calcfunctions',
-			'description': 'Lists the functions supported by .calc',
-			'args': None,
-			'level': 'normal',
-		},
-
-		{
-			'name': 'more',
-			'description': 'Prints subsequent command result pages',
-			'args': None,
-			'level': 'normal',
-		},
-
-		{
-			'name': 'yes',
-			'description': 'Confirms the previous command',
-			'args': None,
-			'level': 'normal',
-		},
-
-		{
-			'name': 'no',
-			'description': 'Unconfirms the previous command',
-			'args': None,
-			'level': 'normal',
-		},
-
-		{
-			'name': 'bitly',
-			'description': 'Shortens a link using bit.ly',
-			'args': '<link>',
-			'level': 'normal'
-		},
-	]
-}
-
-def cmd_convert (bot, args, reply, error, **rest):
+@modulecore.irc_command (args='<value> as <valuetype>')
+def convert (bot, args, reply, error, **rest):
+	'''Performs numeric conversion.'''
 	try:
 		value = float (args['value'])
 	except Exception as e:
@@ -143,7 +70,9 @@
 	error ('unknown valuetype %s, expected one of: degrees, radians (angle conversion), ' +
 		'celsius, fahrenheit (temperature conversion)' % valuetype)
 
-def cmd_ud (bot, args, reply, error, **rest):
+@modulecore.irc_command (args='<term...>')
+def ud (bot, args, reply, error, **rest):
+	'''Looks up a term in urban dictionary.'''
 	try:
 		url = 'http://api.urbandictionary.com/v0/define?term=%s' % (args['term'].replace (' ', '%20'))
 		response = utility.read_url (url)
@@ -163,7 +92,9 @@
 	except Exception as e:
 		error ('Urban dictionary lookup failed: %s' % e)
 
-def cmd_commands (bot, reply, ident, host, **rest):
+@modulecore.irc_command()
+def commands (bot, reply, ident, host, **rest):
+	'''Lists commands available to the calling user.'''
 	commandlist = modulecore.get_available_commands (ident, host)
 	partitioned=[]
 
@@ -174,7 +105,9 @@
 	for part in partitioned:
 		reply ('\002Available commands\002: %s' % (", ".join (part)))
 
-def cmd_help (bot, reply, ident, host, args, error, **rest):
+@modulecore.irc_command (args='<command>')
+def help (bot, reply, ident, host, args, error, **rest):
+	'''Prints help about a given command.'''
 	cmd = modulecore.get_command_by_name (args['command'])
 
 	if not cmd:
@@ -185,28 +118,40 @@
 
 	reply ('%s %s: %s' % (cmd['name'], cmd['args'], cmd['description']))
 
-def cmd_calcfunctions (bot, reply, **rest):
+@modulecore.irc_command()
+def calcfunctions (bot, reply, **rest):
+	'''Lists the functions supported by .calc.'''
 	reply ('Available functions for .calc: %s' % \
 		', '.join (sorted ([name for name, data in calc.Functions.items()])))
 
-def cmd_calc (bot, reply, args, **rest):
+@modulecore.irc_command (args='<expression...>')
+def calc (bot, reply, args, **rest):
+	'''Calculates a mathematical expression.'''
 	reply (calc.Calculator().calc (args['expression']))
 
-def cmd_more (commandObject, **rest):
+@modulecore.irc_command()
+def more (commandObject, **rest):
+	'''Prints subsequent command result pages.'''
 	modulecore.print_responses (commandObject)
 
-def cmd_yes (**k):
+@modulecore.irc_command()
+def yes (**k):
+	'''Confirms the previous command.'''
 	modulecore.confirm (k, True)
 
-def cmd_no (**k):
+@modulecore.irc_command()
+def no (**k):
+	'''Unconfirms the previous command.'''
 	modulecore.confirm (k, False)
 
-def cmd_bitly (reply, args, **k):
+@modulecore.irc_command (args='<link...>')
+def bitly (reply, args, **k):
+	'''Shortens a link using bit.ly.'''
 	reply ('Result: %s' % utility.shorten_link (args['link']))
 
 @modulecore.irc_command (args='<command...>')
 def py (reply, args, **rest):
-	''' Evaluates the given Python string using appspot.com '''
+	'''Evaluates the given Python string using appspot.com.'''
 	url = 'http://eval.appspot.com/eval?statement=' + urllib.parse.quote (args['command'])
 	result = utility.read_url (url, timeout=15).splitlines()
 
--- a/modulecore.py	Sun Aug 16 23:30:11 2015 +0300
+++ b/modulecore.py	Mon Aug 17 02:05:16 2015 +0300
@@ -63,8 +63,12 @@
 		module = __import__ (fn)
 		Modules[fn] = module
 
-		for cmd in module.ModuleData['commands']:
-			install_command (cmd, module)
+		if not hasattr (module, 'ModuleData'):
+			continue # No manifest
+
+		if 'commands' in module.ModuleData:
+			for cmd in module.ModuleData['commands']:
+				install_command (cmd, module)
 
 		if 'hooks' in module.ModuleData:
 			for key, hooks in module.ModuleData['hooks'].items():

mercurial