Mercurial > hg > webaudioevaluationtool
comparison python/pythonServer.py @ 2997:a10cbbccc4f3
#193. Partial files save with prefix ‘update’. Partials are deleted once full test is submitted and saved.
author | Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk> |
---|---|
date | Wed, 02 Aug 2017 08:50:19 +0100 |
parents | a087cb7b5972 |
children | 03b0e5dc57e6 |
comparison
equal
deleted
inserted
replaced
2996:eaa5dc4aedbf | 2997:a10cbbccc4f3 |
---|---|
136 def saveFile(self): | 136 def saveFile(self): |
137 global curFileName | 137 global curFileName |
138 global curSaveIndex | 138 global curSaveIndex |
139 options = self.path.rsplit('?') | 139 options = self.path.rsplit('?') |
140 options = options[1].rsplit('&') | 140 options = options[1].rsplit('&') |
141 update = False | |
141 for option in options: | 142 for option in options: |
142 optionPair = option.rsplit('=') | 143 optionPair = option.rsplit('=') |
143 if optionPair[0] == "key": | 144 if optionPair[0] == "key": |
144 key = optionPair[1] | 145 key = optionPair[1] |
145 elif optionPair[0] == "saveFilenamePrefix": | 146 elif optionPair[0] == "saveFilenamePrefix": |
146 prefix = optionPair[1] | 147 prefix = optionPair[1] |
148 elif optionPair[0] == "state": | |
149 update = optionPair[1] == "update" | |
147 if key == None: | 150 if key == None: |
148 self.send_response(404) | 151 self.send_response(404) |
149 return | 152 return |
150 if prefix == None: | 153 if prefix == None: |
151 prefix = "save" | 154 prefix = "save" |
152 varLen = int(self.headers['Content-Length']) | 155 varLen = int(self.headers['Content-Length']) |
153 postVars = self.rfile.read(varLen) | 156 postVars = self.rfile.read(varLen) |
154 print("Saving file key "+key) | 157 print("Saving file key "+key) |
155 filename = prefix+'-'+key+'.xml' | 158 filename = prefix+'-'+key+'.xml' |
159 if update: | |
160 filename = "update-"+filename | |
156 file = open('../saves/'+filename,'wb') | 161 file = open('../saves/'+filename,'wb') |
157 file.write(postVars) | 162 file.write(postVars) |
158 file.close() | 163 file.close() |
159 try: | 164 try: |
160 wbytes = os.path.getsize('../saves/'+filename) | 165 wbytes = os.path.getsize('../saves/'+filename) |
171 self.wfile.write(reply) | 176 self.wfile.write(reply) |
172 elif sys.version_info[0] == 3: | 177 elif sys.version_info[0] == 3: |
173 self.wfile.write(bytes(reply, "utf-8")) | 178 self.wfile.write(bytes(reply, "utf-8")) |
174 curSaveIndex += 1 | 179 curSaveIndex += 1 |
175 curFileName = 'test-'+str(curSaveIndex)+'.xml' | 180 curFileName = 'test-'+str(curSaveIndex)+'.xml' |
181 if update == False: | |
182 os.remove("../saves/update-"+filename) | |
176 | 183 |
177 def poolXML(s): | 184 def poolXML(s): |
178 pool = ET.parse('../tests/pool.xml') | 185 pool = ET.parse('../tests/pool.xml') |
179 root = pool.getroot() | 186 root = pool.getroot() |
180 setupNode = root.find("setup"); | 187 setupNode = root.find("setup"); |