Skip to content

Commit

Permalink
Added deconz prebuild logic. Updated variable in all build files to b…
Browse files Browse the repository at this point in the history
…e more clear
  • Loading branch information
Slyke committed Jul 9, 2020
1 parent a3e6b64 commit a72dc24
Show file tree
Hide file tree
Showing 36 changed files with 121 additions and 218 deletions.
16 changes: 8 additions & 8 deletions .templates/adminer/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def main():
from deps.consts import servicesDirectory, templatesDirectory
from deps.common_functions import getExternalPorts, getInternalPorts, checkPortConflicts

global dockerComposeYaml # The loaded memory YAML of all checked services
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
Expand Down Expand Up @@ -90,10 +90,10 @@ def preBuild():
# #####################################

def checkForIssues():
for (index, serviceName) in enumerate(dockerComposeYaml):
for (index, serviceName) in enumerate(dockerComposeServicesYaml):
if not currentServiceName == serviceName: # Skip self
currentServicePorts = getExternalPorts(currentServiceName, dockerComposeYaml)
portConflicts = checkPortConflicts(serviceName, currentServicePorts, dockerComposeYaml)
currentServicePorts = getExternalPorts(currentServiceName, dockerComposeServicesYaml)
portConflicts = checkPortConflicts(serviceName, currentServicePorts, dockerComposeServicesYaml)
if (len(portConflicts) > 0):
issues["portConflicts"] = portConflicts

Expand Down Expand Up @@ -127,7 +127,7 @@ def goBack():

def enterPortNumber():
global needsRender
global dockerComposeYaml
global dockerComposeServicesYaml
newPortNumber = ""
try:
print(term.move_y(hotzoneLocation[0]))
Expand All @@ -143,8 +143,8 @@ def enterPortNumber():
if 1 <= newPortNumber <= 65535:
needsRender = 1
time.sleep(0.2) # Prevent loop
internalPort = getInternalPorts(currentServiceName, dockerComposeYaml)[0]
dockerComposeYaml[currentServiceName]["ports"][0] = "{newExtPort}:{oldIntPort}".format(
internalPort = getInternalPorts(currentServiceName, dockerComposeServicesYaml)[0]
dockerComposeServicesYaml[currentServiceName]["ports"][0] = "{newExtPort}:{oldIntPort}".format(
newExtPort = newPortNumber,
oldIntPort = internalPort
)
Expand Down Expand Up @@ -173,7 +173,7 @@ def createMenu():
global adminerBuildOptions
try:
adminerBuildOptions = []
portNumber = getExternalPorts(currentServiceName, dockerComposeYaml)[0]
portNumber = getExternalPorts(currentServiceName, dockerComposeServicesYaml)[0]
adminerBuildOptions.append([
"Change external WUI Port Number from: {port}".format(port=portNumber),
enterPortNumber
Expand Down
16 changes: 8 additions & 8 deletions .templates/blynk_server/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def main():
from deps.consts import servicesDirectory, templatesDirectory
from deps.common_functions import getExternalPorts, getInternalPorts, checkPortConflicts

global dockerComposeYaml # The loaded memory YAML of all checked services
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
Expand Down Expand Up @@ -90,10 +90,10 @@ def preBuild():
# #####################################

def checkForIssues():
for (index, serviceName) in enumerate(dockerComposeYaml):
for (index, serviceName) in enumerate(dockerComposeServicesYaml):
if not currentServiceName == serviceName: # Skip self
currentServicePorts = getExternalPorts(currentServiceName, dockerComposeYaml)
portConflicts = checkPortConflicts(serviceName, currentServicePorts, dockerComposeYaml)
currentServicePorts = getExternalPorts(currentServiceName, dockerComposeServicesYaml)
portConflicts = checkPortConflicts(serviceName, currentServicePorts, dockerComposeServicesYaml)
if (len(portConflicts) > 0):
issues["portConflicts"] = portConflicts

Expand Down Expand Up @@ -127,7 +127,7 @@ def goBack():

def enterPortNumber():
global needsRender
global dockerComposeYaml
global dockerComposeServicesYaml
newPortNumber = ""
try:
print(term.move_y(hotzoneLocation[0]))
Expand All @@ -143,8 +143,8 @@ def enterPortNumber():
if 1 <= newPortNumber <= 65535:
needsRender = 1
time.sleep(0.2) # Prevent loop
internalPort = getInternalPorts(currentServiceName, dockerComposeYaml)[0]
dockerComposeYaml[currentServiceName]["ports"][0] = "{newExtPort}:{oldIntPort}".format(
internalPort = getInternalPorts(currentServiceName, dockerComposeServicesYaml)[0]
dockerComposeServicesYaml[currentServiceName]["ports"][0] = "{newExtPort}:{oldIntPort}".format(
newExtPort = newPortNumber,
oldIntPort = internalPort
)
Expand Down Expand Up @@ -173,7 +173,7 @@ def createMenu():
global blynkServerBuildOptions
try:
blynkServerBuildOptions = []
portNumber = getExternalPorts(currentServiceName, dockerComposeYaml)[0]
portNumber = getExternalPorts(currentServiceName, dockerComposeServicesYaml)[0]
blynkServerBuildOptions.append([
"Change external WUI Port Number from: {port}".format(port=portNumber),
enterPortNumber
Expand Down
26 changes: 18 additions & 8 deletions .templates/deconz/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def main():
from deps.consts import servicesDirectory, templatesDirectory
from deps.common_functions import getExternalPorts, getInternalPorts, checkPortConflicts

global dockerComposeYaml # The loaded memory YAML of all checked services
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
Expand Down Expand Up @@ -91,6 +91,16 @@ def postBuild():

# This function is optional, and will run just before the build docker-compose.yml code.
def preBuild():
global dockerComposeServicesYaml
with open(r'%s/hardware_selected.yml' % serviceService) as objHardwareListFile:
hardwareList = yaml.load(objHardwareListFile, Loader=yaml.SafeLoader)
try:
if "deconz" in dockerComposeServicesYaml:
dockerComposeServicesYaml["deconz"]["devices"] = hardwareList["hardware"]
except Exception as err:
print("Error setting deconz hardware: ", err)
return False

return True

# #####################################
Expand All @@ -101,10 +111,10 @@ def checkForIssues():
fileIssues = checkFiles()
if (len(fileIssues) > 0):
issues["fileIssues"] = fileIssues
for (index, serviceName) in enumerate(dockerComposeYaml):
for (index, serviceName) in enumerate(dockerComposeServicesYaml):
if not currentServiceName == serviceName: # Skip self
currentServicePorts = getExternalPorts(currentServiceName, dockerComposeYaml)
portConflicts = checkPortConflicts(serviceName, currentServicePorts, dockerComposeYaml)
currentServicePorts = getExternalPorts(currentServiceName, dockerComposeServicesYaml)
portConflicts = checkPortConflicts(serviceName, currentServicePorts, dockerComposeServicesYaml)
if (len(portConflicts) > 0):
issues["portConflicts"] = portConflicts

Expand Down Expand Up @@ -167,7 +177,7 @@ def selectDeconzHardware():

def enterPortNumber():
global needsRender
global dockerComposeYaml
global dockerComposeServicesYaml
newPortNumber = ""
try:
print(term.move_y(hotzoneLocation[0]))
Expand All @@ -183,8 +193,8 @@ def enterPortNumber():
if 1 <= newPortNumber <= 65535:
needsRender = 1
time.sleep(0.2) # Prevent loop
internalPort = getInternalPorts(currentServiceName, dockerComposeYaml)[0]
dockerComposeYaml[currentServiceName]["ports"][0] = "{newExtPort}:{oldIntPort}".format(
internalPort = getInternalPorts(currentServiceName, dockerComposeServicesYaml)[0]
dockerComposeServicesYaml[currentServiceName]["ports"][0] = "{newExtPort}:{oldIntPort}".format(
newExtPort = newPortNumber,
oldIntPort = internalPort
)
Expand Down Expand Up @@ -214,7 +224,7 @@ def createMenu():
global serviceService
try:
deconzBuildOptions = []
portNumber = getExternalPorts(currentServiceName, dockerComposeYaml)[0]
portNumber = getExternalPorts(currentServiceName, dockerComposeServicesYaml)[0]
deconzBuildOptions.append([
"Change external WUI Port Number from: {port}".format(port=portNumber),
enterPortNumber
Expand Down
44 changes: 0 additions & 44 deletions .templates/deconz/build.sh

This file was deleted.

5 changes: 2 additions & 3 deletions .templates/deconz/service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
volumes:
- ./volumes/deconz/:/root/.local/share/dresden-elektronik/deCONZ
devices:
#RaspBee:
- /dev/ttyAMA0
#alternatively - /dev/ttyS0
# This list is replaced during the build process. Modify the list in "hardware_list.yml" to change it.
- /dev/null
environment:
- DECONZ_VNC_MODE=1
- DECONZ_VNC_PASSWORD=changeme
Expand Down
21 changes: 0 additions & 21 deletions .templates/deconz/service_conbee.yml

This file was deleted.

21 changes: 0 additions & 21 deletions .templates/deconz/service_conbee_II.yml

This file was deleted.

22 changes: 0 additions & 22 deletions .templates/deconz/service_raspbee.yml

This file was deleted.

8 changes: 4 additions & 4 deletions .templates/diyhue/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# Main wrapper function. Required to make local vars work correctly
def main():
global dockerComposeYaml # The loaded memory YAML of all checked services
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
Expand Down Expand Up @@ -72,7 +72,7 @@ def preBuild():
# #####################################

def checkForIssues():
for (index, serviceName) in enumerate(dockerComposeYaml):
for (index, serviceName) in enumerate(dockerComposeServicesYaml):
if not currentServiceName == serviceName: # Skip self
currentServicePorts = getExternalPorts(currentServiceName)
portConflicts = checkPortConflicts(serviceName, currentServicePorts)
Expand All @@ -82,7 +82,7 @@ def checkForIssues():
def getExternalPorts(serviceName):
externalPorts = []
try:
yamlService = dockerComposeYaml[serviceName]
yamlService = dockerComposeServicesYaml[serviceName]
if "ports" in yamlService:
for (index, port) in enumerate(yamlService["ports"]):
try:
Expand All @@ -97,7 +97,7 @@ def getExternalPorts(serviceName):
def checkPortConflicts(serviceName, currentPorts):
portConflicts = []
if not currentServiceName == serviceName:
yamlService = dockerComposeYaml[serviceName]
yamlService = dockerComposeServicesYaml[serviceName]
servicePorts = getExternalPorts(serviceName)
for (index, servicePort) in enumerate(servicePorts):
for (index, currentPort) in enumerate(currentPorts):
Expand Down
2 changes: 1 addition & 1 deletion .templates/dozzle/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# Main wrapper function. Required to make local vars work correctly
def main():
global dockerComposeYaml # The loaded memory YAML of all checked services
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
Expand Down
2 changes: 1 addition & 1 deletion .templates/espruinohub/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# Main wrapper function. Required to make local vars work correctly
def main():
global dockerComposeYaml # The loaded memory YAML of all checked services
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
Expand Down
8 changes: 4 additions & 4 deletions .templates/example_template/example_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def main():
import types
import time

global dockerComposeYaml # The loaded memory YAML of all checked services
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
Expand Down Expand Up @@ -90,7 +90,7 @@ def preBuild():
# #####################################

def checkForIssues():
for (index, serviceName) in enumerate(dockerComposeYaml):
for (index, serviceName) in enumerate(dockerComposeServicesYaml):
if not currentServiceName == serviceName: # Skip self
currentServicePorts = getExternalPorts(currentServiceName)
portConflicts = checkPortConflicts(serviceName, currentServicePorts)
Expand All @@ -100,7 +100,7 @@ def checkForIssues():
def getExternalPorts(serviceName):
externalPorts = []
try:
yamlService = dockerComposeYaml[serviceName]
yamlService = dockerComposeServicesYaml[serviceName]
if "ports" in yamlService:
for (index, port) in enumerate(yamlService["ports"]):
try:
Expand All @@ -115,7 +115,7 @@ def getExternalPorts(serviceName):
def checkPortConflicts(serviceName, currentPorts):
portConflicts = []
if not currentServiceName == serviceName:
yamlService = dockerComposeYaml[serviceName]
yamlService = dockerComposeServicesYaml[serviceName]
servicePorts = getExternalPorts(serviceName)
for (index, servicePort) in enumerate(servicePorts):
for (index, currentPort) in enumerate(currentPorts):
Expand Down
Loading

0 comments on commit a72dc24

Please sign in to comment.