correct the Problem with the react route/urls in flask
This commit is contained in:
@@ -35,8 +35,9 @@ class VRPMDV_Data:
|
||||
logging.basicConfig(format=format, level=logging.INFO, datefmt="%H:%M:%S")
|
||||
self.mons:list = []
|
||||
#TODO ML: uncomment this lines
|
||||
self.rtservice = None #rts.RT_Service()
|
||||
self.rtservice = rts.RT_Service()
|
||||
if (self.rtservice != None):
|
||||
logging.info("init: initCoproFW")
|
||||
self.rtservice.initCoproFW("home/root/elffile","zephyr_openamp_rsc_table.elf")
|
||||
self.logTask = None #createCoproLoggingTask()
|
||||
self.loaded = self.loadFile()
|
||||
@@ -404,6 +405,9 @@ class VRPMDV_Data:
|
||||
# schema = VRPMDV_MonfilesCompleteSchema()
|
||||
# else :
|
||||
logging.info("loadMonfiles: before schemaload")
|
||||
if (complete):
|
||||
schema = VRPMDV_MonfilesCompleteSchema()
|
||||
else:
|
||||
schema = VRPMDV_MonfilesSchema()
|
||||
try:
|
||||
monfile = schema.loads(fmonfile, unknown=EXCLUDE)
|
||||
|
||||
@@ -19,6 +19,7 @@ import io
|
||||
import fcntl
|
||||
import mmap
|
||||
|
||||
from vrpmdvntlink import trySend
|
||||
from vrpmdvstatusmoncmd import VRPMDV_StatusMonCmd
|
||||
from vrpmdvstatusmonschema import VRPMDV_StatusMonSchema
|
||||
|
||||
@@ -80,7 +81,7 @@ class VRPMDV_Monitoring(VRPMDV_MonReq):
|
||||
self.created_at = created_at
|
||||
#TODO ML: uncomment
|
||||
self.rtservice = None #rts.RT_Service()
|
||||
self.rtMon = None #rts.RTSMonitoringTask()
|
||||
self.rtMon = None
|
||||
self.monTask = None
|
||||
self.run_thread = False
|
||||
self.fdesc = -1
|
||||
@@ -97,8 +98,8 @@ class VRPMDV_Monitoring(VRPMDV_MonReq):
|
||||
schemaCreateCmd = VRPMDV_CreateMonSchema()
|
||||
logging.info("MainThread: try send start monitoring starting %s", schemaCreateCmd.dumps(vrpmdCreateCmd))
|
||||
# TODO ML: uncomment this
|
||||
# res = trySend(schemaCreateCmd.dumps(vrpmdCreateCmd))
|
||||
res = 'Test'
|
||||
res = trySend(schemaCreateCmd.dumps(vrpmdCreateCmd))
|
||||
#res = 'Test'
|
||||
logging.info("MainThread: try send start monitoring done %s", res)
|
||||
|
||||
# start the receiving thread
|
||||
@@ -109,10 +110,29 @@ class VRPMDV_Monitoring(VRPMDV_MonReq):
|
||||
# self.monTask = threading.Thread(target=self.run, args=())
|
||||
# self.monTask.start()
|
||||
# logging.info("MainThread: strated Mon Thread %s started", self.id)
|
||||
logging.info("startmonitoring: create RTSMonitoringTask")
|
||||
strid = str(self.id)
|
||||
logging.info("rts.RTSMonitoringTask: self.id:%s", strid)
|
||||
self.rtMon = rts.RTSMonitoringTask(str(self.id), str(self.name), self.samplerate, self.sampleperiod, self.downtime, '/home/root/monfiles/')
|
||||
# self.rtMon.id = self.id
|
||||
# self.rtMon.name = self.name
|
||||
# self.rtMon.samplerate = self.samplerate
|
||||
# self.rtMon.samplePeriod = self.sampleperiod
|
||||
# self.rtMon.downtime = self.downtime
|
||||
# self.rtMon.path = '/home/root/monfiles'
|
||||
#logging.info("startmonitoring: created RTSMonitoringTask: id:%s name:%s samplerate:%d sampleperiod:%d downtime:%d path:%s", self.rtMon.id, self.rtMon.name, self.rtMon.samplerate, self.rtMon.samplePeriod, self.rtMon.downtime, self.rtMon.path)
|
||||
|
||||
##new ML 09.07.2024
|
||||
if (self.rtMon.start()) :
|
||||
logging.info("startmonitoring - self.rtMon.start(): Monitoring started")
|
||||
|
||||
self.status = 'started'
|
||||
else :
|
||||
self.status = 'stopped'
|
||||
return self.status
|
||||
except :
|
||||
self.status = "stopped"
|
||||
self.rtMon = None
|
||||
return self.status
|
||||
|
||||
def stopMonitoring(self) :
|
||||
@@ -120,27 +140,32 @@ class VRPMDV_Monitoring(VRPMDV_MonReq):
|
||||
logging.basicConfig(format=format, level=logging.INFO, datefmt="%H:%M:%S")#
|
||||
logging.info("MainThread: stopping Mon Thread %s ", self.id)
|
||||
#send delete cmd to M4
|
||||
logging.info("MainThread: stop monitoring")
|
||||
#logging.info("MainThread: stop monitoring")
|
||||
|
||||
|
||||
if (self.monTask != None) :
|
||||
# if (self.monTask != None) :
|
||||
# set the value Runthread to fals that the thread terminate
|
||||
self.run_thread = False
|
||||
self.monTask.join(None)
|
||||
self.monTask = None
|
||||
logging.info("MonThread %s: closing fdesc=%s", str(self.id), str(self.fdesc))
|
||||
self.rtMon.closeChannel(self.fdesc)
|
||||
logging.info("MonThread %s: closed fdesc=%s", str(self.id), str(self.fdesc))
|
||||
# self.run_thread = False
|
||||
# self.monTask.join(None)
|
||||
|
||||
##new ML 09.07.2024
|
||||
if (self.rtMon != None) :
|
||||
self.rtMon.stop()
|
||||
# self.monTask = None
|
||||
# logging.info("MonThread %s: closing fdesc=%s", str(self.id), str(self.fdesc))
|
||||
# # self.rtMon.closeChannel(self.fdesc)
|
||||
# logging.info("MonThread %s: closed fdesc=%s", str(self.id), str(self.fdesc))
|
||||
|
||||
logging.info("MainThread: stopped Mon Thread %s ", self.id)
|
||||
|
||||
vrpmdDeleteCmd = VRPMDV_DeleteMonCmd(self.no)
|
||||
schemaDeleteCmd = VRPMDV_DeleteMonSchema()
|
||||
# TODO ML: uncomment this
|
||||
# res = trySend(schemaDeleteCmd.dumps(vrpmdDeleteCmd))
|
||||
res = 'Stop'
|
||||
res = trySend(schemaDeleteCmd.dumps(vrpmdDeleteCmd))
|
||||
#res = 'Stopped'
|
||||
logging.info("MainThread: try send stop monitoring done %s", res)
|
||||
|
||||
self.rtMon = None
|
||||
# if (isstopped) :
|
||||
self.status = 'stopped'
|
||||
return self.status
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
# from vrpmdv-server/vrpmdv-main import application
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
from flask import Flask, request , send_from_directory , Response
|
||||
@@ -10,15 +12,30 @@ from vrpmdvmonreqschema import VRPMDV_MonReqSchema
|
||||
|
||||
|
||||
app = Flask(__name__, static_url_path='', static_folder='./build')
|
||||
#app = Flask(__name__, static_url_path='/public', static_folder='../build')
|
||||
#app = Flask(__name__)
|
||||
CORS(app) #comment this on deployment
|
||||
|
||||
vrpmdvdata = VRPMDV_Data()
|
||||
|
||||
|
||||
@app.route("/", defaults={'path':''})
|
||||
#@app.route("/")
|
||||
@app.route('/<path:path>')
|
||||
def serve(path):
|
||||
logging.basicConfig(format=format, level=logging.INFO, datefmt="%H:%M:%S")
|
||||
logging.info("vrpmdvserver: path:%s", path)
|
||||
# path_dir = os.path.abspath("../build") #path react build
|
||||
# if path != "" and os.path.exists(os.path.join(path_dir, path)):
|
||||
# return send_from_directory(os.path.join(path_dir), path)
|
||||
# else:
|
||||
# return send_from_directory(os.path.join(path_dir),'index.html')
|
||||
return send_from_directory(app.static_folder,'index.html')
|
||||
|
||||
@app.errorhandler(404)
|
||||
def not_found(e):
|
||||
return app.send_static_file('index.html')
|
||||
|
||||
@app.route('/vrpmdvapi/1_0/monitorings', methods=['GET'])
|
||||
def get_monitorings():
|
||||
data = vrpmdvdata.getMonitorings()
|
||||
|
||||
Reference in New Issue
Block a user