Mercurial > cgi-bin > hgwebdir.cgi > POP > oldRepo
diff 1__Development/6__Website/POPBottleServer/POPBottleServer.py @ 5:e73fbbcb5fd2
Persisting basic graph works, starting to add persist of view hierarchy too
| author | Sean Halle <seanhalle@yahoo.com> |
|---|---|
| date | Sun, 03 Aug 2014 23:38:15 -0700 |
| parents | |
| children | d18eee376f45 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/1__Development/6__Website/POPBottleServer/POPBottleServer.py Sun Aug 03 23:38:15 2014 -0700 1.3 @@ -0,0 +1,72 @@ 1.4 +from bottle import route, run, template, response 1.5 + 1.6 +graphFile = None 1.7 + 1.8 +@route('/') 1.9 +def index(): 1.10 + return '<b>Hello</b>!' 1.11 + 1.12 +@route('/<name>') 1.13 +@route('/hello/<name>') 1.14 +def nameroute(name): 1.15 + return template('<b>Hello {{name}}</b>!', name=name) 1.16 + 1.17 +@route('/savejson/<thejson>') 1.18 +def savejson(thejson): 1.19 + text_file = open("syntaxGraph.json", "w") 1.20 + text_file.write("%s" % thejson) 1.21 + text_file.close() 1.22 + print "hello" 1.23 + response.set_header('Access-Control-Allow-Origin', '*') 1.24 +# return 'Got JSON!' 1.25 +# return template('Got JSON! {{printjson}}</b>!', printjson = thejson) 1.26 + 1.27 +@route('/getjson') 1.28 +def getjson(): 1.29 + text_file = open("syntaxGraph.json", "r") 1.30 + returnjson = text_file.read() 1.31 + text_file.close() 1.32 + response.set_header('Access-Control-Allow-Origin', '*') 1.33 + return returnjson 1.34 + 1.35 +#=============== 1.36 +@route('/startsavinggraph') 1.37 +def startsavinggraph(): 1.38 + global graphFile 1.39 + graphFile = open("syntaxGraph.json", "w") 1.40 + response.set_header('Access-Control-Allow-Origin', '*') 1.41 + 1.42 +@route('/save1elem/<thejson>') 1.43 +def save1elem(thejson): 1.44 + global graphFile 1.45 + graphFile.write("%s\n" % thejson) 1.46 + response.set_header('Access-Control-Allow-Origin', '*') 1.47 + 1.48 +@route('/endsavinggraph') 1.49 +def endsavinggraph(): 1.50 + global graphFile 1.51 + response.set_header('Access-Control-Allow-Origin', '*') 1.52 + graphFile.close() 1.53 + 1.54 +#================ 1.55 + 1.56 +@route('/startretrievinggraph') 1.57 +def startretrievinggraph(): 1.58 + global graphFile 1.59 + graphFile = open("syntaxGraph.json", "r") 1.60 + response.set_header('Access-Control-Allow-Origin', '*') 1.61 + 1.62 +@route('/get1elem') 1.63 +def get1elem(): 1.64 + global graphFile 1.65 + returnjson = graphFile.readline() 1.66 + response.set_header('Access-Control-Allow-Origin', '*') 1.67 + return returnjson 1.68 + 1.69 +@route('/endretrievinggraph') 1.70 +def endretrievinggraph(): 1.71 + global graphFile 1.72 + response.set_header('Access-Control-Allow-Origin', '*') 1.73 + graphFile.close() 1.74 + 1.75 +run(host='localhost', port=8080)
