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']
|
2019-06-17 13:46:26 +02:00
|
|
|
aliases_only = True
|
2018-11-13 21:55:59 +01:00
|
|
|
stacked_type = 'nested'
|
|
|
|
|
description = ('update WordOps to latest version')
|
2019-06-16 21:13:58 +02:00
|
|
|
arguments = [
|
|
|
|
|
(['--force'],
|
|
|
|
|
dict(help='Force WordOps update', action='store_true')),
|
2019-06-18 14:35:05 +02:00
|
|
|
(['--preserve'],
|
|
|
|
|
dict(help='Preserve current Nginx configuration',
|
|
|
|
|
action='store_true')),
|
2019-07-19 00:57:32 +02:00
|
|
|
(['--beta'],
|
|
|
|
|
dict(help='Update WordOps to latest beta release',
|
|
|
|
|
action='store_true')),
|
2019-06-17 11:44:46 +02:00
|
|
|
(['--travis'],
|
|
|
|
|
dict(help='Argument used only for WordOps development',
|
|
|
|
|
action='store_true')),
|
2019-06-16 21:13:58 +02:00
|
|
|
]
|
|
|
|
|
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-06-17 11:56:33 +02:00
|
|
|
|
|
|
|
|
if self.app.pargs.travis:
|
2019-07-19 00:57:32 +02:00
|
|
|
wo_branch = "updating-configuration"
|
|
|
|
|
install_args = "--travis --force "
|
|
|
|
|
elif self.app.pargs.beta:
|
|
|
|
|
wo_branch = "beta"
|
|
|
|
|
install_args = ""
|
2019-06-16 23:03:12 +02:00
|
|
|
else:
|
2019-07-19 00:57:32 +02:00
|
|
|
wo_branch = "master "
|
|
|
|
|
install_args = ""
|
|
|
|
|
if self.app.pargs.force:
|
|
|
|
|
install_args = install_args + "--force "
|
|
|
|
|
if self.app.pargs.preserve:
|
|
|
|
|
install_args = install_args + "--preserve "
|
|
|
|
|
|
|
|
|
|
WODownload.download(self, [["https://raw.githubusercontent.com/"
|
|
|
|
|
"WordOps/WordOps/{0}/install"
|
|
|
|
|
.format(wo_branch),
|
|
|
|
|
"/var/lib/wo/tmp/{0}".format(filename),
|
|
|
|
|
"update script"]])
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
Log.info(self, "updating WordOps, please wait...")
|
|
|
|
|
os.system("/bin/bash /var/lib/wo/tmp/{0} "
|
|
|
|
|
"-b {1} {2}".format(filename,
|
|
|
|
|
wo_branch, install_args))
|
|
|
|
|
except OSError as e:
|
|
|
|
|
Log.debug(self, str(e))
|
|
|
|
|
Log.error(self, "WordOps update failed !")
|
2019-06-16 21:13:58 +02:00
|
|
|
|
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)
|