correctly checks for exec-strings in files
parent
c9e710ab9b
commit
ca0920fb44
|
@ -72,25 +72,42 @@ def replaceFiles(targetDir, fileNames, args):
|
||||||
|
|
||||||
return list(fileNames.values())
|
return list(fileNames.values())
|
||||||
|
|
||||||
def appendToActuals(targetDir, fileList, args):
|
def appendToActuals(targetDir, fileList, defaultsGiven, args):
|
||||||
|
if defaultsGiven:
|
||||||
|
classList = [
|
||||||
|
"scout",
|
||||||
|
"soldier",
|
||||||
|
"pyro",
|
||||||
|
"demo",
|
||||||
|
"engi",
|
||||||
|
"heavy",
|
||||||
|
"medic",
|
||||||
|
"sniper",
|
||||||
|
"spy"
|
||||||
|
]
|
||||||
|
for cclass in classList:
|
||||||
|
addCallIfUncalled('exec default_script_1', targetDir, cclass, args)
|
||||||
fileList = onlyFirsts(fileList)
|
fileList = onlyFirsts(fileList)
|
||||||
for currFile in fileList:
|
for currFile in fileList:
|
||||||
execStr = f'exec {currFile.split(".")[0]}'
|
execStr = f'exec {currFile.split(".")[0]}'
|
||||||
realFilePath = targetDir + getRealName(currFile)
|
addCallIfUncalled(execStr, targetDir, currFile, args)
|
||||||
|
|
||||||
realExists = exists(realFilePath)
|
def addCallIfUncalled(execStr, targetDir, fileName, args):
|
||||||
|
realFilePath = targetDir + getRealName(fileName)
|
||||||
|
|
||||||
# creates if it doesn't exist, so must come after the exists() call
|
realExists = exists(realFilePath)
|
||||||
cfgFile = open(realFilePath, 'a+')
|
|
||||||
if not realExists:
|
|
||||||
if args.debug:
|
|
||||||
print( f"DEBUG: Created file {targetDir}{realFilePath}" )
|
|
||||||
cfgFile.write(execStr)
|
|
||||||
|
|
||||||
elif not strInFile(execStr, cfgFile):
|
# creates if it doesn't exist, so must come after the exists() call
|
||||||
cfgFile.write('\n' + execStr)
|
cfgFile = open(realFilePath, 'r+')
|
||||||
|
if not realExists:
|
||||||
|
if args.debug:
|
||||||
|
print( f"DEBUG: Created file {targetDir}{realFilePath}" )
|
||||||
|
cfgFile.write(execStr + '\n')
|
||||||
|
|
||||||
cfgFile.close()
|
elif not strInFile(execStr, cfgFile):
|
||||||
|
cfgFile.write('\n' + execStr + '\n')
|
||||||
|
|
||||||
|
cfgFile.close()
|
||||||
|
|
||||||
def onlyFirsts(fileList):
|
def onlyFirsts(fileList):
|
||||||
for i, fileName in enumerate(fileList):
|
for i, fileName in enumerate(fileList):
|
||||||
|
@ -115,13 +132,11 @@ def getRealName(fileName):
|
||||||
return className + '.cfg'
|
return className + '.cfg'
|
||||||
|
|
||||||
def strInFile(execStr, f):
|
def strInFile(execStr, f):
|
||||||
while True:
|
lineList = [ ' '.join(line.split()) for line in f.readlines() ]
|
||||||
line = f.readline()
|
for line in lineList:
|
||||||
if line == "":
|
|
||||||
# eof
|
|
||||||
break
|
|
||||||
# Remove indent and outdent, including trailing newline
|
# Remove indent and outdent, including trailing newline
|
||||||
if execStr in line.strip():
|
print(line)
|
||||||
|
if execStr == line:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
Loading…
Reference in New Issue