Skip to content

Commit

Permalink
Fixed bug where menu would crash when no build options selected
Browse files Browse the repository at this point in the history
  • Loading branch information
Slyke committed Nov 8, 2024
1 parent 313faf2 commit 57fc352
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 70 deletions.
24 changes: 13 additions & 11 deletions .templates/otbr/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,23 +140,25 @@ def preBuild():
# #####################################

def checkForIssues():
with open("{serviceDir}{buildSettings}".format(serviceDir=serviceService, buildSettings=buildSettingsFileName)) as objHardwareListFile:
otbrYamlBuildOptions = yaml.load(objHardwareListFile)
passed = True
try:
with open("{serviceDir}{buildSettings}".format(serviceDir=serviceService, buildSettings=buildSettingsFileName)) as objHardwareListFile:
otbrYamlBuildOptions = yaml.load(objHardwareListFile)
if not otbrYamlBuildOptions["hardware"] or len(otbrYamlBuildOptions["hardware"]) < 1:
issues["hardware"] = "No Thread radio selected."
passed = False
if otbrYamlBuildOptions["hardware"] and len(otbrYamlBuildOptions["hardware"]) > 1:
issues["hardware"] = "Two or more thread radios selected. The first listed one will be used"
passed = False
except Exception as err:
issues["hardware"] = "No Thread radio selected."
for (index, serviceName) in enumerate(dockerComposeServicesYaml):
if not currentServiceName == serviceName: # Skip self
currentServicePorts = getExternalPorts(currentServiceName, dockerComposeServicesYaml)
portConflicts = checkPortConflicts(serviceName, currentServicePorts, dockerComposeServicesYaml)
if (len(portConflicts) > 0):
issues["portConflicts"] = portConflicts

print(otbrYamlBuildOptions["hardware"])
if not otbrYamlBuildOptions["hardware"] or len(otbrYamlBuildOptions["hardware"]) < 1:
issues["hardware"] = "No Thread radio selected."
if otbrYamlBuildOptions["hardware"] and len(otbrYamlBuildOptions["hardware"]) > 1:
issues["hardware"] = "Two or more thread radios selected. The first listed one will be used"



passed = False

# #####################################
# End Supporting functions
Expand Down
119 changes: 60 additions & 59 deletions .templates/python-matter-server/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,76 +97,77 @@ def postBuild():
def preBuild():
global dockerComposeServicesYaml
global currentServiceName
with open("{serviceDir}{buildSettings}".format(serviceDir=serviceService, buildSettings=buildSettingsFileName)) as objExtrasListFile:
pythonMatterServerYamlBuildOptions = yaml.load(objExtrasListFile)

with open((r'%s/' % serviceTemplate) + servicesFileName) as objServiceFile:
serviceYamlTemplate = yaml.load(objServiceFile)

oldBuildCache = {}
try:
with open(r'%s' % buildCache) as objBuildCache:
oldBuildCache = yaml.load(objBuildCache)
except:
pass

with open("{serviceDir}{buildSettings}".format(serviceDir=serviceService, buildSettings=buildSettingsFileName)) as objExtrasListFile:
pythonMatterServerYamlBuildOptions = yaml.load(objExtrasListFile)

with open((r'%s/' % serviceTemplate) + servicesFileName) as objServiceFile:
serviceYamlTemplate = yaml.load(objServiceFile)

oldBuildCache = {}
try:
with open(r'%s' % buildCache) as objBuildCache:
oldBuildCache = yaml.load(objBuildCache)
except:
pass

buildCacheServices = {}
if "services" in oldBuildCache:
buildCacheServices = oldBuildCache["services"]

if not os.path.exists(serviceService):
os.makedirs(serviceService, exist_ok=True)

try:
if currentServiceName in dockerComposeServicesYaml:
if pythonMatterServerYamlBuildOptions["extras"]:
if "Mount Bluetooth: /run/dbus" in pythonMatterServerYamlBuildOptions["extras"]:
if not "/run/dbus:/run/dbus:ro" in dockerComposeServicesYaml[currentServiceName]["volumes"]:
dockerComposeServicesYaml[currentServiceName]["volumes"].append("/run/dbus:/run/dbus:ro")

currentCommand = dockerComposeServicesYaml[currentServiceName]["command"]
if not "--bluetooth-adapter 0\n" in currentCommand:
newCommand = currentCommand + "--bluetooth-adapter 0\n"
dockerComposeServicesYaml[currentServiceName]["command"] = newCommand
else:
if "/run/dbus:/run/dbus:ro" in dockerComposeServicesYaml[currentServiceName]["volumes"]:
dockerComposeServicesYaml[currentServiceName]["volumes"].remove("/run/dbus:/run/dbus:ro")

currentCommand = dockerComposeServicesYaml[currentServiceName]["command"]
if "--bluetooth-adapter 0\n" in currentCommand:
newCommand = currentCommand.replace("--bluetooth-adapter 0\n", "")
buildCacheServices = {}
if "services" in oldBuildCache:
buildCacheServices = oldBuildCache["services"]

if not os.path.exists(serviceService):
os.makedirs(serviceService, exist_ok=True)

try:
if currentServiceName in dockerComposeServicesYaml:
if pythonMatterServerYamlBuildOptions["extras"]:
if "Mount Bluetooth: /run/dbus" in pythonMatterServerYamlBuildOptions["extras"]:
if not "/run/dbus:/run/dbus:ro" in dockerComposeServicesYaml[currentServiceName]["volumes"]:
dockerComposeServicesYaml[currentServiceName]["volumes"].append("/run/dbus:/run/dbus:ro")

currentCommand = dockerComposeServicesYaml[currentServiceName]["command"]
if not "--bluetooth-adapter 0\n" in currentCommand:
newCommand = currentCommand + "--bluetooth-adapter 0\n"
dockerComposeServicesYaml[currentServiceName]["command"] = newCommand

if "Enabled Root Certificates" in pythonMatterServerYamlBuildOptions["extras"]:
currentCommand = dockerComposeServicesYaml[currentServiceName]["command"]
if not "--paa-root-cert-dir /data/credentials\n" in currentCommand:
newCommand = currentCommand + "--paa-root-cert-dir /data/credentials\n"
dockerComposeServicesYaml[currentServiceName]["command"] = newCommand
else:
if "/run/dbus:/run/dbus:ro" in dockerComposeServicesYaml[currentServiceName]["volumes"]:
dockerComposeServicesYaml[currentServiceName]["volumes"].remove("/run/dbus:/run/dbus:ro")

currentCommand = dockerComposeServicesYaml[currentServiceName]["command"]
if "--bluetooth-adapter 0\n" in currentCommand:
newCommand = currentCommand.replace("--bluetooth-adapter 0\n", "")
dockerComposeServicesYaml[currentServiceName]["command"] = newCommand

if "Enabled Root Certificates" in pythonMatterServerYamlBuildOptions["extras"]:
currentCommand = dockerComposeServicesYaml[currentServiceName]["command"]
if not "--paa-root-cert-dir /data/credentials\n" in currentCommand:
newCommand = currentCommand + "--paa-root-cert-dir /data/credentials\n"
dockerComposeServicesYaml[currentServiceName]["command"] = newCommand
else:
currentCommand = dockerComposeServicesYaml[currentServiceName]["command"]
if "--paa-root-cert-dir /data/credentials\n" in currentCommand:
newCommand = currentCommand.replace("--paa-root-cert-dir /data/credentials\n", "")
dockerComposeServicesYaml[currentServiceName]["command"] = newCommand
else:
currentCommand = dockerComposeServicesYaml[currentServiceName]["command"]
if "--paa-root-cert-dir /data/credentials\n" in currentCommand:
newCommand = currentCommand.replace("--paa-root-cert-dir /data/credentials\n", "")
dockerComposeServicesYaml[currentServiceName]["command"] = newCommand
else:
currentCommand = dockerComposeServicesYaml[currentServiceName]["command"]
if "--paa-root-cert-dir /data/credentials\n" in currentCommand:
newCommand = currentCommand.replace("--paa-root-cert-dir /data/credentials\n", "")
dockerComposeServicesYaml[currentServiceName]["command"] = newCommand

if "/run/dbus:/run/dbus:ro" in dockerComposeServicesYaml[currentServiceName]["volumes"]:
dockerComposeServicesYaml[currentServiceName]["volumes"].remove("/run/dbus:/run/dbus:ro")

currentCommand = dockerComposeServicesYaml[currentServiceName]["command"]
if "--bluetooth-adapter 0\n" in currentCommand:
newCommand = currentCommand.replace("--bluetooth-adapter 0\n", "")
dockerComposeServicesYaml[currentServiceName]["command"] = newCommand
if "/run/dbus:/run/dbus:ro" in dockerComposeServicesYaml[currentServiceName]["volumes"]:
dockerComposeServicesYaml[currentServiceName]["volumes"].remove("/run/dbus:/run/dbus:ro")

currentCommand = dockerComposeServicesYaml[currentServiceName]["command"]
if "--bluetooth-adapter 0\n" in currentCommand:
newCommand = currentCommand.replace("--bluetooth-adapter 0\n", "")
dockerComposeServicesYaml[currentServiceName]["command"] = newCommand

except Exception as err:
print("Error setting pythonMatterServer extras: ", err)
time.sleep(10)
return False
except Exception as err:
print("Error setting pythonMatterServer extras: ", err)
time.sleep(10)
return False
except:
pass



Expand Down

0 comments on commit 57fc352

Please sign in to comment.