diff options
Diffstat (limited to 'competition.py')
-rwxr-xr-x | competition.py | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/competition.py b/competition.py index 3a21115..7c48846 100755 --- a/competition.py +++ b/competition.py @@ -9,10 +9,11 @@ The script writes a competitionlog to competitions/game_p1_vs_p2.txt (with p1 and p2 replaced by their respective commands). Options: - -C Do not write a Competition log - -h Help. What you're looking at - -q Quiet. Don't print so much - -V Do not view the competition, so don't write an html file + -c <file> Write the Competition log to the specified file instead of the default + -C Do not write a Competition log + -h Help. What you're looking at + -q Quiet. Don't print so much + -V Do not view the competition, so don't write an html file """ import os,sys,subprocess,shlex,re,time @@ -117,13 +118,22 @@ fname="" quiet=False viewcompetition=True complog=True +logfname=None + +nextIsLogfname=False if len(sys.argv)==1: #no args fname="competition.txt" else: for arg in sys.argv[1:]: #skip script name + if nextIsLogfname: + logfname=arg + nextIsLogfname=False + continue if len(arg)>1 and arg[0]=="-": for c in arg[1:]: #skip "-" - if c=="C": + if c=="c": + nextIsLogfname=True + elif c=="C": complog=False elif c=="h": print(__doc__) @@ -140,6 +150,10 @@ else: print("Unrecognised argument '"+arg+"'; the competition file name was already given as '"+fname+"'.") sys.exit(1) +if nextIsLogfname: + print("Missing argument to -c flag") + sys.exit(1) + if fname=="-": if not quiet: print("Getting entries from stdin.") p1fname="" @@ -222,7 +236,8 @@ elif not os.path.isdir("competitions"): sys.exit(1) try: - logfname="competitions"+os.path.sep+"game_"+re.sub(r"[^a-zA-Z0-9 ]","",p1fname)+"_vs_"+re.sub(r"[^a-zA-Z0-9 ]","",p2fname)+".txt" + if logfname==None: + logfname="competitions"+os.path.sep+"game_"+re.sub(r"[^a-zA-Z0-9 ]","",p1fname)+"_vs_"+re.sub(r"[^a-zA-Z0-9 ]","",p2fname)+".txt" logfile=open(logfname,mode="w") logfile.write("P1: "+p1fname+"\nP2: "+p2fname+"\n") except: @@ -359,4 +374,4 @@ if viewcompetition: #Apparently, there's a file named "gamevisuals". Bastard. print("Error: an existing file prohibits creation of log directory 'gamevisuals'.") sys.exit(1) - os.system("."+os.path.sep+"viewcompetition "+logfname+" >gamevisuals"+os.path.sep+logfname[logfname.index(os.path.sep)+1:]+".html") + os.system("."+os.path.sep+"viewcompetition "+logfname+" >gamevisuals"+os.path.sep+"game_"+re.sub(r"[^a-zA-Z0-9 ]","",p1fname)+"_vs_"+re.sub(r"[^a-zA-Z0-9 ]","",p2fname)+".html") |