diff --git a/src/tfscript/writing.py b/src/tfscript/writing.py index f5a7411..f2a5cab 100644 --- a/src/tfscript/writing.py +++ b/src/tfscript/writing.py @@ -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 \ No newline at end of file