18 from enum
import IntEnum
19 from pathlib
import Path
23 from .utils
import getExecPath
24 from .cron
import jobExists, scheduleJob
25 from ..resources
import RESOURCES_DIR
26 from ...utils
import command
27 from ...configuration
import DEFAULT_VENV_PATH
30 UPDATE_SCRIPT_NAME =
"update_node.sh"
33 class NodeStatus(IntEnum):
42 def generateUpdateScript() -> str:
43 dockerExecPath = getExecPath(
"docker")
44 gitExecPath = getExecPath(
"git")
45 bashScriptTemplatePath = RESOURCES_DIR /
"update_script_template.sh"
47 with bashScriptTemplatePath.open(
"r")
as scriptFile:
48 bashScriptTemplate = scriptFile.read()
50 return bashScriptTemplate.format(
51 dockerPath = dockerExecPath,
52 gitPath = gitExecPath,
53 venvPath = DEFAULT_VENV_PATH
57 def dumpScript(updateScriptPath: Path) ->
None:
58 with updateScriptPath.open(
"w")
as scriptFile:
59 scriptFile.write(generateUpdateScript())
61 command([
"chmod",
"+x", str(updateScriptPath)], ignoreStdout =
True)
64 def activateAutoUpdate() -> None:
65 updateScriptPath = DEFAULT_VENV_PATH.parent / UPDATE_SCRIPT_NAME
66 dumpScript(updateScriptPath)
68 if not jobExists(str(updateScriptPath)):
69 scheduleJob(UPDATE_SCRIPT_NAME)