QuasarAppCI/BuildBotLib/asssetsinstaller.py

156 lines
4.2 KiB
Python
Raw Normal View History

2019-12-13 16:09:43 +03:00
# This Python file uses the following encoding: utf-8
2019-12-26 17:08:56 +03:00
from BuildBotLib.basemodule import BaseModule
2019-12-13 16:09:43 +03:00
from buildbot.plugins import util, steps
import os
2019-12-17 18:35:28 +03:00
from pathlib import Path
2019-12-13 16:09:43 +03:00
2019-12-13 17:05:49 +03:00
2019-12-26 17:08:56 +03:00
class AsssetsInstaller(BaseModule):
def __init__(self):
BaseModule.__init__(self)
2019-12-17 10:37:56 +03:00
2019-12-26 17:08:56 +03:00
format = ""
2019-12-17 10:37:56 +03:00
2019-12-26 17:08:56 +03:00
AndroidBaseDir = str(Path.home()) + "/Android"
2019-12-17 10:37:56 +03:00
2019-12-26 17:08:56 +03:00
def isInit(self, step):
return step.getProperty('module') == 'init'
2019-12-13 16:09:43 +03:00
2019-12-26 17:08:56 +03:00
@util.renderer
def RemoveOldData(self, props):
2019-12-13 16:09:43 +03:00
2019-12-26 17:08:56 +03:00
cmd = "mkdir -p " + self.AndroidBaseDir
2019-12-16 15:48:24 +03:00
2019-12-26 17:08:56 +03:00
if os.path.exists(self.AndroidBaseDir):
cmd = "rm -rdf " + self.AndroidBaseDir + " ; " + cmd
2019-12-16 15:48:24 +03:00
2019-12-26 17:08:56 +03:00
return self.generateCmd(cmd)
2019-12-16 15:48:24 +03:00
2019-12-26 17:08:56 +03:00
@util.renderer
def NDKDownloadCMD(self, props):
link = props.getProperty("link")
2019-12-16 15:48:24 +03:00
2019-12-26 17:08:56 +03:00
self.format = link[link.rfind('.'):].lower()
2019-12-13 16:09:43 +03:00
2019-12-26 17:08:56 +03:00
return ["curl",
link,
"--output",
self.AndroidBaseDir + "/temp" + self.format]
2019-12-13 16:09:43 +03:00
2019-12-26 17:08:56 +03:00
@util.renderer
def ExtractCMD(self, props):
2019-12-13 16:09:43 +03:00
2019-12-26 17:08:56 +03:00
res = ["echo", "format '" + format + "' not supported"]
2019-12-13 16:09:43 +03:00
2019-12-26 17:08:56 +03:00
if format == ".zip":
res = ["unzip", self.AndroidBaseDir + "/temp" + self.format,
"-d", self.AndroidBaseDir]
2019-12-13 16:09:43 +03:00
2019-12-26 17:08:56 +03:00
return res
2019-12-13 16:09:43 +03:00
2019-12-26 17:08:56 +03:00
@util.renderer
def InstallCMD(self, props):
2019-12-13 16:09:43 +03:00
2019-12-26 17:08:56 +03:00
module = props.getProperty("module")
version = props.getProperty("version")
2019-12-13 16:39:15 +03:00
2019-12-26 17:08:56 +03:00
unit_to_multiplier = {
'SDK': 'platform-tools;tools;platforms;android-'+version,
'NDK': 'ndk-bundle'
}
2019-12-16 15:11:58 +03:00
2019-12-26 17:08:56 +03:00
return ["sdkmanager", unit_to_multiplier.get(module, "--list")]
2019-12-16 15:11:58 +03:00
2019-12-26 17:08:56 +03:00
@util.renderer
def ConfigureCMD(self, props):
2019-12-16 15:11:58 +03:00
2019-12-26 17:08:56 +03:00
res = ["echo", "Configure failed"]
2019-12-17 10:37:56 +03:00
2019-12-26 17:08:56 +03:00
if format == ".zip":
2019-12-17 10:37:56 +03:00
2019-12-26 17:08:56 +03:00
all_subdirs = self.allSubdirsOf(self.AndroidBaseDir)
latest_subdir = max(all_subdirs, key=os.path.getmtime)
res = "mv " + latest_subdir + " " + self.AndroidBaseDir + "/tools"
res += " ; ln -sf "
res += self.AndroidBaseDir + "/tools/bin/sdkmanager "
res += self.home + "/.local/bin/sdkmanager"
res += " ; yes | sdkmanager --licenses"
2019-12-17 10:37:56 +03:00
2019-12-26 17:08:56 +03:00
return self.generateCmd(res)
2019-12-17 10:37:56 +03:00
2019-12-26 17:08:56 +03:00
def getFactory(self):
factory = super().getFactory()
2019-12-16 15:11:58 +03:00
2019-12-26 17:08:56 +03:00
factory.addStep(
steps.ShellCommand(
command=self.RemoveOldData,
name='rm old item',
doStepIf=self.isInit,
description='rm old',
haltOnFailure=True,
)
2019-12-16 15:48:24 +03:00
)
2019-12-26 17:08:56 +03:00
factory.addStep(
steps.ShellCommand(
command=self.NDKDownloadCMD,
name='download new item',
doStepIf=self.isInit,
description='download new item',
haltOnFailure=True,
)
2019-12-13 16:09:43 +03:00
)
2019-12-26 17:08:56 +03:00
factory.addStep(
steps.ShellCommand(
command=self.ExtractCMD,
name='extract new item',
doStepIf=self.isInit,
description='extract new item',
haltOnFailure=True,
)
2019-12-13 16:09:43 +03:00
)
2019-12-26 17:08:56 +03:00
factory.addStep(
steps.ShellCommand(
command=self.ConfigureCMD,
name='configure new item',
doStepIf=self.isInit,
description='configure new item',
haltOnFailure=True,
)
2019-12-17 10:37:56 +03:00
)
2019-12-26 17:08:56 +03:00
factory.addStep(
steps.ShellCommand(
command=self.InstallCMD,
name='install module',
doStepIf=lambda step: not self.isInit(step),
description='configure new item',
haltOnFailure=True,
)
2019-12-16 15:11:58 +03:00
)
2019-12-26 17:08:56 +03:00
return factory
def getPropertyes(self):
return [
util.ChoiceStringParameter(
name='module',
choices=["init", "SDK", "NDK"],
default="init"
),
util.StringParameter(
name='link',
label="url to download item",
default=""
),
util.StringParameter(
name='version',
label="Version",
default=""
),
]