2019-04-26 21:30:46 +02:00
|
|
|
import os
|
|
|
|
|
import time
|
|
|
|
|
|
2019-10-28 14:53:15 +01:00
|
|
|
|
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
|
2019-10-28 06:52:23 +01:00
|
|
|
from wo.core.variables import WOVar
|
2018-11-13 21:55:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
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-07-19 00:57:32 +02:00
|
|
|
(['--beta'],
|
2019-10-24 22:04:52 +02:00
|
|
|
dict(help='Update WordOps to latest mainline release '
|
|
|
|
|
'(same than --mainline)',
|
|
|
|
|
action='store_true')),
|
|
|
|
|
(['--mainline'],
|
|
|
|
|
dict(help='Update WordOps to latest mainline release',
|
2019-07-19 00:57:32 +02:00
|
|
|
action='store_true')),
|
2019-10-24 22:04:52 +02:00
|
|
|
(['--branch'],
|
|
|
|
|
dict(help="Update WordOps from a specific repository branch ",
|
|
|
|
|
action='store' or 'store_const',
|
|
|
|
|
const='develop', nargs='?')),
|
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):
|
2019-08-07 02:45:26 +02:00
|
|
|
pargs = self.app.pargs
|
2018-11-13 21:55:59 +01:00
|
|
|
filename = "woupdate" + time.strftime("%Y%m%d-%H%M%S")
|
2019-10-28 06:52:23 +01:00
|
|
|
|
2019-10-24 22:04:52 +02:00
|
|
|
install_args = ""
|
|
|
|
|
if pargs.mainline or pargs.beta:
|
|
|
|
|
wo_branch = "mainline"
|
2019-10-28 14:53:15 +01:00
|
|
|
install_args = install_args + "--mainline "
|
2019-10-24 22:04:52 +02:00
|
|
|
elif pargs.branch:
|
|
|
|
|
wo_branch = pargs.branch
|
2019-10-28 14:53:15 +01:00
|
|
|
install_args = install_args + "-b {0} ".format(wo_branch)
|
2019-08-07 02:45:26 +02:00
|
|
|
if pargs.force:
|
2019-07-19 00:57:32 +02:00
|
|
|
install_args = install_args + "--force "
|
2019-10-28 14:53:15 +01:00
|
|
|
if pargs.travis:
|
|
|
|
|
install_args = install_args + "--travis "
|
|
|
|
|
wo_branch = "updating-configuration"
|
|
|
|
|
|
|
|
|
|
if ((not pargs.force) and (not pargs.travis) and
|
|
|
|
|
(not pargs.mainline) and (not pargs.beta) and
|
|
|
|
|
(not pargs.branch)):
|
2019-10-30 16:14:14 +01:00
|
|
|
wo_current = WOVar.wo_version
|
|
|
|
|
wo_latest = WODownload.latest_release(self, "WordOps/WordOps")
|
2019-10-28 14:53:15 +01:00
|
|
|
if wo_current == wo_latest:
|
|
|
|
|
Log.error(
|
|
|
|
|
self, "WordOps {0} is already installed"
|
|
|
|
|
.format(wo_latest))
|
2019-07-19 00:57:32 +02:00
|
|
|
|
2019-10-23 14:08:54 +02:00
|
|
|
if not os.path.isdir('/var/lib/wo/tmp'):
|
|
|
|
|
os.makedirs('/var/lib/wo/tmp')
|
2019-07-19 00:57:32 +02:00
|
|
|
WODownload.download(self, [["https://raw.githubusercontent.com/"
|
|
|
|
|
"WordOps/WordOps/{0}/install"
|
|
|
|
|
.format(wo_branch),
|
|
|
|
|
"/var/lib/wo/tmp/{0}".format(filename),
|
|
|
|
|
"update script"]])
|
|
|
|
|
|
2019-10-28 14:53:15 +01:00
|
|
|
if os.path.isfile('install'):
|
2019-10-30 16:14:14 +01:00
|
|
|
Log.info(self, "updating WordOps from local install\n")
|
2019-10-28 14:53:15 +01:00
|
|
|
try:
|
|
|
|
|
Log.info(self, "updating WordOps, please wait...")
|
|
|
|
|
os.system("/bin/bash install --travis")
|
|
|
|
|
except OSError as e:
|
|
|
|
|
Log.debug(self, str(e))
|
|
|
|
|
Log.error(self, "WordOps update failed !")
|
2019-08-21 15:02:55 +02:00
|
|
|
else:
|
|
|
|
|
try:
|
|
|
|
|
Log.info(self, "updating WordOps, please wait...")
|
|
|
|
|
os.system("/bin/bash /var/lib/wo/tmp/{0} "
|
2019-10-28 14:53:15 +01:00
|
|
|
"{1}".format(filename, install_args))
|
2019-08-21 15:02:55 +02:00
|
|
|
except OSError as e:
|
|
|
|
|
Log.debug(self, str(e))
|
|
|
|
|
Log.error(self, "WordOps update failed !")
|
2019-06-16 21:13:58 +02:00
|
|
|
|
2019-10-24 22:04:52 +02:00
|
|
|
os.remove("/var/lib/wo/tmp/{0}".format(filename))
|
|
|
|
|
|
2018-11-13 21:55:59 +01:00
|
|
|
|
|
|
|
|
def load(app):
|
|
|
|
|
# register the plugin class.. this only happens if the plugin is enabled
|
2019-09-24 00:01:20 +02:00
|
|
|
app.handler.register(WOUpdateController)
|
2018-11-13 21:55:59 +01:00
|
|
|
# register a hook (function) to run after arguments are parsed.
|
2019-09-24 00:04:32 +02:00
|
|
|
app.hook.register('post_argument_parsing', wo_update_hook)
|