mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Added deprecation support.
This commit is contained in:
parent
11908f5f2c
commit
69f8c40119
@ -33,6 +33,8 @@
|
|||||||
A plugin that tries to emulate Infobot somewhat faithfully.
|
A plugin that tries to emulate Infobot somewhat faithfully.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
deprecated = True
|
||||||
|
|
||||||
__revision__ = "$Id$"
|
__revision__ = "$Id$"
|
||||||
|
|
||||||
import plugins
|
import plugins
|
||||||
|
@ -34,6 +34,8 @@ Does various (well, only one at the moment :)) things with the Internet Movie
|
|||||||
Database.
|
Database.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
deprecated = True
|
||||||
|
|
||||||
__revision__ = "$Id$"
|
__revision__ = "$Id$"
|
||||||
|
|
||||||
import plugins
|
import plugins
|
||||||
|
32
src/Owner.py
32
src/Owner.py
@ -43,6 +43,7 @@ import os
|
|||||||
import imp
|
import imp
|
||||||
import sys
|
import sys
|
||||||
import sets
|
import sets
|
||||||
|
import getopt
|
||||||
import linecache
|
import linecache
|
||||||
|
|
||||||
import log
|
import log
|
||||||
@ -56,13 +57,16 @@ import drivers
|
|||||||
import privmsgs
|
import privmsgs
|
||||||
import callbacks
|
import callbacks
|
||||||
|
|
||||||
def loadPluginModule(name):
|
class Deprecated(ImportError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def loadPluginModule(name, ignoreDeprecation=False):
|
||||||
"""Loads (and returns) the module for the plugin with the given name."""
|
"""Loads (and returns) the module for the plugin with the given name."""
|
||||||
files = []
|
files = []
|
||||||
for dir in conf.pluginDirs:
|
for dir in conf.pluginDirs:
|
||||||
try:
|
try:
|
||||||
files.extend(os.listdir(dir))
|
files.extend(os.listdir(dir))
|
||||||
except EnvironmentError:
|
except EnvironmentError: # OSError, IOError superclass.
|
||||||
log.warning('Invalid plugin directory: %s', dir)
|
log.warning('Invalid plugin directory: %s', dir)
|
||||||
loweredFiles = map(str.lower, files)
|
loweredFiles = map(str.lower, files)
|
||||||
try:
|
try:
|
||||||
@ -72,6 +76,11 @@ def loadPluginModule(name):
|
|||||||
pass
|
pass
|
||||||
moduleInfo = imp.find_module(name, conf.pluginDirs)
|
moduleInfo = imp.find_module(name, conf.pluginDirs)
|
||||||
module = imp.load_module(name, *moduleInfo)
|
module = imp.load_module(name, *moduleInfo)
|
||||||
|
if 'deprecated' in module.__dict__ and module.deprecated:
|
||||||
|
if ignoreDeprecation:
|
||||||
|
log.warning('Deprecated plugin loaded: %s', name)
|
||||||
|
else:
|
||||||
|
raise Deprecated, 'Attempted to load deprecated plugin %s' % name
|
||||||
if module.__name__ in sys.modules:
|
if module.__name__ in sys.modules:
|
||||||
sys.modules[module.__name__] = module
|
sys.modules[module.__name__] = module
|
||||||
linecache.checkcache()
|
linecache.checkcache()
|
||||||
@ -345,19 +354,30 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
|
|||||||
irc.reply('%s collected.' % utils.nItems('object', collected))
|
irc.reply('%s collected.' % utils.nItems('object', collected))
|
||||||
|
|
||||||
def load(self, irc, msg, args):
|
def load(self, irc, msg, args):
|
||||||
"""<plugin>
|
"""[--deprecated] <plugin>
|
||||||
|
|
||||||
Loads the plugin <plugin> from any of the directories in
|
Loads the plugin <plugin> from any of the directories in
|
||||||
conf.pluginDirs; usually this includes the main installed directory
|
conf.pluginDirs; usually this includes the main installed directory
|
||||||
and 'plugins' in the current directory. Be sure not to have ".py" at
|
and 'plugins' in the current directory. --deprecated is necessary
|
||||||
the end.
|
if you wish to load deprecated plugins.
|
||||||
"""
|
"""
|
||||||
|
(optlist, args) = getopt.getopt(args, '', ['deprecated'])
|
||||||
|
ignoreDeprecation = False
|
||||||
|
for (option, argument) in optlist:
|
||||||
|
if option == '--deprecated':
|
||||||
|
ignoreDeprecation = True
|
||||||
name = privmsgs.getArgs(args)
|
name = privmsgs.getArgs(args)
|
||||||
|
if name.endswith('.py'):
|
||||||
|
name = name[:-3]
|
||||||
if irc.getCallback(name):
|
if irc.getCallback(name):
|
||||||
irc.error('That module is already loaded.')
|
irc.error('That module is already loaded.')
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
module = loadPluginModule(name)
|
module = loadPluginModule(name, ignoreDeprecation)
|
||||||
|
except Deprecated:
|
||||||
|
irc.error('Plugin %r is deprecated. '
|
||||||
|
'Use --deprecated to force it to load.')
|
||||||
|
return
|
||||||
except ImportError, e:
|
except ImportError, e:
|
||||||
if name in str(e):
|
if name in str(e):
|
||||||
irc.error('No plugin %s exists.' % name)
|
irc.error('No plugin %s exists.' % name)
|
||||||
|
Loading…
Reference in New Issue
Block a user