diff 1__Development/6__Website/POPBottleServer/POPBottleServer.py @ 8:cc10d99e3f83

Persist and read back from disk and parse to objects is working.. Display needs updating now
author Sean Halle <seanhalle@yahoo.com>
date Sat, 09 Aug 2014 03:34:26 -0700
parents 20a1407463a0
children
line diff
     1.1 --- a/1__Development/6__Website/POPBottleServer/POPBottleServer.py	Thu Aug 07 00:10:50 2014 -0700
     1.2 +++ b/1__Development/6__Website/POPBottleServer/POPBottleServer.py	Sat Aug 09 03:34:26 2014 -0700
     1.3 @@ -1,32 +1,47 @@
     1.4  from bottle import route, run, template, response
     1.5  import urllib
     1.6  
     1.7 -graphFile = None
     1.8 -
     1.9  #==============
    1.10 -
    1.11 -@route('/startsavinggraph')
    1.12 -def startsavinggraph():
    1.13 -    global graphFile
    1.14 +# Persisting the graph to disk
    1.15 +#==============
    1.16 +@route('/cleargraph')
    1.17 +def cleargraph():
    1.18      graphFile = open("syntaxGraph.json", "w")
    1.19 -    print "opened graph file "
    1.20 -    print "Name of the file: ", graphFile.name
    1.21 -    print "Closed or not : ", graphFile.closed
    1.22 -    print "Opening mode : ", graphFile.mode
    1.23 -    print "Softspace flag : ", graphFile.softspace
    1.24 +    print "opened graph file, which should have cleared it"
    1.25 +    graphFile.close()
    1.26      response.set_header('Access-Control-Allow-Origin', '*')
    1.27  
    1.28  @route('/save1elem/<thejson>')
    1.29  def save1elem(thejson):
    1.30 -	thejson = thejson.replace('%T', '\t')
    1.31 -	thejson = thejson.replace('%N', '\n')
    1.32 -	thejson = thejson.replace('%H', '\\')
    1.33 -	thejson = thejson.replace('%S', '/')
    1.34 -#	print thejson
    1.35 -	global graphFile
    1.36 -	graphFile.write("%s\nend elem\n" % thejson)
    1.37 +    thejson = thejson.replace('%T', '\t')
    1.38 +    thejson = thejson.replace('%N', '\n')
    1.39 +    thejson = thejson.replace('%H', '\\')
    1.40 +    thejson = thejson.replace('%S', '/')
    1.41 +#    print thejson
    1.42 +    graphFile = open("syntaxGraph.json", "a")
    1.43 +    graphFile.write("%s\nseparator\n" % thejson)
    1.44 +    graphFile.close()
    1.45 +    response.set_header('Access-Control-Allow-Origin', '*')
    1.46 +    return "ACK"
    1.47 +
    1.48 +#================
    1.49 +# Retrieving graph
    1.50 +#================
    1.51 +
    1.52 +@route('/retrievegraph')
    1.53 +def retrieveGraph():
    1.54 +	graphFile = open("syntaxGraph.json", "r")
    1.55 +	returnjson = graphFile.read()
    1.56  	response.set_header('Access-Control-Allow-Origin', '*')
    1.57 +	graphFile.close()
    1.58 +	return returnjson
    1.59  
    1.60 +#================
    1.61 +
    1.62 +#Deprecated -- at first, tried open via "start" URL, then write, then close
    1.63 +# here..  but issues in async mode.  So now, just "start" clears the file
    1.64 +# then write opens in append mode, writes, and closes right away.
    1.65 +#So no longer need the "end" URL
    1.66  @route('/endsavinggraph')
    1.67  def endsavinggraph():
    1.68  	global graphFile
    1.69 @@ -34,8 +49,7 @@
    1.70  	graphFile.close()
    1.71  	return 'ACK'
    1.72  
    1.73 -#================
    1.74 -
    1.75 +#Deprecated -- start and end retrieve are deprecated
    1.76  @route('/startretrievinggraph')
    1.77  def startretrievinggraph():
    1.78  	global graphFile
    1.79 @@ -43,13 +57,6 @@
    1.80  	response.set_header('Access-Control-Allow-Origin', '*')
    1.81  	return 'ACK'
    1.82  
    1.83 -@route('/get1elem')
    1.84 -def get1elem():
    1.85 -	global graphFile
    1.86 -	returnjson = graphFile.readline()
    1.87 -	response.set_header('Access-Control-Allow-Origin', '*')
    1.88 -	return returnjson
    1.89 -
    1.90  @route('/endretrievinggraph')
    1.91  def endretrievinggraph():
    1.92  	global graphFile