|
| 1 | +from cement.core.controller import CementBaseController, expose |
| 2 | +from cement.core import handler, hook |
| 3 | +from ee.core.download import EEDownload |
| 4 | +from ee.core.logging import Log |
| 5 | +import time |
| 6 | +import os |
| 7 | + |
| 8 | + |
| 9 | +def ee_update_hook(app): |
| 10 | + # do something with the ``app`` object here. |
| 11 | + pass |
| 12 | + |
| 13 | + |
| 14 | +class EEUpdateController(CementBaseController): |
| 15 | + class Meta: |
| 16 | + label = 'ee_update' |
| 17 | + stacked_on = 'base' |
| 18 | + aliases = ['update'] |
| 19 | + aliases_only = True |
| 20 | + stacked_type = 'nested' |
| 21 | + description = ('update EasyEngine to latest version') |
| 22 | + usage = "ee update" |
| 23 | + |
| 24 | + @expose(hide=True) |
| 25 | + def default(self): |
| 26 | + filename = "eeupdate" + time.strftime("%Y%m%d-%H%M%S") |
| 27 | + EEDownload.download(self, [["http://rt.cx/eeup", |
| 28 | + "/tmp/{0}".format(filename), |
| 29 | + "update script"]]) |
| 30 | + try: |
| 31 | + Log.info(self, "updating EasyEngine, please wait ...") |
| 32 | + os.system("bash /tmp/{0}".format(filename)) |
| 33 | + except OSError as e: |
| 34 | + Log.debug(self, str(e)) |
| 35 | + Log.error(self, "EasyEngine update failed !") |
| 36 | + except Exception as e: |
| 37 | + Log.debug(self, str(e)) |
| 38 | + Log.error(self, "EasyEngine update failed !") |
| 39 | + |
| 40 | + |
| 41 | +def load(app): |
| 42 | + # register the plugin class.. this only happens if the plugin is enabled |
| 43 | + handler.register(EEUpdateController) |
| 44 | + # register a hook (function) to run after arguments are parsed. |
| 45 | + hook.register('post_argument_parsing', ee_update_hook) |
0 commit comments