Skip to content

Commit

Permalink
better setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Arjun Thekkumadathil authored and Arjun Thekkumadathil committed Jul 4, 2017
1 parent 31233d1 commit f102528
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
9 changes: 6 additions & 3 deletions example_config/plugins.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
plugin_path: D:/development/pyplug/example_plugins
plugin_path: D:\development\pyplug\example_plugins
plugin_list:
plugin_a:
enable: true
enable: false
args:
myarg: blah
jack: this is jack
jack: this is jack

plugin_b:
enable: true
Binary file removed example_plugins/plugin_a.pyc
Binary file not shown.
21 changes: 14 additions & 7 deletions src/pyplug.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,28 @@ def __init__(self, config=None):
self.setup()

def setup(self):
sys.path.append(os.path.abspath(self.plugin_config['plugin_path']))

try:
sys.path.append(os.path.abspath(self.plugin_config['plugin_path']))
except KeyError:
pass

def import_plugins(self, plugin_name):
m = __import__(plugin_name)
return m

def run_plugin(self, plugin_name, args_dict):
def run_plugin(self, plugin_name):
args = {}
plug = self.import_plugins(plugin_name)
plug.main(**args_dict)
try:
args = self.plugin_list[plugin_name]['args']
except KeyError:
pass
if self.plugin_list[plugin_name]['enable']:
plug.main(**args)

def run_all_plugins(self):
for i in self.plugin_list:
self.run_plugin(i, self.plugin_list[i]['args'])
for plug in self.plugin_list:
self.run_plugin(plug)

@property
def plugin_config(self):
Expand All @@ -30,4 +38,3 @@ def plugin_config(self):
@property
def plugin_list(self):
return self._plugin_config['plugin_list']

0 comments on commit f102528

Please sign in to comment.