view 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
line source
1 from bottle import route, run, template, response
2 import urllib
4 #==============
5 # Persisting the graph to disk
6 #==============
7 @route('/cleargraph')
8 def cleargraph():
9 graphFile = open("syntaxGraph.json", "w")
10 print "opened graph file, which should have cleared it"
11 graphFile.close()
12 response.set_header('Access-Control-Allow-Origin', '*')
14 @route('/save1elem/<thejson>')
15 def save1elem(thejson):
16 thejson = thejson.replace('%T', '\t')
17 thejson = thejson.replace('%N', '\n')
18 thejson = thejson.replace('%H', '\\')
19 thejson = thejson.replace('%S', '/')
20 # print thejson
21 graphFile = open("syntaxGraph.json", "a")
22 graphFile.write("%s\nseparator\n" % thejson)
23 graphFile.close()
24 response.set_header('Access-Control-Allow-Origin', '*')
25 return "ACK"
27 #================
28 # Retrieving graph
29 #================
31 @route('/retrievegraph')
32 def retrieveGraph():
33 graphFile = open("syntaxGraph.json", "r")
34 returnjson = graphFile.read()
35 response.set_header('Access-Control-Allow-Origin', '*')
36 graphFile.close()
37 return returnjson
39 #================
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
45 @route('/endsavinggraph')
46 def endsavinggraph():
47 global graphFile
48 response.set_header('Access-Control-Allow-Origin', '*')
49 graphFile.close()
50 return 'ACK'
52 #Deprecated -- start and end retrieve are deprecated
53 @route('/startretrievinggraph')
54 def startretrievinggraph():
55 global graphFile
56 graphFile = open("syntaxGraph.json", "r")
57 response.set_header('Access-Control-Allow-Origin', '*')
58 return 'ACK'
60 @route('/endretrievinggraph')
61 def endretrievinggraph():
62 global graphFile
63 response.set_header('Access-Control-Allow-Origin', '*')
64 graphFile.close()
65 return 'ACK'
67 #================
69 run(host='localhost', port=8080)