mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Persistent renames.
This commit is contained in:
parent
dd7b02fb54
commit
e525e04a42
60
src/Owner.py
60
src/Owner.py
@ -121,6 +121,13 @@ def loadPluginClass(irc, module, register=None):
|
|||||||
public = cb.public
|
public = cb.public
|
||||||
conf.registerPlugin(name, register, public)
|
conf.registerPlugin(name, register, public)
|
||||||
assert not irc.getCallback(name)
|
assert not irc.getCallback(name)
|
||||||
|
try:
|
||||||
|
renames = conf.supybot.commands.renames.get(name)
|
||||||
|
for (name, v) in renames.getValues(fullNames=False):
|
||||||
|
newName = v()
|
||||||
|
renameCommand(cb, name, newName)
|
||||||
|
except registry.NonExistentRegistryEntry, e:
|
||||||
|
pass # The plugin isn't there.
|
||||||
irc.addCallback(cb)
|
irc.addCallback(cb)
|
||||||
return cb
|
return cb
|
||||||
|
|
||||||
@ -133,10 +140,10 @@ conf.supybot.plugins.Owner.register('public', registry.Boolean(True,
|
|||||||
###
|
###
|
||||||
|
|
||||||
conf.registerGroup(conf.supybot.commands, 'defaultPlugins',
|
conf.registerGroup(conf.supybot.commands, 'defaultPlugins',
|
||||||
orderAlphabetically=True)
|
orderAlphabetically=True, help=utils.normalizeWhitespace("""Determines
|
||||||
conf.supybot.commands.defaultPlugins.help = utils.normalizeWhitespace("""
|
what commands have default plugins set, and which plugins are set to
|
||||||
Determines what commands have default plugins set, and which plugins are set to
|
be the default for each of those commands."""))
|
||||||
be the default for each of those commands.""".strip())
|
conf.registerGroup(conf.supybot.commands, 'renames', orderAlphabetically=True)
|
||||||
|
|
||||||
def registerDefaultPlugin(command, plugin):
|
def registerDefaultPlugin(command, plugin):
|
||||||
command = callbacks.canonicalName(command)
|
command = callbacks.canonicalName(command)
|
||||||
@ -145,14 +152,30 @@ def registerDefaultPlugin(command, plugin):
|
|||||||
# This must be set, or the quotes won't be removed.
|
# This must be set, or the quotes won't be removed.
|
||||||
conf.supybot.commands.defaultPlugins.get(command).set(plugin)
|
conf.supybot.commands.defaultPlugins.get(command).set(plugin)
|
||||||
|
|
||||||
registerDefaultPlugin('ignore', 'Admin')
|
def registerRename(plugin, command, newName):
|
||||||
registerDefaultPlugin('unignore', 'Admin')
|
g = conf.registerGroup(conf.supybot.commands.renames, plugin)
|
||||||
registerDefaultPlugin('addcapability', 'Admin')
|
v = conf.registerGlobalValue(g, command, registry.String(newName, ''))
|
||||||
registerDefaultPlugin('removecapability', 'Admin')
|
v.setValue(newName) # In case it was already registered.
|
||||||
|
return v
|
||||||
|
|
||||||
|
def renameCommand(cb, name, newName):
|
||||||
|
assert not hasattr(cb, newName), 'Cannot rename over existing attributes.'
|
||||||
|
assert newName == callbacks.canonicalName(newName), \
|
||||||
|
'newName must already be canonicalized.'
|
||||||
|
if name != newName:
|
||||||
|
method = getattr(cb.__class__, name)
|
||||||
|
setattr(cb.__class__, newName, method)
|
||||||
|
delattr(cb.__class__, name)
|
||||||
|
|
||||||
|
|
||||||
registerDefaultPlugin('list', 'Misc')
|
registerDefaultPlugin('list', 'Misc')
|
||||||
registerDefaultPlugin('help', 'Misc')
|
registerDefaultPlugin('help', 'Misc')
|
||||||
|
registerDefaultPlugin('ignore', 'Admin')
|
||||||
registerDefaultPlugin('reload', 'Owner')
|
registerDefaultPlugin('reload', 'Owner')
|
||||||
|
registerDefaultPlugin('unignore', 'Admin')
|
||||||
registerDefaultPlugin('capabilities', 'User')
|
registerDefaultPlugin('capabilities', 'User')
|
||||||
|
registerDefaultPlugin('addcapability', 'Admin')
|
||||||
|
registerDefaultPlugin('removecapability', 'Admin')
|
||||||
|
|
||||||
class holder(object):
|
class holder(object):
|
||||||
pass
|
pass
|
||||||
@ -778,16 +801,29 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
|
|||||||
if cb is None:
|
if cb is None:
|
||||||
irc.errorInvalid('plugin', plugin, Raise=True)
|
irc.errorInvalid('plugin', plugin, Raise=True)
|
||||||
if not cb.isCommand(command):
|
if not cb.isCommand(command):
|
||||||
irc.errorInvalid('command in the %s plugin'%plugin,name,Raise=True)
|
what = 'command in the %s plugin' % plugin
|
||||||
|
irc.errorInvalid(what, name, Raise=True)
|
||||||
if hasattr(cb, name):
|
if hasattr(cb, name):
|
||||||
irc.error('The %s plugin already has an attribute named %s.' %
|
irc.error('The %s plugin already has an attribute named %s.' %
|
||||||
(plugin, name))
|
(plugin, name))
|
||||||
return
|
return
|
||||||
method = getattr(cb.__class__, command)
|
registerRename(cb.name(), command, name)
|
||||||
setattr(cb.__class__, name, method)
|
renameCommand(cb, command, newName)
|
||||||
delattr(cb.__class__, command)
|
|
||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
|
|
||||||
|
def unrename(self, irc, msg, args):
|
||||||
|
"""<plugin>
|
||||||
|
|
||||||
|
Removes all renames in <plugin>. The plugin will be reloaded after
|
||||||
|
this command is run.
|
||||||
|
"""
|
||||||
|
plugin = privmsgs.getArgs(args)
|
||||||
|
try:
|
||||||
|
conf.supybot.commands.renames.unregister(plugin)
|
||||||
|
except registry.NonExistentRegistryEntry:
|
||||||
|
irc.errorInvalid('plugin', plugin, Raise=True)
|
||||||
|
self.reload(irc, msg, args) # This makes the replySuccess.
|
||||||
|
|
||||||
def _connect(self, network, serverPort=None):
|
def _connect(self, network, serverPort=None):
|
||||||
try:
|
try:
|
||||||
group = conf.supybot.networks.get(network)
|
group = conf.supybot.networks.get(network)
|
||||||
|
@ -107,6 +107,20 @@ class OwnerTestCase(PluginTestCase, PluginDocumentation):
|
|||||||
self.assertNotError('disable Foo')
|
self.assertNotError('disable Foo')
|
||||||
self.assertNotError('enable foo')
|
self.assertNotError('enable foo')
|
||||||
|
|
||||||
|
def testRename(self):
|
||||||
|
self.assertError('rename admin ignore IGNORE')
|
||||||
|
self.assertError('rename admin ignore ig-nore')
|
||||||
|
self.assertNotError('rename admin removecapability rmcap')
|
||||||
|
self.assertNotRegexp('list admin', 'removecapability')
|
||||||
|
self.assertRegexp('list admin', 'rmcap')
|
||||||
|
self.assertNotError('reload admin')
|
||||||
|
self.assertNotRegexp('list admin', 'removecapability')
|
||||||
|
self.assertRegexp('list admin', 'rmcap')
|
||||||
|
self.assertNotError('unrename admin')
|
||||||
|
self.assertRegexp('list admin', 'removecapability')
|
||||||
|
self.assertNotRegexp('list admin', 'rmcap')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class FunctionsTestCase(SupyTestCase):
|
class FunctionsTestCase(SupyTestCase):
|
||||||
def testLoadPluginModule(self):
|
def testLoadPluginModule(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user