From 41581dac2f0cd25bd5a45bd2e05c0cb83edd5a53 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Wed, 31 Jul 2013 19:08:49 +0200 Subject: [PATCH] Aka: Add @importAliasDatabase command. --- plugins/Aka/plugin.py | 24 ++++++++++++++++++++++++ plugins/Aka/test.py | 31 ++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/plugins/Aka/plugin.py b/plugins/Aka/plugin.py index 02ca4e2e7..dc0a5aaf0 100644 --- a/plugins/Aka/plugin.py +++ b/plugins/Aka/plugin.py @@ -454,6 +454,30 @@ class Aka(callbacks.Plugin): 'channel': 'somethingWithoutSpaces', }), 'user', 'something']) + def importaliasdatabase(self, irc, msg, args): + """takes no arguments + + Imports the Alias database into Aka's, and clean the former.""" + alias_plugin = irc.getCallback('Alias') + if alias_plugin is None: + irc.error(_('Alias plugin is not loaded.'), Raise=True) + errors = {} + for (name, (command, locked, func)) in alias_plugin.aliases.items(): + try: + self._add_aka('global', name, command) + except AkaError as e: + errors[name] = e.args[0] + else: + alias_plugin.removeAlias(name) + if errors: + irc.error(format(_('Error occured when importing the %n: %L'), + (len(errors), 'following', 'command'), + map(lambda x:'%s (%s)' % x, errors.items()))) + else: + irc.replySuccess() + importaliasdatabase = wrap(importaliasdatabase, ['owner']) + + Class = Aka diff --git a/plugins/Aka/test.py b/plugins/Aka/test.py index d386ce312..94b873569 100644 --- a/plugins/Aka/test.py +++ b/plugins/Aka/test.py @@ -157,7 +157,7 @@ class AkaChannelTestCase(ChannelPluginTestCase): self.assertRegexp('fact 50', 'more nesting') class AkaTestCase(PluginTestCase): - plugins = ('Aka', 'User') + plugins = ('Aka', 'Alias', 'User', 'Utilities') def testAkaLockedHelp(self): self.assertNotError('register evil_admin foo') @@ -170,4 +170,33 @@ class AkaTestCase(PluginTestCase): self.assertNotError('aka unlock slashdot') self.assertNotRegexp('help slashdot', 'Locked by') + def testAliasImport(self): + self.assertNotError('alias add foo "echo bar"') + self.assertNotError(u'alias add baz "echo café"') + self.assertNotError('aka add qux "echo quux"') + self.assertResponse('alias foo', 'bar') + self.assertResponse('alias baz', 'café') + self.assertRegexp('aka foo', 'there is no command named') + self.assertResponse('aka qux', 'quux') + + self.assertNotError('aka importaliasdatabase') + + self.assertRegexp('alias foo', 'there is no command named') + self.assertResponse('aka foo', 'bar') + self.assertResponse('aka baz', 'café') + self.assertResponse('aka qux', 'quux') + + self.assertNotError('alias add foo "echo test"') + self.assertNotError('alias add spam "echo egg"') + + self.assertRegexp('aka importaliasdatabase', + r'the 1 following command: foo \(This Aka already exists.\)$') + self.assertResponse('aka foo', 'bar') + self.assertResponse('alias foo', 'test') + self.assertRegexp('alias spam', 'there is no command named') + self.assertResponse('aka spam', 'egg') + + + + # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: