harshadyeola
10 years ago
4 changed files with 102 additions and 0 deletions
@ -0,0 +1,5 @@ |
|||||
|
### Example Plugin Configuration for EasyEngine |
||||
|
|
||||
|
[plugin] |
||||
|
|
||||
|
enable_plugin = true |
@ -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) |
@ -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 |
Loading…
Reference in new issue