Changed how targetDir works for consistency

main
Nicholas Hope 2022-08-15 13:40:01 -04:00
parent ac086e5894
commit 7248acb787
2 changed files with 24 additions and 10 deletions

View File

@ -40,8 +40,10 @@ def parseFile(inputFile) -> (dict, dict):
# See verify.py
config, aliases = verify.verifyConfig(config)
if "errors" in config:
for e in config["errors"]:
print(e, file=stderr)
for cclass, messages in config["errors"].items():
print(f"Error in {cclass}:")
for msg in messages:
print(f" {msg}")
return None, None
else:
return config, aliases
@ -59,7 +61,7 @@ def parseConfig(config, defaults):
tempsAndReals = {}
if defaults is not None:
stringToWrite = tfscript.makeCFG(defaults)
stringToWrite = tfscript.makeCFG(defaults, default=True)
replaceDict = writing.writeOutput(stringToWrite, "default", args)
tempsAndReals.update(replaceDict)
@ -129,10 +131,15 @@ def main() -> int:
parser = parseCLI()
args = parser.parse_args()
systemName = GetOSName()
if args.directory is not None:
targetDir = args.directory
targetDir = normpath(args.directory)
if systemName == "Windows":
targetDir += '\\'
else:
targetDir += '/'
else:
systemName = GetOSName()
targetDir = getTargetDir(systemName)
if targetDir is not None:
# Supported OS: add steamapps path

View File

@ -55,7 +55,7 @@ def writeOutput(data, className, args) -> dict:
outfile.close() # the most-recent tempfile will not have been closed
if args.debug:
print( f'DEBUG: Wrote {bytesWritten} bytes to {className} ({fileNum}/{filesNeeded})', file=stderr)
print( f'DEBUG: Wrote {bytesWritten} bytes to {className} ({fileNum}/{filesNeeded})', end='\n\n', file=stderr)
return namesDict
@ -70,6 +70,10 @@ def replaceFiles(targetDir, fileNames, args):
if args.debug:
print( f'DEBUG: Created {targetDir}{realName}', file=stderr)
if args.debug:
# Break up the debug messages
print(end='\n')
return list(fileNames.values())
def appendToActuals(targetDir, fileList, defaultsGiven, args):
@ -87,6 +91,7 @@ def appendToActuals(targetDir, fileList, defaultsGiven, args):
]
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]}'
@ -98,10 +103,10 @@ def addCallIfUncalled(execStr, targetDir, fileName, args):
realExists = exists(realFilePath)
# creates if it doesn't exist, so must come after the exists() call
cfgFile = open(realFilePath, 'r+')
cfgFile = open(realFilePath, 'a+')
if not realExists:
if args.debug:
print( f"DEBUG: Created file {targetDir}{realFilePath}" )
print( f"DEBUG: Created {realFilePath}" )
cfgFile.write(execStr + '\n')
elif not strInFile(execStr, cfgFile):
@ -132,10 +137,12 @@ def getRealName(fileName):
return className + '.cfg'
def strInFile(execStr, f):
lineList = [ ' '.join(line.split()) for line in f.readlines() ]
# Opened in append mode, so cursor is at the end.
# Must reopen to put cursor at the start.
with open(f.name, 'r') as dupfile:
lineList = [ ' '.join(line.split()) for line in dupfile.readlines() ]
for line in lineList:
# Remove indent and outdent, including trailing newline
print(line)
if execStr == line:
return True