Check ./cfg directory exists before using.
parent
5328f486fa
commit
5fbd0f75a2
15
cli.py
15
cli.py
|
@ -27,16 +27,27 @@ def parseFile(inputFile):
|
|||
def parseConfig(config):
|
||||
"""With validated data structure, write out all the files."""
|
||||
global args
|
||||
prefix = './cfg'
|
||||
# Make sure ./cfg exists before we try to use it
|
||||
if os.path.isdir( prefix ) == False:
|
||||
try:
|
||||
os.mkdir( prefix )
|
||||
args.debug and print( f'DEBUG: created {prefix}')
|
||||
except Exception as fileExcept:
|
||||
print( f'WARN: Failed to create {prefix}: {fileExcept.strerror}\nUsing current directory instead.' )
|
||||
prefix = '.'
|
||||
|
||||
for currentClass in config:
|
||||
outfile = tempfile.NamedTemporaryFile( prefix=currentClass, delete=False )
|
||||
if args.debug:
|
||||
print( f'created {outfile.name} ')
|
||||
print( f'DEBUG: created temporary {outfile.name} ')
|
||||
|
||||
classDict = config[currentClass]
|
||||
stringToWrite = tfscript.makeCFG(classDict)
|
||||
outfile.write(stringToWrite.encode("utf8"))
|
||||
|
||||
os.replace(outfile.name, f'./cfg/{currentClass}_nscript.txt')
|
||||
os.replace(outfile.name, f'{prefix}/{currentClass}_nscript.txt')
|
||||
args.debug and print( f'DEBUG: Created {prefix}/{currentClass}_nscript.txt')
|
||||
outfile.close()
|
||||
|
||||
# Main function
|
||||
|
|
Loading…
Reference in New Issue