diff --git a/LaunchScript/VirtualAcousticsStarterServer.py b/LaunchScript/VirtualAcousticsStarterServer.py index 46c1524cf8ac41d6519ae41c435b87e7e41c51d7..2d90eaf59cf59779e1f138663faa2e47f59f9907 100644 --- a/LaunchScript/VirtualAcousticsStarterServer.py +++ b/LaunchScript/VirtualAcousticsStarterServer.py @@ -1,5 +1,6 @@ import sys, socket, subprocess, time, os, json from enum import Enum +from configparser import ConfigParser class ErrorCodes(Enum): @@ -8,6 +9,9 @@ class ErrorCodes(Enum): ERROR_INCOMPLETE_CONFIG = 2 ERROR_BINDING_SOCKET = 3 ERROR_CONNECTING_SOCKET = 4 + ERROR_MISSING_VA_INI = 5 + ERROR_INVALID_REPRODUCTION_ID = 6 + ERROR_INCOMPLETE_VA_INI = 7 # Class representing the VA-Launcher config (.json) file class LauncherConfig: @@ -26,6 +30,70 @@ class LauncherConfig: print( "ERROR reading the json config. Missing " + str(e.args[0]) ) sys.exit( ErrorCodes.ERROR_INCOMPLETE_CONFIG ) +class VAComposedIniParser: + def __init__(self, lsReproductionModuleIDs, sRendererIniPath = None): + self.lsReproductionModuleIDs = lsReproductionModuleIDs + self.sRendererIniPath = sRendererIniPath + self.sConfFolder = "../conf/" + + def _create_parser(self): + parser = ConfigParser() + parser.optionxform = str + return parser + + def get_main_inifile(self): + return self.sConfFolder + "VACore.Main.ini" + + def prepare_inis(self): + print("Parsing VA ini-files") + self.link_renderer_ini() + self.prepare_reproduction_ini() + + def link_renderer_ini(self): + if not self.sRendererIniPath: + self.sRendererIniPath = "VARenderer.Default.ini" + + sMainInifile = self.get_main_inifile() + if not os.path.isfile(sMainInifile): + print("ERROR: Could not find 'VACore.Main.ini' in 'conf' folder. Did you delete it?") + sys.exit( ErrorCodes.ERROR_MISSING_VA_INI ) + + rendererIni = self._create_parser() + try: + rendererIni.read( sMainInifile ) + rendererIni["Files"]["VARendererIni"] = self.sRendererIniPath + except Exception as e: + print( "ERROR: " + str(e) ) + sys.exit( ErrorCodes.ERROR_INCOMPLETE_VA_INI ) + + with open( sMainInifile, 'w' ) as inifile: + rendererIni.write(inifile) + + def prepare_reproduction_ini(self): + sFileToRead = self.sConfFolder + "VAReproduction.Prototype.ini" + sFileToWrite = self.sConfFolder + "VAReproduction.ini" + if not os.path.isfile(sFileToRead): + print("ERROR: Could not find 'VAReproduction.Prototype.ini' in 'conf' folder. Did you delete it?") + sys.exit( ErrorCodes.ERROR_MISSING_VA_INI ) + + reproductionIni = self._create_parser() + try: + reproductionIni.read( sFileToRead ) + except Exception as e: + print( "ERROR: " + str(e) ) + sys.exit( ErrorCodes.ERROR_INCOMPLETE_VA_INI ) + + for sReproductionID in self.lsReproductionModuleIDs: + sSection = "Reproduction:" + sReproductionID + if not reproductionIni.has_section(sSection): + print( "ERROR: Reproduction module with ID: '" + sReproductionID + "' not available in respective ini file '" + sFileToRead + "'") + sys.exit( ErrorCodes.ERROR_INVALID_REPRODUCTION_ID ) + reproductionIni[sSection]["Enabled"] = "True" + + with open( sFileToWrite, 'w' ) as inifile: + reproductionIni.write(inifile) + + class VirtualAcousticsLauncher: def __init__(self): print("init")