diff --git a/.templates/otbr/build.py b/.templates/otbr/build.py index bb15b805..cecdf58c 100755 --- a/.templates/otbr/build.py +++ b/.templates/otbr/build.py @@ -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 diff --git a/.templates/python-matter-server/build.py b/.templates/python-matter-server/build.py index ce5ce21a..261aceb8 100755 --- a/.templates/python-matter-server/build.py +++ b/.templates/python-matter-server/build.py @@ -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