Skip to content
Snippets Groups Projects
Commit e5b2768c authored by Philipp Schäfer's avatar Philipp Schäfer
Browse files

Launcher: adding class allowing to parse data into composed VA config

- in VACore.Main.ini: sets the renderer ini file
- Creates copy of reproduction ini file and enables desired reproduction modules
parent ee195f95
Branches
No related tags found
No related merge requests found
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")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment