annotate 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
rev   line source
seanhalle@5 1 from bottle import route, run, template, response
seanhalle@6 2 import urllib
seanhalle@5 3
seanhalle@7 4 #==============
seanhalle@8 5 # Persisting the graph to disk
seanhalle@8 6 #==============
seanhalle@8 7 @route('/cleargraph')
seanhalle@8 8 def cleargraph():
seanhalle@7 9 graphFile = open("syntaxGraph.json", "w")
seanhalle@8 10 print "opened graph file, which should have cleared it"
seanhalle@8 11 graphFile.close()
seanhalle@7 12 response.set_header('Access-Control-Allow-Origin', '*')
seanhalle@5 13
seanhalle@5 14 @route('/save1elem/<thejson>')
seanhalle@5 15 def save1elem(thejson):
seanhalle@8 16 thejson = thejson.replace('%T', '\t')
seanhalle@8 17 thejson = thejson.replace('%N', '\n')
seanhalle@8 18 thejson = thejson.replace('%H', '\\')
seanhalle@8 19 thejson = thejson.replace('%S', '/')
seanhalle@8 20 # print thejson
seanhalle@8 21 graphFile = open("syntaxGraph.json", "a")
seanhalle@8 22 graphFile.write("%s\nseparator\n" % thejson)
seanhalle@8 23 graphFile.close()
seanhalle@8 24 response.set_header('Access-Control-Allow-Origin', '*')
seanhalle@8 25 return "ACK"
seanhalle@8 26
seanhalle@8 27 #================
seanhalle@8 28 # Retrieving graph
seanhalle@8 29 #================
seanhalle@8 30
seanhalle@8 31 @route('/retrievegraph')
seanhalle@8 32 def retrieveGraph():
seanhalle@8 33 graphFile = open("syntaxGraph.json", "r")
seanhalle@8 34 returnjson = graphFile.read()
seanhalle@5 35 response.set_header('Access-Control-Allow-Origin', '*')
seanhalle@8 36 graphFile.close()
seanhalle@8 37 return returnjson
seanhalle@5 38
seanhalle@8 39 #================
seanhalle@8 40
seanhalle@8 41 #Deprecated -- at first, tried open via "start" URL, then write, then close
seanhalle@8 42 # here.. but issues in async mode. So now, just "start" clears the file
seanhalle@8 43 # then write opens in append mode, writes, and closes right away.
seanhalle@8 44 #So no longer need the "end" URL
seanhalle@5 45 @route('/endsavinggraph')
seanhalle@5 46 def endsavinggraph():
seanhalle@5 47 global graphFile
seanhalle@5 48 response.set_header('Access-Control-Allow-Origin', '*')
seanhalle@5 49 graphFile.close()
seanhalle@6 50 return 'ACK'
seanhalle@5 51
seanhalle@8 52 #Deprecated -- start and end retrieve are deprecated
seanhalle@5 53 @route('/startretrievinggraph')
seanhalle@5 54 def startretrievinggraph():
seanhalle@5 55 global graphFile
seanhalle@5 56 graphFile = open("syntaxGraph.json", "r")
seanhalle@5 57 response.set_header('Access-Control-Allow-Origin', '*')
seanhalle@6 58 return 'ACK'
seanhalle@5 59
seanhalle@5 60 @route('/endretrievinggraph')
seanhalle@5 61 def endretrievinggraph():
seanhalle@5 62 global graphFile
seanhalle@5 63 response.set_header('Access-Control-Allow-Origin', '*')
seanhalle@5 64 graphFile.close()
seanhalle@6 65 return 'ACK'
seanhalle@5 66
seanhalle@7 67 #================
seanhalle@7 68
seanhalle@5 69 run(host='localhost', port=8080)
seanhalle@7 70