Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ docker-compose.yml
docker-compose.override.yml
compose-override.yml
build-installer.sh
rsync-to-dev.sh
docker-compose-base.yml
build-options.json
iotstack_build_*.zip
Expand Down
111 changes: 56 additions & 55 deletions .templates/adminer/build.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3


issues = {} # Returned issues dict
buildHooks = {} # Options, and others hooks
haltOnErrors = True

# Main wrapper function. Required to make local vars work correctly
Expand All @@ -22,7 +22,6 @@ def main():

global dockerComposeServicesYaml # The loaded memory YAML of all checked services
global toRun # Switch for which function to run when executed
global buildHooks # Where to place the options menu result
global currentServiceName # Name of the current service
global issues # Returned issues dict
global haltOnErrors # Turn on to allow erroring
Expand All @@ -38,43 +37,6 @@ def main():
# runtime vars
portConflicts = []

# This lets the menu know whether to put " >> Options " or not
# This function is REQUIRED.
def checkForOptionsHook():
try:
buildHooks["options"] = callable(runOptionsMenu)
except:
buildHooks["options"] = False
return buildHooks
return buildHooks

# This function is REQUIRED.
def checkForPreBuildHook():
try:
buildHooks["preBuildHook"] = callable(preBuild)
except:
buildHooks["preBuildHook"] = False
return buildHooks
return buildHooks

# This function is REQUIRED.
def checkForPostBuildHook():
try:
buildHooks["postBuildHook"] = callable(postBuild)
except:
buildHooks["postBuildHook"] = False
return buildHooks
return buildHooks

# This function is REQUIRED.
def checkForRunChecksHook():
try:
buildHooks["runChecksHook"] = callable(runChecks)
except:
buildHooks["runChecksHook"] = False
return buildHooks
return buildHooks

# This service will not check anything unless this is set
# This function is optional, and will run each time the menu is rendered
def runChecks():
Expand Down Expand Up @@ -165,13 +127,18 @@ def createMenu():
adminerBuildOptions.append(["Go back", goBack])

def runOptionsMenu():
createMenu()
menuEntryPoint()
return True
originalSignalHandler = signal.getsignal(signal.SIGWINCH)
signal.signal(signal.SIGWINCH, onResize)
try:
createMenu()
menuEntryPoint()
return True
finally:
signal.signal(signal.SIGWINCH, originalSignalHandler)

def renderHotZone(term, menu, selection, hotzoneLocation):
lineLengthAtTextStart = 71
print(term.move(hotzoneLocation[0], hotzoneLocation[1]))
print(term.move(hotzoneLocation[0], hotzoneLocation[1]), end="")
for (index, menuItem) in enumerate(menu):
toPrint = ""
if index == selection:
Expand Down Expand Up @@ -254,6 +221,7 @@ def menuEntryPoint():
with term.fullscreen():
menuNavigateDirection = 0
mainRender(needsRender, adminerBuildOptions, currentMenuItemIndex)
needsRender = 0
selectionInProgress = True
with term.cbreak():
while selectionInProgress:
Expand Down Expand Up @@ -299,17 +267,50 @@ def menuEntryPoint():
####################


hook = locals().get(toRun)
if hook is None:
raise ValueError("Unknown service hook '%s'" % toRun)
if haltOnErrors:
eval(toRun)()
else:
try:
eval(toRun)()
except:
pass
return hook()
try:
return hook()
except Exception:
return None

def _runHook(context, action):
"""Adapt the service's established implementation to hook API v2."""
global dockerComposeServicesYaml
global currentServiceName
global renderMode
global toRun

dockerComposeServicesYaml = context.services
currentServiceName = context.serviceName
renderMode = context.renderMode
toRun = action
result = main()
context.services = dockerComposeServicesYaml
return result


def runChecks(context):
"""Return build issues for the currently selected Compose services."""
global issues
issues = {}
_runHook(context, "runChecks")
return issues


def runOptionsMenu(context):
"""Open this service's interactive configuration menu."""
return _runHook(context, "runOptionsMenu")


def preBuild(context):
"""Run this service's pre-build work."""
return _runHook(context, "preBuild")


# This check isn't required, but placed here for debugging purposes
global currentServiceName # Name of the current service
if currentServiceName == 'adminer':
main()
else:
print("Error. '{}' Tried to run 'adminer' config".format(currentServiceName))
def postBuild(context):
"""Run this service's post-build work."""
return _runHook(context, "postBuild")
Loading