diff --git a/config/ee.conf b/config/ee.conf index 7472f571..ef568c5f 100644 --- a/config/ee.conf +++ b/config/ee.conf @@ -67,3 +67,10 @@ password = ### EMail for WordPress sites email = + +[update] + +### If enabled, load a plugin named `update` either from the Python module +### `ee.cli.plugins.example` or from the file path +### `/var/lib/ee/plugins/example.py` +enable_plugin = true diff --git a/ee/cli/plugins/update.py b/ee/cli/plugins/update.py new file mode 100644 index 00000000..b039afe7 --- /dev/null +++ b/ee/cli/plugins/update.py @@ -0,0 +1,45 @@ +from cement.core.controller import CementBaseController, expose +from cement.core import handler, hook +from ee.core.download import EEDownload +from ee.core.logging import Log +import time +import os + + +def ee_update_hook(app): + # do something with the ``app`` object here. + pass + + +class EEUpdateController(CementBaseController): + class Meta: + label = 'ee_update' + stacked_on = 'base' + aliases = ['update'] + aliases_only = True + stacked_type = 'nested' + description = ('update EasyEngine to latest version') + usage = "ee update" + + @expose(hide=True) + def default(self): + filename = "eeupdate" + time.strftime("%Y%m%d-%H%M%S") + EEDownload.download(self, [["http://rt.cx/ee", + "/tmp/{0}".format(filename), + "update script"]]) + try: + Log.info(self, "updating EasyEngine, please wait ...") + os.system("bash /tmp/{0}".format(filename)) + except OSError as e: + Log.debug(self, str(e)) + Log.error(self, "EasyEngine update failed !") + except Exception as e: + Log.debug(self, str(e)) + Log.error(self, "EasyEngine update failed !") + + +def load(app): + # register the plugin class.. this only happens if the plugin is enabled + handler.register(EEUpdateController) + # register a hook (function) to run after arguments are parsed. + hook.register('post_argument_parsing', ee_update_hook)