Refactor wo update

This commit is contained in:
VirtuBox
2019-10-28 06:52:23 +01:00
parent 9bf0a78f3d
commit 2c2b9c28fb
6 changed files with 55 additions and 25 deletions

View File

@@ -2,9 +2,10 @@ import os
import time
from cement.core.controller import CementBaseController, expose
from requests import RequestException, get, json
from wo.core.download import WODownload
from wo.core.logging import Log
from wo.core.variables import WOVar
def wo_update_hook(app):
@@ -43,6 +44,23 @@ class WOUpdateController(CementBaseController):
def default(self):
pargs = self.app.pargs
filename = "woupdate" + time.strftime("%Y%m%d-%H%M%S")
wo_current = WOVar.wo_version
try:
wo_github_latest = get(
'https://api.github.com/repos/WordOps/WordOps/releases/latest',
timeout=(5, 30)).json()
except RequestException:
Log.debug(
self, "Request to GitHub API failed. "
"Switching to Gitea instance")
wo_github_latest = get(
'https://git.virtubox.net/api/v1/repos/virtubox/WordOps/tags',
timeout=(5, 30)).json()
wo_latest = wo_github_latest[0]["name"]
else:
wo_latest = wo_github_latest["tag_name"]
install_args = ""
if pargs.mainline or pargs.beta:
wo_branch = "mainline"
@@ -52,6 +70,12 @@ class WOUpdateController(CementBaseController):
wo_branch = "master"
if pargs.force:
install_args = install_args + "--force "
else:
if not pargs.travis:
if wo_current == wo_latest:
Log.error(
self, "WordOps {0} is already installed"
.format(wo_latest))
if not os.path.isdir('/var/lib/wo/tmp'):
os.makedirs('/var/lib/wo/tmp')