diff --git a/config/plugins.d/plugin.conf b/config/plugins.d/plugin.conf new file mode 100644 index 00000000..338a92f7 --- /dev/null +++ b/config/plugins.d/plugin.conf @@ -0,0 +1,5 @@ +### Example Plugin Configuration for EasyEngine + +[plugin] + +enable_plugin = true diff --git a/ee/cli/plugins/plugin.py b/ee/cli/plugins/plugin.py new file mode 100644 index 00000000..ef30d6ae --- /dev/null +++ b/ee/cli/plugins/plugin.py @@ -0,0 +1,84 @@ +"""EasyEngine plugin manager""" +from cement.core.controller import CementBaseController, expose +from cement.core import handler, hook +from ee.core.api_return import api_return +import pip + + +def ee_plugin_hook(app): + # do something with the ``app`` object here. + pass + + +class EEPluginController(CementBaseController): + class Meta: + label = 'plugin' + stacked_on = 'base' + stacked_type = 'nested' + description = 'plugin manager for EasyEngine' + arguments = [ + (['-y', '--yes'], + dict(help='Default yes action', action='store_true')), + (['plugin_name'], + dict(help='Plugin name to install/uninstall/search/upgrade', + nargs='?')), + ] + usage = "ee plugin (command) [options]" + + @expose(hide=True) + def default(self): + """default action of ee plugin command""" + self.app.args.print_help() + + @expose(help="Install plugins") + def install(self): + url = ("http://epm.rtcamp.net:3000/info?name={0}" + .format(self.app.pargs.plugin_name)) + pinfo = api_return(url) + try: + pip.main(['install', pinfo[0]['file']]) + except Exception as e: + return False + + @expose(help="Uninstall plugin") + def uninstall(self): + """Start Uninstallation of plugins""" + pass + + @expose(help="List installed plugins") + def list(self): + """List installed plugins""" + pass + + @expose(help="Search plugins") + def search(self): + """Search plugins into EPM respository""" + pass + + @expose(help="Upgrade installed plugins") + def upgrade(self): + """Upgrade installed plugins""" + pass + + @expose(help="Display package information") + def info(self): + """Display package information""" + pass + + @expose(help="Enable installed plugin") + def enable(self): + """Enable installed plugin""" + pass + + @expose(help="Disable installed plugin") + def disable(self): + """Disable installed plugin""" + pass + + +def load(app): + # register the plugin class.. this only happens if the plugin is enabled + handler.register(EEPluginController) + + # register a hook (function) to run after arguments are parsed. + hook.register('post_argument_parsing', ee_plugin_hook) diff --git a/ee/core/api_return.py b/ee/core/api_return.py new file mode 100644 index 00000000..a738cff6 --- /dev/null +++ b/ee/core/api_return.py @@ -0,0 +1,12 @@ +"""EasyEngine JSON to Dict""" +from urllib.request import urlopen +import json + + +def api_return(url): + try: + response = urlopen(url) + data = str(response.read().decode('utf-8')) + return json.loads(data) + except Exception as e: + return False diff --git a/setup.py b/setup.py index 27c5b687..f7884ae7 100644 --- a/setup.py +++ b/setup.py @@ -84,6 +84,7 @@ setup(name='ee', 'psutil', 'sh', 'sqlalchemy', + 'pip', ], data_files=[('/etc/ee', ['config/ee.conf']), ('/etc/ee/plugins.d', conf),