Check if plugin as a parser command before adding it into the OrderedList.
Indeed some plugins may not need to define one.
This commit is contained in:
parent
fa836aaad9
commit
f29f1a96b5
@ -38,6 +38,7 @@ def execute(raw_args = sys.argv):
|
|||||||
# Extend with plugin commands
|
# Extend with plugin commands
|
||||||
plugins.load_plugins(ui, config.plugins.split())
|
plugins.load_plugins(ui, config.plugins.split())
|
||||||
for p in plugins.get_plugins().values():
|
for p in plugins.get_plugins().values():
|
||||||
|
if getattr(p, 'parser') and getattr(p, 'command'):
|
||||||
cmds.update(collections.OrderedDict([(p.name, p)]))
|
cmds.update(collections.OrderedDict([(p.name, p)]))
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="research papers repository")
|
parser = argparse.ArgumentParser(description="research papers repository")
|
||||||
|
@ -12,11 +12,10 @@ class PapersPlugin(object):
|
|||||||
functionality by defining a subclass of PapersPlugin and overriding
|
functionality by defining a subclass of PapersPlugin and overriding
|
||||||
the abstract methods defined here.
|
the abstract methods defined here.
|
||||||
"""
|
"""
|
||||||
def __init__(self, ui):
|
def __init__(self):
|
||||||
"""Perform one-time plugin setup.
|
"""Perform one-time plugin setup.
|
||||||
"""
|
"""
|
||||||
self.name = self.__module__.split('.')[-1]
|
self.name = self.__module__.split('.')[-1]
|
||||||
self.ui = ui
|
|
||||||
|
|
||||||
#ui and given again to stay consistent with the core papers cmd.
|
#ui and given again to stay consistent with the core papers cmd.
|
||||||
#two options:
|
#two options:
|
||||||
@ -25,7 +24,7 @@ class PapersPlugin(object):
|
|||||||
#this may end up with a lot of function with config/ui in argument
|
#this may end up with a lot of function with config/ui in argument
|
||||||
#or just keep it that way...
|
#or just keep it that way...
|
||||||
def parser(self, subparsers):
|
def parser(self, subparsers):
|
||||||
""" Should retrun the parser with plugins specific command.
|
""" Should return the parser with plugins specific command.
|
||||||
This is a basic example
|
This is a basic example
|
||||||
"""
|
"""
|
||||||
parser = subparsers.add_parser(self.name, help="echo string in argument")
|
parser = subparsers.add_parser(self.name, help="echo string in argument")
|
||||||
@ -59,7 +58,7 @@ def load_plugins(ui, names):
|
|||||||
"""
|
"""
|
||||||
for name in names:
|
for name in names:
|
||||||
modname = '%s.%s.%s.%s' % ('papers', PLUGIN_NAMESPACE, name, name)
|
modname = '%s.%s.%s.%s' % ('papers', PLUGIN_NAMESPACE, name, name)
|
||||||
try:
|
#try:
|
||||||
try:
|
try:
|
||||||
namespace = importlib.import_module(modname)
|
namespace = importlib.import_module(modname)
|
||||||
except ImportError as exc:
|
except ImportError as exc:
|
||||||
@ -73,10 +72,10 @@ def load_plugins(ui, names):
|
|||||||
if isinstance(obj, type) and issubclass(obj, PapersPlugin) \
|
if isinstance(obj, type) and issubclass(obj, PapersPlugin) \
|
||||||
and obj != PapersPlugin:
|
and obj != PapersPlugin:
|
||||||
_classes.append(obj)
|
_classes.append(obj)
|
||||||
_instances[obj] = obj(ui)
|
_instances[obj] = obj()
|
||||||
|
|
||||||
except:
|
#except:
|
||||||
ui.warning('error loading plugin {}'.format(name))
|
# ui.warning('error loading plugin {}'.format(name))
|
||||||
|
|
||||||
|
|
||||||
def get_plugins():
|
def get_plugins():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user