Commit 3d744309 authored by TOUZE Francois's avatar TOUZE Francois
Browse files

docker containers creation: step 5

parent 993f9b5d
......@@ -4,7 +4,7 @@
from pspaplots cimport pspaplot
from libcpp.string cimport string
cdef class PyPspaPlot:
cdef class PyPspaPlots:
cdef pspaplot *ptr
def __cinit__(self):
......
......@@ -6,8 +6,8 @@ import os
import json
import urllib.parse
from cython-cpp import pspaclass
from cython-cpp import pspaplots
from pypspaclass import PyPspaClass
from pypspaplots import PyPspaPlots
from flask_cors import CORS
app = Flask(__name__, template_folder='.')
......@@ -25,7 +25,7 @@ def importe():
u_bytes= str.encode( upath )
w_bytes= str.encode( wpath )
ptr= pspaclass.PyPspaClass( u_bytes, w_bytes )
ptr= PyPspaClass( u_bytes, w_bytes )
x= request.json
print( "/api/importe => ", x['fileName'] )
......@@ -37,3 +37,12 @@ def importe():
}
return jsonify(response)
@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def catch_all(path):
"""Our entry point"""
return render_template("index.html")
if __name__ == "__main__":
app.run("0.0.0.0", port=5000, debug=True)
#!/bin/env python3
from flask import Flask, render_template, jsonify
from flask import request
import os
import json
import urllib.parse
from modules import pspacode
from modules import pspaplot
from flask_cors import CORS
app = Flask(__name__, template_folder='.')
cors = CORS(app, resources={r"/api/*": {"origins": "*"}})
curdir = os.getcwd()
print( "current directory => ", curdir)
pkgRoot = curdir.split('pspa.git')
print( "root directory => ", pkgRoot[0])
upath = os.path.join(pkgRoot[0],'workZone/')
wpath = os.path.join(pkgRoot[0],'pspa.git/softwares/')
@app.route('/api/importe', methods=['GET', 'POST'])
def importe():
u_bytes= str.encode( upath )
w_bytes= str.encode( wpath )
ptr= pspacode.Pypspa( u_bytes, w_bytes )
x= request.json
print( "/api/importe => ", x['fileName'] )
x_bytes= str.encode( x['fileName'] )
s= ptr.read( x_bytes ).decode('utf-8')
response = {
'import': s
}
return jsonify(response)
@app.route('/api/simulate', methods=['GET', 'POST'])
def simulate():
x= request.json
#print( "x => ", x["machine"])
#print( "y => ", x["simulations"])
#print( "z => ", x["projectName"])
u_bytes= str.encode( upath )
w_bytes= str.encode( wpath )
ptr= pspacode.Pypspa( u_bytes, w_bytes )
data= json.dumps(x, ensure_ascii=False)
x_bytes= str.encode( data )
status= ptr.execute( x_bytes )
#print( "/api/simulate:: status => ", status )
s= "failure"
if (status): s= "success"
response = {
'status': s
}
return jsonify(response)
@app.route('/api/console', methods=['GET', 'POST'])
def console():
print( "api/console => ", request.full_path)
""" x is the list after splitting by the separator 'ids='
"""
x = request.full_path.split("ids=")
""" y is the list after splitting the 2nd item by the separator ','
"""
y = x[1].split(",")
#print( "api/pourVoir y => ", type(y), len(y))
#print( "api/pourVoir y => ", y)
z= []
if len(y[0]) > 0:
for item in y:
d={"id":urllib.parse.unquote( item )}
ids= urllib.parse.unquote( item ).split()
out= ids[0]+"-output.txt"
fname= os.path.join(upath,out)
if os.path.exists( fname ):
fp= open(fname).read()
d["output"]= fp
d["status"]= "loaded"
else:
d["output"]= "unknown result"
d["status"]= "not loaded"
z.append(d)
response = {
'results': z
}
return jsonify(response)
@app.route('/api/plots', methods=['GET', 'POST'])
def plots():
x= request.json
"""
x1= x['plotSimulation']
print( "/api/plots Ids=> ", x1, type(x1), len(x1) )
x2= x['plotItem']
print( "/api/plots item=> ", x2, type(x2) )
"""
up_bytes= str.encode( upath )
ptr= pspaplot.Pypspaplot( up_bytes )
data= json.dumps(x, ensure_ascii=False)
x_bytes= str.encode( data )
ptr.settings( x_bytes )
data= os.path.join(upath,'simulator-plot.txt')
"""
data= os.path.join(pkgRoot[0],"workZone/raf.txt")
"""
with open(data) as f:
ofi= json.load(f)
response = {
'chartConfig': ofi
}
return jsonify(response)
@app.route('/api/settings', methods=['GET', 'POST'])
def settings():
x= request.json
ids= x['selectedIds']
print( "/api/settings Ids=> ", ids, type(ids), len(ids) )
z= []
for id in ids:
d={"id": id}
out= id + "-plot.txt"
fname= os.path.join(upath,out)
if os.path.exists( fname ):
d['status']= 'found'
data= json.load( open(fname) )
d['software']= data['software']
d['action']= data['action']
else:
d['status']= 'not found'
z.append(d)
response = {
'parameters': z
}
return jsonify(response)
@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def catch_all(path):
"""Our entry point"""
return render_template("index.html")
if __name__ == "__main__":
app.run("0.0.0.0", port=5000, debug=True)
#!/bin/env python3
from flask import Flask, render_template, jsonify
from flask import request
import os
import json
import urllib.parse
from pypspaclass import PyPspaClass
from pypspaplots import PyPspaPlots
from flask_cors import CORS
app = Flask(__name__, template_folder='.')
cors = CORS(app, resources={r"/api/*": {"origins": "*"}})
curdir = os.getcwd()
print( "current directory => ", curdir)
pkgRoot = curdir.split('pspa')
print( "root directory => ", pkgRoot[0])
upath = os.path.join(pkgRoot[0],'workZone/')
wpath = os.path.join(pkgRoot[0],'pspa/softwares/')
@app.route('/api/importe', methods=['GET', 'POST'])
def importe():
u_bytes= str.encode( upath )
w_bytes= str.encode( wpath )
ptr= PyPspaClass( u_bytes, w_bytes )
x= request.json
print( "/api/importe => ", x['fileName'] )
x_bytes= str.encode( x['fileName'] )
s= ptr.read( x_bytes ).decode('utf-8')
response = {
'import': s
}
return jsonify(response)
@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def catch_all(path):
"""Our entry point"""
return render_template("index.html")
if __name__ == "__main__":
app.run("0.0.0.0", port=5000, debug=True)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment