Mise à jour de 'DoConfig.py'
+ add feature to order keys in sections by key names (=> for ServerActors and ServerPackages) +fix ServerActors and ServerPackages behavior
This commit is contained in:
72
DoConfig.py
72
DoConfig.py
@@ -12,9 +12,36 @@ from os.path import join
|
||||
|
||||
|
||||
from pprint import pprint
|
||||
from ChaChaSimpleINI import ChaChaSimpleINI,ChaChaINI_KeyNotFoundException
|
||||
from ChaChaSimpleINI import ChaChaSimpleINI,ChaChaINI_KeyNotFoundException,ChaChaINI_SectionNotFoundException,ChaChaSimpleINI_section,ChaChaSimpleINI_key
|
||||
from abc import ABCMeta,abstractmethod
|
||||
|
||||
class ChaChaSimpleINI_UT(ChaChaSimpleINI):
|
||||
def GroupKeysInSection(self,szSectionName,szKeyName):
|
||||
try:
|
||||
_section=self.getSection(szSectionName)
|
||||
if type(_section) is ChaChaSimpleINI_section:
|
||||
ar_ServerPackages = _section.getKey(szKeyName)
|
||||
if isinstance(ar_ServerPackages,ChaChaSimpleINI_key):
|
||||
ar_ServerPackages = [ar_ServerPackages]
|
||||
else: #array
|
||||
pass
|
||||
for ServerPackages in ar_ServerPackages:
|
||||
_section.delKey(ServerPackages.name,None,ServerPackages.value)
|
||||
for ServerPackages in ar_ServerPackages:
|
||||
_section.setAddKeyValue(ServerPackages.name,ServerPackages.value,True)
|
||||
except ChaChaINI_SectionNotFoundException:
|
||||
pass
|
||||
|
||||
def writeFile(self,bBeautify:bool = False) -> None:
|
||||
self.GroupKeysInSection("XC_Engine.XC_GameEngine","ServerPackages")
|
||||
self.GroupKeysInSection("XC_Engine.XC_GameEngine","ServerActors")
|
||||
self.GroupKeysInSection("Engine.GameEngine","ServerPackages")
|
||||
self.GroupKeysInSection("Engine.GameEngine","ServerActors")
|
||||
self.GroupKeysInSection("Core.System","Suppress")
|
||||
self.GroupKeysInSection("Editor.EditorEngine","EditPackages")
|
||||
super().writeFile(bBeautify)
|
||||
|
||||
|
||||
class OptionType(Enum):
|
||||
OT_INVALID = 0
|
||||
OT_STRING = 1
|
||||
@@ -115,7 +142,7 @@ class GameOption_UT99(GameOption):
|
||||
def set(self,value:str):
|
||||
if not self.szOptionName:
|
||||
raise RuntimeError("szOptionName is not set")
|
||||
inifile = ChaChaSimpleINI(self. mainConfigFilePath)
|
||||
inifile = ChaChaSimpleINI_UT(self.mainConfigFilePath)
|
||||
inifile.setAddKeyValue(self.szSectionName,self.szKeyName,value,self.bForceAdd)
|
||||
inifile.writeFile()
|
||||
|
||||
@@ -124,7 +151,7 @@ class GameOption_UT99(GameOption):
|
||||
raise RuntimeError("szOptionName is not set")
|
||||
if not self.bRemovable:
|
||||
raise RuntimeError("this options is not removable")
|
||||
inifile = ChaChaSimpleINI(self. mainConfigFilePath)
|
||||
inifile = ChaChaSimpleINI(self.mainConfigFilePath)
|
||||
inifile.delKeyEx(self.szSectionName,self.szKeyName,None,value)
|
||||
inifile.writeFile()
|
||||
|
||||
@@ -132,13 +159,12 @@ class GameOption_UT99(GameOption):
|
||||
if not self.szOptionName:
|
||||
raise RuntimeError("szOptionName not set")
|
||||
print("get option <{0}>".format(self.szOptionName))
|
||||
inifile = ChaChaSimpleINI(self. mainConfigFilePath)
|
||||
inifile = ChaChaSimpleINI(self.mainConfigFilePath)
|
||||
res = inifile.getKeyValue(self.szSectionName,self.szKeyName)
|
||||
return res
|
||||
|
||||
class GameOption_UT99_GenAdd(GameOption_UT99):
|
||||
bForceAdd = True
|
||||
|
||||
def rem(self,value:str):
|
||||
try:
|
||||
super().rem(value)
|
||||
@@ -146,7 +172,8 @@ class GameOption_UT99_GenAdd(GameOption_UT99):
|
||||
pass
|
||||
|
||||
def set(self,value:str):
|
||||
self.rem(value)
|
||||
#force to call the rem method of THIS level
|
||||
GameOption_UT99_GenAdd.rem(self,value)
|
||||
super().set(value)
|
||||
|
||||
class GameOption_UT99_GenAdd__Engine(GameOption_UT99_GenAdd):
|
||||
@@ -154,18 +181,33 @@ class GameOption_UT99_GenAdd__Engine(GameOption_UT99_GenAdd):
|
||||
TValueType = OptionType.OT_STRING
|
||||
bRemovable = True
|
||||
def set(self,value:str):
|
||||
prev = self.szSectionName
|
||||
|
||||
inifile = ChaChaSimpleINI(self.mainConfigFilePath)
|
||||
try:
|
||||
inifile.getSection("XC_Engine.XC_GameEngine")
|
||||
self.szSectionName = "XC_Engine.XC_GameEngine"
|
||||
super().set(value)
|
||||
except ChaChaINI_SectionNotFoundException:
|
||||
pass
|
||||
|
||||
self.szSectionName = "Engine.GameEngine"
|
||||
super().set(value)
|
||||
self.szSectionName = "XC_Engine.XC_GameEngine"
|
||||
super().set(value)
|
||||
self.szSectionName = "Engine.GameEngine"
|
||||
self.szSectionName = prev
|
||||
|
||||
def rem(self,value:str):
|
||||
def rem(self,value:str):
|
||||
prev = self.szSectionName
|
||||
|
||||
inifile = ChaChaSimpleINI(self.mainConfigFilePath)
|
||||
try:
|
||||
inifile.getSection("XC_Engine.XC_GameEngine")
|
||||
self.szSectionName = "XC_Engine.XC_GameEngine"
|
||||
super().rem(value)
|
||||
except ChaChaINI_SectionNotFoundException:
|
||||
pass
|
||||
self.szSectionName = "Engine.GameEngine"
|
||||
super().rem(value)
|
||||
self.szSectionName = "XC_Engine.XC_GameEngine"
|
||||
super().rem(value)
|
||||
self.szSectionName = "Engine.GameEngine"
|
||||
self.szSectionName = prev
|
||||
|
||||
|
||||
@GameOptions_Factory_Register
|
||||
@@ -350,13 +392,13 @@ class GameOption_UT99_ServerLogName(GameOption_UT99):
|
||||
class GameOption_UT99_WebServer(GameOption_UT99):
|
||||
szOptionName = "WebServer"
|
||||
szSectionName = "UWeb.WebServer"
|
||||
szKeyName = "Listenport"
|
||||
szKeyName = "ListenPort"
|
||||
TValueType = OptionType.OT_INTEGER
|
||||
szDefaultValue = "8076"
|
||||
szHelp = "enable Web Server"
|
||||
def set(self,value:str):
|
||||
super().set(value)
|
||||
inifile = ChaChaSimpleINI(self. mainConfigFilePath)
|
||||
inifile = ChaChaSimpleINI(self.mainConfigFilePath)
|
||||
if int(value) > 0:
|
||||
inifile.setAddKeyValue("UWeb.WebServer","bEnabled","True")
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user