From: Bdale Garbee Date: Sun, 25 May 2025 23:41:11 +0000 (-0600) Subject: add an endpoint to store user-provided test metadata X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=2b3f08d6f02dbd8cbf3735c0f8738d0c4094e8d2;p=fw%2Fquantimotor add an endpoint to store user-provided test metadata --- diff --git a/ui/app.py b/ui/app.py index ced6ad8..48bf7e7 100755 --- a/ui/app.py +++ b/ui/app.py @@ -10,10 +10,14 @@ from cherrypy.lib.static import serve_file import gpiod from gpiod.line import Direction, Value import iio +import json import signal import sys import time +# where we'll store all our test data +DATAPATH = "/var/lib/quantimotor/" + n = 0 pressure = 0 thrust = 0 @@ -75,6 +79,8 @@ config = { 'server.socket_host' : '0.0.0.0', 'server.socket_port' : 80, 'server.thread_pool' : 8, + 'log.access_file': '/var/log/access.log', + 'log.error_file': '/var/log/error.log', }, '/': { 'tools.staticdir.on': True, @@ -85,13 +91,27 @@ config = { class App: + # main user interface home page @cherrypy.expose def index(self): return serve_file(os.path.join(path, 'index.html')) + # end point for accepting and saving test metadata + @cherrypy.expose + @cherrypy.tools.json_in() + def metadata(self): + if cherrypy.request.method == 'PUT': + jsondata = cherrypy.request.json + metadata_path = DATAPATH + "metadata.json" + with open(metadata_path, 'w') as json_file: + json.dump(jsondata, json_file, indent=2) + return "Data received and processed" + else: + return "Method not allowed", 405 + + # end point for handling AJAX requests for current status @cherrypy.expose @cherrypy.tools.json_out() - def getData(self): global n global pressure