seanhalle@5: from bottle import route, run, template, response seanhalle@6: import urllib seanhalle@5: seanhalle@7: #============== seanhalle@8: # Persisting the graph to disk seanhalle@8: #============== seanhalle@8: @route('/cleargraph') seanhalle@8: def cleargraph(): seanhalle@7: graphFile = open("syntaxGraph.json", "w") seanhalle@8: print "opened graph file, which should have cleared it" seanhalle@8: graphFile.close() seanhalle@7: response.set_header('Access-Control-Allow-Origin', '*') seanhalle@5: seanhalle@5: @route('/save1elem/') seanhalle@5: def save1elem(thejson): seanhalle@8: thejson = thejson.replace('%T', '\t') seanhalle@8: thejson = thejson.replace('%N', '\n') seanhalle@8: thejson = thejson.replace('%H', '\\') seanhalle@8: thejson = thejson.replace('%S', '/') seanhalle@8: # print thejson seanhalle@8: graphFile = open("syntaxGraph.json", "a") seanhalle@8: graphFile.write("%s\nseparator\n" % thejson) seanhalle@8: graphFile.close() seanhalle@8: response.set_header('Access-Control-Allow-Origin', '*') seanhalle@8: return "ACK" seanhalle@8: seanhalle@8: #================ seanhalle@8: # Retrieving graph seanhalle@8: #================ seanhalle@8: seanhalle@8: @route('/retrievegraph') seanhalle@8: def retrieveGraph(): seanhalle@8: graphFile = open("syntaxGraph.json", "r") seanhalle@8: returnjson = graphFile.read() seanhalle@5: response.set_header('Access-Control-Allow-Origin', '*') seanhalle@8: graphFile.close() seanhalle@8: return returnjson seanhalle@5: seanhalle@8: #================ seanhalle@8: seanhalle@8: #Deprecated -- at first, tried open via "start" URL, then write, then close seanhalle@8: # here.. but issues in async mode. So now, just "start" clears the file seanhalle@8: # then write opens in append mode, writes, and closes right away. seanhalle@8: #So no longer need the "end" URL seanhalle@5: @route('/endsavinggraph') seanhalle@5: def endsavinggraph(): seanhalle@5: global graphFile seanhalle@5: response.set_header('Access-Control-Allow-Origin', '*') seanhalle@5: graphFile.close() seanhalle@6: return 'ACK' seanhalle@5: seanhalle@8: #Deprecated -- start and end retrieve are deprecated seanhalle@5: @route('/startretrievinggraph') seanhalle@5: def startretrievinggraph(): seanhalle@5: global graphFile seanhalle@5: graphFile = open("syntaxGraph.json", "r") seanhalle@5: response.set_header('Access-Control-Allow-Origin', '*') seanhalle@6: return 'ACK' seanhalle@5: seanhalle@5: @route('/endretrievinggraph') seanhalle@5: def endretrievinggraph(): seanhalle@5: global graphFile seanhalle@5: response.set_header('Access-Control-Allow-Origin', '*') seanhalle@5: graphFile.close() seanhalle@6: return 'ACK' seanhalle@5: seanhalle@7: #================ seanhalle@7: seanhalle@5: run(host='localhost', port=8080) seanhalle@7: