From 2eba17dfbd9a19c1abd6954531b45ed12fa76db9 Mon Sep 17 00:00:00 2001 From: gau1991 Date: Wed, 10 Jun 2015 17:58:09 +0530 Subject: [PATCH 1/4] First try to install plugin using command ee install --- ee/cli/plugins/plugin.py | 82 ++++++++++++++++++++++++++++++++++++++++ ee/core/api_return.py | 12 ++++++ setup.py | 1 + 3 files changed, 95 insertions(+) create mode 100644 ee/cli/plugins/plugin.py create mode 100644 ee/core/api_return.py diff --git a/ee/cli/plugins/plugin.py b/ee/cli/plugins/plugin.py new file mode 100644 index 00000000..e65f4b03 --- /dev/null +++ b/ee/cli/plugins/plugin.py @@ -0,0 +1,82 @@ +"""EasyEngine plugin manager""" +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', '-q', 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 b658791c..874deb35 100644 --- a/setup.py +++ b/setup.py @@ -83,6 +83,7 @@ setup(name='ee', 'psutil', 'sh', 'sqlalchemy', + 'pip', ], data_files=[('/etc/ee', ['config/ee.conf']), ('/etc/ee/plugins.d', conf), From c3bed1778faa473212d1c92529f8284d3a2224c7 Mon Sep 17 00:00:00 2001 From: gau1991 Date: Wed, 10 Jun 2015 18:09:50 +0530 Subject: [PATCH 2/4] Added plugin conf file to enable plugin --- ee/cli/plugins/plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ee/cli/plugins/plugin.py b/ee/cli/plugins/plugin.py index e65f4b03..06a6930e 100644 --- a/ee/cli/plugins/plugin.py +++ b/ee/cli/plugins/plugin.py @@ -34,7 +34,7 @@ class EEPluginController(CementBaseController): .format(self.app.pargs.plugin_name)) pinfo = api_return(url) try: - pip.main(['install', '-q', pinfo[0].['file']]) + pip.main(['install', pinfo[0]['file']]) except Exception as e: return False From 19ca393adbf371744adca8c76903e3d50323c823 Mon Sep 17 00:00:00 2001 From: gau1991 Date: Wed, 10 Jun 2015 18:09:58 +0530 Subject: [PATCH 3/4] Added plugin conf file to enable plugin --- config/plugins.d/plugin.conf | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 config/plugins.d/plugin.conf 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 From 2db003c02a8abda59a42dbae2257996fa004712f Mon Sep 17 00:00:00 2001 From: gau1991 Date: Wed, 10 Jun 2015 18:11:58 +0530 Subject: [PATCH 4/4] Addded cement dependencies for plugin --- ee/cli/plugins/plugin.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ee/cli/plugins/plugin.py b/ee/cli/plugins/plugin.py index 06a6930e..ef30d6ae 100644 --- a/ee/cli/plugins/plugin.py +++ b/ee/cli/plugins/plugin.py @@ -1,4 +1,6 @@ """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