Mercurial > cgi-bin > hgwebdir.cgi > POP > oldRepo
comparison 1__Development/6__Website/POPBottleServer/POPBottleServer.py @ 7:20a1407463a0
sort of working with view sets -- does restore, (not tested) have to chg Display to handle view sets
| author | Sean Halle <seanhalle@yahoo.com> |
|---|---|
| date | Thu, 07 Aug 2014 00:10:50 -0700 |
| parents | d18eee376f45 |
| children | cc10d99e3f83 |
comparison
equal
deleted
inserted
replaced
| 1:c9bc1dc86c6f | 2:caf24fe792fe |
|---|---|
| 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 | 4 graphFile = None |
| 5 | 5 |
| 6 @route('/') | 6 #============== |
| 7 def index(): | |
| 8 return '<b>Hello</b>!' | |
| 9 | 7 |
| 10 @route('/<name>') | |
| 11 @route('/hello/<name>') | |
| 12 def nameroute(name): | |
| 13 return template('<b>Hello {{name}}</b>!', name=name) | |
| 14 | |
| 15 @route('/savejson/<thejson>') | |
| 16 def savejson(thejson): | |
| 17 text_file = open("syntaxGraph.json", "w") | |
| 18 text_file.write("%s" % thejson) | |
| 19 text_file.close() | |
| 20 print "hello" | |
| 21 response.set_header('Access-Control-Allow-Origin', '*') | |
| 22 # return 'Got JSON!' | |
| 23 # return template('Got JSON! {{printjson}}</b>!', printjson = thejson) | |
| 24 | |
| 25 @route('/getjson') | |
| 26 def getjson(): | |
| 27 text_file = open("syntaxGraph.json", "r") | |
| 28 returnjson = text_file.read() | |
| 29 text_file.close() | |
| 30 response.set_header('Access-Control-Allow-Origin', '*') | |
| 31 return returnjson | |
| 32 | |
| 33 #=============== | |
| 34 @route('/startsavinggraph') | 8 @route('/startsavinggraph') |
| 35 def startsavinggraph(): | 9 def startsavinggraph(): |
| 36 global graphFile | 10 global graphFile |
| 37 graphFile = open("syntaxGraph.json", "w") | 11 graphFile = open("syntaxGraph.json", "w") |
| 38 response.set_header('Access-Control-Allow-Origin', '*') | 12 print "opened graph file " |
| 39 return 'ACK' | 13 print "Name of the file: ", graphFile.name |
| 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', '*') | |
| 40 | 18 |
| 41 @route('/save1elem/<thejson>') | 19 @route('/save1elem/<thejson>') |
| 42 def save1elem(thejson): | 20 def save1elem(thejson): |
| 43 thejson = thejson.replace('%T', '\t') | 21 thejson = thejson.replace('%T', '\t') |
| 44 thejson = thejson.replace('%N', '\n') | 22 thejson = thejson.replace('%N', '\n') |
| 45 thejson = thejson.replace('%H', '\\') | 23 thejson = thejson.replace('%H', '\\') |
| 46 thejson = thejson.replace('%S', '/') | 24 thejson = thejson.replace('%S', '/') |
| 47 print thejson | 25 # print thejson |
| 48 global graphFile | 26 global graphFile |
| 49 graphFile.write("%s\n<end elem>\n" % thejson) | 27 graphFile.write("%s\nend elem\n" % thejson) |
| 50 response.set_header('Access-Control-Allow-Origin', '*') | 28 response.set_header('Access-Control-Allow-Origin', '*') |
| 51 return 'ACK' | |
| 52 | 29 |
| 53 @route('/endsavinggraph') | 30 @route('/endsavinggraph') |
| 54 def endsavinggraph(): | 31 def endsavinggraph(): |
| 55 global graphFile | 32 global graphFile |
| 56 response.set_header('Access-Control-Allow-Origin', '*') | 33 response.set_header('Access-Control-Allow-Origin', '*') |
| 78 global graphFile | 55 global graphFile |
| 79 response.set_header('Access-Control-Allow-Origin', '*') | 56 response.set_header('Access-Control-Allow-Origin', '*') |
| 80 graphFile.close() | 57 graphFile.close() |
| 81 return 'ACK' | 58 return 'ACK' |
| 82 | 59 |
| 60 #================ | |
| 61 | |
| 83 run(host='localhost', port=8080) | 62 run(host='localhost', port=8080) |
| 63 |
