Added docstrings to loader
This commit is contained in:
parent
da84c64012
commit
e8ba002b23
1 changed files with 12 additions and 5 deletions
|
@ -42,10 +42,12 @@ class PluginLoader(object):
|
||||||
|
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
|
"""shuts down the plugin reloader"""
|
||||||
self.observer.stop()
|
self.observer.stop()
|
||||||
|
|
||||||
|
|
||||||
def load_all(self):
|
def load_all(self):
|
||||||
|
"""loads plugins from all files in the plugins folder"""
|
||||||
files = set(glob.glob(os.path.join(self.path, '*.py')))
|
files = set(glob.glob(os.path.join(self.path, '*.py')))
|
||||||
for f in files:
|
for f in files:
|
||||||
self.load_file(f, loaded_all=True)
|
self.load_file(f, loaded_all=True)
|
||||||
|
@ -53,6 +55,7 @@ class PluginLoader(object):
|
||||||
|
|
||||||
|
|
||||||
def load_file(self, path, loaded_all=False):
|
def load_file(self, path, loaded_all=False):
|
||||||
|
"""loads (or reloads) all valid plugins from a specified file"""
|
||||||
filename = os.path.basename(path)
|
filename = os.path.basename(path)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -88,6 +91,7 @@ class PluginLoader(object):
|
||||||
|
|
||||||
|
|
||||||
def unload_file(self, path):
|
def unload_file(self, path):
|
||||||
|
"""unloads all loaded plugins from a specified file"""
|
||||||
filename = os.path.basename(path)
|
filename = os.path.basename(path)
|
||||||
self.bot.logger.info("Unloading plugins from: {}".format(filename))
|
self.bot.logger.info("Unloading plugins from: {}".format(filename))
|
||||||
|
|
||||||
|
@ -99,20 +103,23 @@ class PluginLoader(object):
|
||||||
main.handler.stop()
|
main.handler.stop()
|
||||||
del self.bot.threads[func]
|
del self.bot.threads[func]
|
||||||
|
|
||||||
|
self.rebuild()
|
||||||
|
|
||||||
|
|
||||||
def rebuild(self):
|
def rebuild(self):
|
||||||
|
"""rebuilds the cloudbot command and event hook lists"""
|
||||||
self.bot.commands = {}
|
self.bot.commands = {}
|
||||||
for plug in self.bot.plugins['command']:
|
for plugin in self.bot.plugins['command']:
|
||||||
name = plug[1]['name'].lower()
|
name = plugin[1]['name'].lower()
|
||||||
if not re.match(r'^\w+$', name):
|
if not re.match(r'^\w+$', name):
|
||||||
print '### ERROR: invalid command name "{}" ({})'.format(name, format_plug(plug))
|
self.bot.logger.error('Invalid command name: "{}"" ({})'.format(name, format_plug(plugin)))
|
||||||
continue
|
continue
|
||||||
if name in self.bot.commands:
|
if name in self.bot.commands:
|
||||||
print "### ERROR: command '{}' already registered ({}, {})".format(name,
|
print "### ERROR: command '{}' already registered ({}, {})".format(name,
|
||||||
format_plug(self.bot.commands[name]),
|
format_plug(self.bot.commands[name]),
|
||||||
format_plug(plug))
|
format_plug(plugin))
|
||||||
continue
|
continue
|
||||||
self.bot.commands[name] = plug
|
self.bot.commands[name] = plugin
|
||||||
|
|
||||||
self.bot.events = collections.defaultdict(list)
|
self.bot.events = collections.defaultdict(list)
|
||||||
for func, args in self.bot.plugins['event']:
|
for func, args in self.bot.plugins['event']:
|
||||||
|
|
Reference in a new issue