correctly checks for exec-strings in files

main
Nicholas Hope 2022-08-14 15:48:09 -04:00
parent c9e710ab9b
commit ca0920fb44
1 changed files with 33 additions and 18 deletions

View File

@ -72,25 +72,42 @@ def replaceFiles(targetDir, fileNames, args):
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)
for currFile in fileList:
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
cfgFile = open(realFilePath, 'a+')
if not realExists:
if args.debug:
print( f"DEBUG: Created file {targetDir}{realFilePath}" )
cfgFile.write(execStr)
realExists = exists(realFilePath)
elif not strInFile(execStr, cfgFile):
cfgFile.write('\n' + execStr)
# creates if it doesn't exist, so must come after the exists() call
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):
for i, fileName in enumerate(fileList):
@ -115,13 +132,11 @@ def getRealName(fileName):
return className + '.cfg'
def strInFile(execStr, f):
while True:
line = f.readline()
if line == "":
# eof
break
lineList = [ ' '.join(line.split()) for line in f.readlines() ]
for line in lineList:
# Remove indent and outdent, including trailing newline
if execStr in line.strip():
print(line)
if execStr == line:
return True
return False