make Graphics work again

as base for Mathis work
This commit is contained in:
l_samenv
2024-07-11 10:05:17 +02:00
parent 3fd8bc6bf3
commit 91be383803
7 changed files with 123 additions and 112 deletions

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env python
import sys
sys.path.append("../histreader")
sys.path.append("../frappyhistory")
# Make sure your gevent version is >= 1.0
import gevent
import gevent.pywsgi
@@ -25,8 +25,8 @@ import circularlog
import os
import signal
from histgraph import get_vars, get_curves, get_abs_time
from histreader.histreader import MainCache
from histreader.frappyreader import FrappyReader
from main import MainCache
from frappyreader import FrappyReader
try: import simplejson as json
except ImportError: import json
@@ -143,12 +143,7 @@ def reply():
@app.route('/test/<file>')
def subdir_test_file(file):
gevent.sleep(2)
try:
with open("client/test/"+file, 'r') as content_file:
content = content_file.read()
except IOError:
flask.abort(404)
resp = flask.Response(content, mimetype=guess_mimetype(file))
resp = flask.send_file("client/test/"+file, mimetype=guess_mimetype(file))
return resp
@app.route('/jsFiles/<file>')
@@ -156,12 +151,7 @@ def subdir_test_file(file):
@app.route('/externalFiles/<file>')
def subdir_file(file):
subdir = flask.request.path.split('/')[1]
try:
with open("client/" + subdir+"/"+file, 'r') as content_file:
content = content_file.read()
except IOError:
flask.abort(404)
resp = flask.Response(content, mimetype=guess_mimetype(file))
resp = flask.send_file("client/" + subdir+"/"+file, mimetype=guess_mimetype(file))
#resp.headers['Content-Security-Policy'] = "sandbox; script-src 'unsafe-inline';"
return resp
@@ -176,12 +166,7 @@ def default():
@app.route('/<file>')
def general_file(file):
subdir = "client/"
try:
with open(subdir+file, 'r') as content_file:
content = content_file.read()
except IOError:
flask.abort(404)
resp = flask.Response(content, mimetype=guess_mimetype(file))
resp = flask.send_file(subdir+file, mimetype=guess_mimetype(file))
#resp.headers['Content-Security-Policy'] = "sandbox; script-src 'unsafe-inline';"
return resp
@@ -294,6 +279,7 @@ class SeaInstrument(Instrument):
self.seacmd = None
self.last_client_remove = time.time()
self.history = deque(maxlen=1000)
self.title = inst_name # hack?
self.init()
gevent.Greenlet.spawn(self.checkconnections)
@@ -337,7 +323,7 @@ class SeaInstrument(Instrument):
def poll_groups(self, paths):
'polls values and components of requested groups'
for path in paths:
for path in list(paths):
gobj = self.groups[path]
now = time.time()
if now < gobj.lastpoll + 0.5:
@@ -483,12 +469,8 @@ class SeaInstrument(Instrument):
idx = min(len(self.history), self.consolepos - startindex) # distance from end
messages = []
for i in range(-idx,0):
type, line, origin = self.history[i]
if origin == id:
origin = 'self'
elif origin != 'async':
origin = 'other'
messages.append(dict(type=type, line=line, origin=origin))
typ, line, hid = self.history[i]
messages.append(dict(type=typ, line=line, origin=('self' if hid==id else 'other')))
return self.consolepos, messages
def command(self, command, id):
@@ -636,7 +618,9 @@ class SeaClient(SeaGraph):
def w_getblock(self, path):
gobj = instrument.findgroup(path.split(',')[-1])
self.group_version[path] = gobj.version
# self.group_version[path] = gobj.version
# simplify: allow only one group per client
self.group_version = {path: gobj.version}
logging.info('getblock %s %d', path, gobj.version)
return dict(type='draw', title=gobj.grouptitle, path=path, components=gobj.components)
@@ -678,7 +662,7 @@ class DummyClient(SeaGraph):
line = self.linesocket.get_line()
if line != None:
msg = json.loads(line)
if msg.type in self.asynch:
if msg['type'] in self.asynch:
t = 0
# print 'PUSH',msg, replytype
self.queue.append(msg)
@@ -689,8 +673,8 @@ class DummyClient(SeaGraph):
raise Exception("timeout")
gevent.sleep(0.1)
t += 0.1
if replytype and msg.type != replytype:
logging.error('REPLY MISMATCH %s %s <> %s', command, replytype, msg.type)
if replytype and msg['type'] != replytype:
logging.error('REPLY MISMATCH %s %s <> %s', command, replytype, msg['type'])
return msg
def strip_future(self, result):
@@ -724,7 +708,7 @@ class DummyClient(SeaGraph):
messages = []
if line:
msg = json.loads(line)
if msg.type in self.asynch:
if msg['type'] in self.asynch:
messages.append(msg)
else:
self.syncreply.append(msg)