Files
WPIQ/wo/cli/plugins/update.py

56 lines
1.9 KiB
Python
Raw Normal View History

2019-04-26 21:30:46 +02:00
import os
import time
2018-11-13 21:55:59 +01:00
from cement.core import handler, hook
2019-04-26 21:30:46 +02:00
from cement.core.controller import CementBaseController, expose
2018-11-13 21:55:59 +01:00
from wo.core.download import WODownload
from wo.core.logging import Log
def wo_update_hook(app):
pass
class WOUpdateController(CementBaseController):
class Meta:
label = 'wo_update'
stacked_on = 'base'
aliases = ['update']
aliases_only = True
stacked_type = 'nested'
description = ('update WordOps to latest version')
arguments = [
(['--force'],
dict(help='Force WordOps update', action='store_true')),
]
usage = "wo update [options]"
2018-11-13 21:55:59 +01:00
@expose(hide=True)
def default(self):
filename = "woupdate" + time.strftime("%Y%m%d-%H%M%S")
2019-03-10 19:43:37 +01:00
WODownload.download(self, [["https://raw.githubusercontent.com/"
"WordOps/WordOps/master/install",
2018-11-13 21:55:59 +01:00
"/tmp/{0}".format(filename),
"update script"]])
2019-06-16 23:03:12 +02:00
if self.app.pargs.force:
try:
Log.info(self, "updating WordOps, please wait...")
os.system("bash /tmp/{0} --force".format(filename))
except OSError as e:
Log.debug(self, str(e))
Log.error(self, "WordOps update failed !")
else:
try:
Log.info(self, "updating WordOps, please wait...")
os.system("bash /tmp/{0}".format(filename))
except OSError as e:
Log.debug(self, str(e))
Log.error(self, "WordOps update failed !")
2018-11-13 21:55:59 +01:00
def load(app):
# register the plugin class.. this only happens if the plugin is enabled
handler.register(WOUpdateController)
# register a hook (function) to run after arguments are parsed.
hook.register('post_argument_parsing', wo_update_hook)