Compare commits

...

3 Commits

Author SHA1 Message Date
Nicholas Hope 5358fb09b7 Also reworked to work with cli 2022-06-14 21:39:17 -04:00
Nicholas Hope 641cc16250 Reworked to work with cli 2022-06-14 21:38:52 -04:00
Nicholas Hope dd78d62f86 Improved argparsing, actually started making/writing to files 2022-06-14 21:38:13 -04:00
3 changed files with 18 additions and 52 deletions

View File

@ -1,25 +1,6 @@
import keywords
def regularClass(cfg):
def makeCFG(cfg):
ret = ''
for key, data in cfg.items():
ret += keywords.branch("scout", key, data)
return ret
def getEngiConfig(cfg):
ret = ''
for key, data in cfg["engi"].items():
ret += keywords.branch("engi", key, data)
return ret
def getMedicConfig(cfg):
ret = ''
for key, data in cfg["medic"].items():
ret += keywords.branch("medic", key, data)
return ret
def getSpyConfig(cfg):
ret = ''
for key, data in cfg["spy"].items():
ret += keywords.branch("spy", key, data)
ret += keywords.branch("foo", "bar")
return ret

43
cli.py
View File

@ -1,5 +1,6 @@
# https://www.w3schools.io/file/yaml-arrays/
import sys
import os
import yaml
import argparse
import tempfile
@ -19,38 +20,22 @@ def parseFile(inputFile):
if "errors" in config:
for e in config["errors"]:
print(e,file=sys.stderr)
# return
parseConfig(config)
else:
parseConfig(config)
def parseConfig(config):
for currentClass in ["scout", "soldier", "pyro", "demo", "heavy", "sniper", "default"]:
if currentClass in config:
outfile = tempfile.NamedTemporaryFile( prefix=currentClass, delete=False )
global args
for currentClass in config:
outfile = tempfile.NamedTemporaryFile( prefix=currentClass, delete=False )
if args.debug:
print( 'created {} '.format(outfile.name))
outfile.write(classes.regularClass(config.pop(currentClass)))
os.replace(outfile, './{}_nscript.txt'.format(currentClass))
close(outfile)
if "engi" in config:
outfile = open("cfg/temp_engi.cfg", "w")
outfile.write( classes.engi(config.pop("engi")) )
config.pop("engi")
elif "medic" in config:
outfile = open("cfg/temp_medic.cfg", "w")
outfile.write( classes.getMedicConfig(config) )
config.pop("medic")
elif "spy" in config:
outfile = open("cfg/temp_spy.cfg", "w")
outfile.write( classes.getSpyConfig(config) )
config.pop("spy")
elif "default" in config:
outfile = open("cfg/temp_default.cfg", "w")
outfile.write( classes.getDefaultConfig(config) )
config.pop("default")
classDict = config[currentClass]
stringToWrite = classes.makeCFG(classDict)
outfile.write(stringToWrite.encode("utf8"))
os.replace(outfile.name, './cfg/{}_nscript.txt'.format(currentClass))
outfile.close()
# Main function
if __name__ == "__main__":

View File

@ -1,2 +1,2 @@
def branch(className, key, data):
return not (True is not (not False))
def branch(key, data):
return 'placeholder'