Mercurial > hg > webaudioevaluationtool
comparison pythonServer.py @ 1552:fbd8b526c97d
PythonServer now supports pseudorandom page setup using preconfigured XML files. Set the PSEUDO_PATH in the python file, it will cycle through all .xml files in there. Index based off file save number. Set the .html url to /pseudo.xml to trigger
author | Nicholas Jillings <nickjillings@users.noreply.github.com> |
---|---|
date | Sun, 28 Jun 2015 10:33:47 +0100 |
parents | 76dece6eff10 |
children | a2800d0b5656 b7fd0296c6ab |
comparison
equal
deleted
inserted
replaced
1551:76dece6eff10 | 1552:fbd8b526c97d |
---|---|
1 import BaseHTTPServer | 1 import BaseHTTPServer |
2 from os import walk | 2 from os import walk |
3 from os import path | 3 from os import path |
4 from os import listdir | |
4 import urllib2 | 5 import urllib2 |
5 import pickle | 6 import pickle |
6 import datetime | 7 import datetime |
8 | |
9 PSEUDO_PATH = 'example_eval/' | |
10 pseudo_files = [] | |
11 for filename in listdir(PSEUDO_PATH): | |
12 if filename.endswith('.xml'): | |
13 pseudo_files.append(filename) | |
7 | 14 |
8 curSaveIndex = 0; | 15 curSaveIndex = 0; |
9 curFileName = 'test-0.xml' | 16 curFileName = 'test-0.xml' |
10 while(path.isfile('saves/'+curFileName)): | 17 while(path.isfile('saves/'+curFileName)): |
11 curSaveIndex += 1; | 18 curSaveIndex += 1; |
12 curFileName = 'test-'+str(curSaveIndex)+'.xml' | 19 curFileName = 'test-'+str(curSaveIndex)+'.xml' |
13 | 20 |
14 print curFileName | 21 print "Next save - " + curFileName |
22 pseudo_index = curSaveIndex % len(pseudo_files) | |
23 print "Next test - " + pseudo_files[pseudo_index] | |
15 | 24 |
16 def send404(s): | 25 def send404(s): |
17 s.send_response(404) | 26 s.send_response(404) |
18 s.send_header("Content-type", "text/html") | 27 s.send_header("Content-type", "text/html") |
19 s.end_headers() | 28 s.end_headers() |
57 self.end_headers() | 66 self.end_headers() |
58 self.wfile.write('<response><state>OK</state><file>saves/'+curFileName+'</file></response>') | 67 self.wfile.write('<response><state>OK</state><file>saves/'+curFileName+'</file></response>') |
59 | 68 |
60 class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler): | 69 class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler): |
61 def do_HEAD(s): | 70 def do_HEAD(s): |
62 s.send_response(200) | 71 s.send_response(200) |
63 s.send_header("Content-type", "text/html") | 72 s.send_header("Content-type", "text/html") |
64 s.end_headers() | 73 s.end_headers() |
65 def do_GET(request): | 74 def do_GET(request): |
75 global pseudo_index | |
76 global pseudo_files | |
77 global PSEUDO_PATH | |
66 if(request.client_address[0] == "127.0.0.1"): | 78 if(request.client_address[0] == "127.0.0.1"): |
67 if (request.path == "/favicon.ico"): | 79 if (request.path == "/favicon.ico"): |
68 send404(request) | 80 send404(request) |
69 else: | 81 else: |
70 if (request.path == '/'): | 82 if (request.path == '/'): |
71 request.path = '/index.html' | 83 request.path = '/index.html' |
84 elif (request.path == '/pseudo.xml'): | |
85 request.path = '/'+PSEUDO_PATH + pseudo_files[pseudo_index] | |
86 print request.path | |
87 pseudo_index += 1 | |
88 pseudo_index %= len(pseudo_files) | |
72 processFile(request) | 89 processFile(request) |
73 else: | 90 else: |
74 send404(request) | 91 send404(request) |
92 | |
75 def do_POST(request): | 93 def do_POST(request): |
76 if(request.client_address[0] == "127.0.0.1"): | 94 if(request.client_address[0] == "127.0.0.1"): |
77 if (request.path == "/save"): | 95 if (request.path == "/save"): |
78 saveFile(request) | 96 saveFile(request) |
79 else: | 97 else: |