git.ucc.asn.au
/
progcomp2013.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix the index
[progcomp2013.git]
/
qchess
/
qchess.cgi
diff --git
a/qchess/qchess.cgi
b/qchess/qchess.cgi
index
993a36e
..
035dce0
100755
(executable)
--- a/
qchess/qchess.cgi
+++ b/
qchess/qchess.cgi
@@
-1,4
+1,4
@@
-#!/usr/bin/python
+#!/usr/bin/python
-u
# CGI wrapper to qchess
# CGI wrapper to qchess
@@
-6,10
+6,10
@@
import sys
import os
import cgi
import os
import cgi
-import subprocess
import time
import threading
import datetime
import time
import threading
import datetime
+import subprocess
path = "../qchess-cgi-data/"
path = "../qchess-cgi-data/"
@@
-71,6
+71,10
@@
def open_fifo(name, mode, timeout=None):
raise w.exception
return w.result
raise w.exception
return w.result
+def force_quit():
+ os.remove(path+client+".in")
+ os.remove(path+client+".out")
+
def quit():
if os.path.exists(path+client+".in") and os.path.exists(path+client+".out"):
def quit():
if os.path.exists(path+client+".in") and os.path.exists(path+client+".out"):
@@
-105,7
+109,7
@@
def quit():
def main(argv):
def main(argv):
- print "Content-Type: text/plain\r\n
\r\n"
+ print "Content-Type: text/plain\r\n
" #Removed the second new line. Makes parsing everything easier ~BG3
global client
form = cgi.FieldStorage()
global client
form = cgi.FieldStorage()
@@
-119,24
+123,29
@@
def main(argv):
try:
#request = argv[1]
try:
#request = argv[1]
- request = form["r"]
+ request = form["r"]
.value
except:
request = None
mode = None
else:
try:
except:
request = None
mode = None
else:
try:
- mode = form["m"]
+ mode = form["m"]
.value
except:
mode = None
except:
mode = None
+
try:
#x = int(argv[1])
#y = int(argv[2])
try:
#x = int(argv[1])
#y = int(argv[2])
- x =
form["x"]
- y =
form["y"]
+ x =
int(form["x"].value)
+ y =
int(form["y"].value)
except:
except:
-
+ if request == "force_quit":
+ force_quit()
+ quit()
+ return 0
+
if os.path.exists(path+client+".in") and os.path.exists(path+client+".out"):
if request == "quit":
print "Quit."
if os.path.exists(path+client+".in") and os.path.exists(path+client+".out"):
if request == "quit":
print "Quit."
@@
-147,14
+156,24
@@
def main(argv):
return 1
elif request == "start":
print "New game."
return 1
elif request == "start":
print "New game."
- args = [path+"qchess.py", "--no-graphics"]
- if mode == None or mode == "bishop":
- args += ["@fifo:../qchess-cgi-data/"+client, "@internal:AgentBishop"]
- if mode == "random":
- args += ["@fifo:../qchess-cgi-data/"+client, "@internal:AgentRandom"]
+ args = path+"qchess.py --no-graphics"
+ if mode == "black":
+ args += " @internal:AgentBishop @fifo:../qchess-cgi-data/"+client
+ elif mode == None or mode == "bishop":
+ args += " @fifo:../qchess-cgi-data/"+client+" @internal:AgentBishop"
+ elif mode == "random":
+ args += " @fifo:../qchess-cgi-data/"+client+" @internal:AgentRandom"
elif mode == "eigengame":
elif mode == "eigengame":
- args += ["--server=progcomp.ucc.asn.au", "@fifo:../qchess-cgi-data/"+client]
- subprocess.Popen(args)
+ args += " --server=progcomp.ucc.asn.au @fifo:../qchess-cgi-data/"+client
+
+ args += " --log=@../qchess-cgi-data/"+client+".log";
+
+ os.system("echo '"+args+"' | at now")
+
+ # subprocess.Popen(args)
+ # os.spawnl(os.P_NOWAIT, args)
+
+
time.sleep(1)
log = open(path+client, "a")
time.sleep(1)
log = open(path+client, "a")
@@
-186,12
+205,13
@@
def main(argv):
except:
quit()
else:
except:
quit()
else:
- #
sys.stderr.write("O
pened fine\n")
+ #
sys.stderr.write("cgi o
pened fine\n")
s = fifo_in.readline().strip(" \r\n")
s = fifo_in.readline().strip(" \r\n")
-
+ #sys.stderr.write("cgi read first line: "+str(s)+"\n")
while s != "SELECT?" and s != "MOVE?" and not s.split(" ")[0] in ["white","black"]:
if s != "":
print s
while s != "SELECT?" and s != "MOVE?" and not s.split(" ")[0] in ["white","black"]:
if s != "":
print s
+ # sys.stderr.write("Read: " + str(s) + "\n")
s = fifo_in.readline().strip(" \r\n")
print s
s = fifo_in.readline().strip(" \r\n")
print s
@@
-200,7
+220,7
@@
def main(argv):
#sys.stderr.write("cgi quit!\n")
quit()
#sys.stderr.write("cgi quit!\n")
quit()
- #sys.stderr.write("Done\n")
+ #sys.stderr.write("
cgi qchess
Done\n")
return 0
return 0
@@
-209,5
+229,5
@@
if __name__ == "__main__":
sys.exit(main(sys.argv))
except Exception, e:
print e
sys.exit(main(sys.argv))
except Exception, e:
print e
- sys.stderr.write(str(e) + "\n")
+ sys.stderr.write(s
ys.argv[0] + ": " + s
tr(e) + "\n")
sys.exit(1)
sys.exit(1)
UCC
git Repository :: git.ucc.asn.au