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

119 lines
4.4 KiB
Python
Raw Normal View History

2019-04-26 21:30:46 +02:00
import os
import time
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']
aliases_only = True
2018-11-13 21:55:59 +01:00
stacked_type = 'nested'
description = ('update WordOps to latest version')
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')),
]
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 = ""
2019-10-30 17:25:52 +01:00
wo_branch = "master"
2019-10-24 22:04:52 +02:00
if pargs.mainline or pargs.beta:
wo_branch = "mainline"
install_args = install_args + "--mainline "
2019-10-24 22:04:52 +02:00
elif pargs.branch:
wo_branch = pargs.branch
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 "
if pargs.travis:
install_args = install_args + "--travis "
wo_branch = "updating-configuration"
2022-11-14 15:15:04 +01:00
# check if WordOps already up-to-date
if ((not pargs.force) and (not pargs.travis) and
(not pargs.mainline) and (not pargs.beta) and
(not pargs.branch)):
2019-10-30 22:24:26 +01:00
wo_current = ("v{0}".format(WOVar.wo_version))
2019-10-30 16:14:14 +01:00
wo_latest = WODownload.latest_release(self, "WordOps/WordOps")
if wo_current == wo_latest:
Log.info(
self, "WordOps {0} is already installed"
.format(wo_latest))
self.app.close(0)
2019-07-19 00:57:32 +02:00
2022-11-14 15:15:04 +01:00
# prompt user before starting upgrade
if not pargs.force:
Log.info(
self, "WordOps changelog available on "
"https://github.com/WordOps/WordOps/releases/tag/{0}"
.format(wo_latest))
start_upgrade = input("Do you want to continue:[y/N]")
if start_upgrade not in ("Y", "y"):
Log.error(self, "Not starting WordOps update")
# download the install/update script
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"]])
2022-11-14 15:15:04 +01:00
# launch install script
if os.path.isfile('install'):
2019-10-30 16:14:14 +01:00
Log.info(self, "updating WordOps from local install\n")
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} "
"{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-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)