comparison 1__Development/6__Website/POPBottleServer/POPBottleServer.py @ 9:a8e5e71adcf3

Maintenance.. been a while.. lots of stuff
author Sean Halle <seanhalle@yahoo.com>
date Sun, 07 Dec 2014 12:38:00 -0800
parents 20a1407463a0
children
comparison
equal deleted inserted replaced
2:caf24fe792fe 3:04542a0dfe68
1 from bottle import route, run, template, response 1 from bottle import route, run, template, response
2 import urllib 2 import urllib
3 3
4 graphFile = None
5
6 #============== 4 #==============
7 5 # Persisting the graph to disk
8 @route('/startsavinggraph') 6 #==============
9 def startsavinggraph(): 7 @route('/cleargraph')
10 global graphFile 8 def cleargraph():
11 graphFile = open("syntaxGraph.json", "w") 9 graphFile = open("syntaxGraph.json", "w")
12 print "opened graph file " 10 print "opened graph file, which should have cleared it"
13 print "Name of the file: ", graphFile.name 11 graphFile.close()
14 print "Closed or not : ", graphFile.closed
15 print "Opening mode : ", graphFile.mode
16 print "Softspace flag : ", graphFile.softspace
17 response.set_header('Access-Control-Allow-Origin', '*') 12 response.set_header('Access-Control-Allow-Origin', '*')
18 13
19 @route('/save1elem/<thejson>') 14 @route('/save1elem/<thejson>')
20 def save1elem(thejson): 15 def save1elem(thejson):
21 thejson = thejson.replace('%T', '\t') 16 thejson = thejson.replace('%T', '\t')
22 thejson = thejson.replace('%N', '\n') 17 thejson = thejson.replace('%N', '\n')
23 thejson = thejson.replace('%H', '\\') 18 thejson = thejson.replace('%H', '\\')
24 thejson = thejson.replace('%S', '/') 19 thejson = thejson.replace('%S', '/')
25 # print thejson 20 # print thejson
26 global graphFile 21 graphFile = open("syntaxGraph.json", "a")
27 graphFile.write("%s\nend elem\n" % thejson) 22 graphFile.write("%s\nseparator\n" % thejson)
23 graphFile.close()
24 response.set_header('Access-Control-Allow-Origin', '*')
25 return "ACK"
26
27 #================
28 # Retrieving graph
29 #================
30
31 @route('/retrievegraph')
32 def retrieveGraph():
33 graphFile = open("syntaxGraph.json", "r")
34 returnjson = graphFile.read()
28 response.set_header('Access-Control-Allow-Origin', '*') 35 response.set_header('Access-Control-Allow-Origin', '*')
36 graphFile.close()
37 return returnjson
29 38
39 #================
40
41 #Deprecated -- at first, tried open via "start" URL, then write, then close
42 # here.. but issues in async mode. So now, just "start" clears the file
43 # then write opens in append mode, writes, and closes right away.
44 #So no longer need the "end" URL
30 @route('/endsavinggraph') 45 @route('/endsavinggraph')
31 def endsavinggraph(): 46 def endsavinggraph():
32 global graphFile 47 global graphFile
33 response.set_header('Access-Control-Allow-Origin', '*') 48 response.set_header('Access-Control-Allow-Origin', '*')
34 graphFile.close() 49 graphFile.close()
35 return 'ACK' 50 return 'ACK'
36 51
37 #================ 52 #Deprecated -- start and end retrieve are deprecated
38
39 @route('/startretrievinggraph') 53 @route('/startretrievinggraph')
40 def startretrievinggraph(): 54 def startretrievinggraph():
41 global graphFile 55 global graphFile
42 graphFile = open("syntaxGraph.json", "r") 56 graphFile = open("syntaxGraph.json", "r")
43 response.set_header('Access-Control-Allow-Origin', '*') 57 response.set_header('Access-Control-Allow-Origin', '*')
44 return 'ACK' 58 return 'ACK'
45
46 @route('/get1elem')
47 def get1elem():
48 global graphFile
49 returnjson = graphFile.readline()
50 response.set_header('Access-Control-Allow-Origin', '*')
51 return returnjson
52 59
53 @route('/endretrievinggraph') 60 @route('/endretrievinggraph')
54 def endretrievinggraph(): 61 def endretrievinggraph():
55 global graphFile 62 global graphFile
56 response.set_header('Access-Control-Allow-Origin', '*') 63 response.set_header('Access-Control-Allow-Origin', '*')