Skip to content
Snippets Groups Projects
Commit 4b79ca26 authored by wactbprot's avatar wactbprot
Browse files

start with rest api lanfrank

parent 1283d4f9
No related branches found
No related tags found
No related merge requests found
......@@ -34,7 +34,7 @@ class Anselm(System):
year_select = ["2017", "2018", "2019"]
dut_branches = ["dut-a", "dut-b", "dut-c"]
run_kinds = ["single", "loop"]
def __init__(self):
super().__init__()
......@@ -51,7 +51,7 @@ class Anselm(System):
self.add_device_btn_col = 1
self.std_col = 2
self.year_col = 3
# device lines
self.cal_id_col = 2
self.fullscale_col = 3
......@@ -73,12 +73,12 @@ class Anselm(System):
add_device_bttn.clicked.connect(self.add_device_line)
self.add_widget_to_grid(add_device_bttn ,self.current_grid_line, self.add_device_btn_col)
std_select_combo = self.make_combo(self.std_select, first_item = None)
std_select_combo = self.make_combo(self.std_select)
self.add_widget_to_grid(std_select_combo ,self.current_grid_line, self.std_col)
std_select_combo.currentIndexChanged.connect(lambda: self.std_selected(std_select_combo))
year_select_combo = self.make_combo(self.year_select, first_item = None)
year_select_combo = self.make_combo(self.year_select)
self.add_widget_to_grid(year_select_combo ,self.current_grid_line, self.year_col)
year_select_combo.currentIndexChanged.connect(lambda: self.year_selected(year_select_combo))
......@@ -92,12 +92,17 @@ class Anselm(System):
self.grid.addWidget(widget, line, col)
def make_combo(self, item_list, first_item='select'):
def make_combo(self, item_list, first_item=True, last_item=True):
c = QComboBox(self.win)
if first_item:
c.addItem(first_item)
c.addItem(self.first_item)
for item in item_list:
c.addItem(item)
if last_item:
c.addItem(self.last_item)
return c
def run_task(self, line):
......@@ -137,11 +142,12 @@ class Anselm(System):
l = widget_item.widget()
else:
l = QPlainTextEdit(self.win)
l.setFixedSize(self.long_line, self.line_heigth*3)
l.setFixedSize(self.long_line, self.line_heigth*4)
result = self.aget('result', line)
if result:
txt = result
txt = str(result)
txt = txt.replace(",", ",\n")
else:
txt = "raw output"
......@@ -151,21 +157,21 @@ class Anselm(System):
def make_run_kind_combo(self, line):
c = self.make_combo(self.run_kinds, first_item = None)
c = self.make_combo(self.run_kinds, first_item=False, last_item=False)
c.currentIndexChanged.connect(lambda: self.run_kind_selected(c, line))
return c
def make_dut_branch_combo(self, line):
c = self.make_combo(self.dut_branches, first_item = "select branch")
c = self.make_combo(self.dut_branches)
c.currentIndexChanged.connect(lambda: self.dut_branch_selected(c, line))
return c
def make_fullscale_combo(self, line):
c = self.make_combo(self.fullscale, first_item = "select device fullscale")
c = self.make_combo(self.fullscale)
c.currentIndexChanged.connect(lambda: self.fullscale_selected(c, line))
return c
......@@ -173,7 +179,7 @@ class Anselm(System):
def make_cal_id_combo(self, line):
cal_ids = self.db.get_cal_ids()
c = self.make_combo(cal_ids, first_item = "select calib. document")
c = self.make_combo(cal_ids)
c.currentIndexChanged.connect(lambda: self.cal_id_selected(c, line))
return c
......@@ -184,7 +190,7 @@ class Anselm(System):
self.log.debug("found following auxobj ids {}".format(aux_obj_ids))
c = self.make_combo(aux_obj_ids)
c = self.make_combo(aux_obj_ids, first_item=False, last_item=False)
c.currentIndexChanged.connect(lambda: self.auxobj_selected(c, line))
return c
......@@ -192,7 +198,7 @@ class Anselm(System):
def make_task_combo(self, doc_id, line):
task_names = self.db.get_task_names(doc_id = doc_id)
self.log.debug("found following tasknames {}".format(task_names))
c = self.make_combo(task_names)
c = self.make_combo(task_names, first_item=False, last_item=False)
c.currentIndexChanged.connect(lambda: self.task_selected(c, line))
return c
......
#!/bin/sh
python anselm.py
......@@ -11,7 +11,8 @@ class System:
expire_time = 10000 #ms
log_fmt = '%(asctime)s,%(msecs)03d %(hostname)s %(filename)s:%(lineno)s %(levelname)s %(message)s'
log_level = "DEBUG"
first_item ="select"
last_item = "remove"
def __init__(self):
"""
Gets the configuration out of the file: ``config.json``.
......@@ -55,7 +56,11 @@ class System:
if isinstance(value, str):
v = value
self.r.set(k,v)
if v == self.first_item or v == self.last_item:
self.r.delete(k)
else:
self.r.set(k,v)
if expire:
self.r.pexpire(k, self.expire_time)
......
......@@ -25,10 +25,9 @@ class Worker(System):
acc = task['Action']
if acc == "TCP":
worker = self.relay_worker
if acc == "VXI11":
if acc == "TCP" or acc == "VXI11" or acc == "MODBUS":
worker = self.relay_worker
if acc == "wait":
worker = self.wait_worker
......
from flask import Flask, jsonify
from anselm.system import System
app = Flask(__name__)
s = System()
@app.route('/calids')
def calids():
keys = s.r.keys('calid@*')
calids = []
for key in keys:
calids.append(s.r.get(key))
s.log.info("request cal ids")
return jsonify({"calids":calids })
\ No newline at end of file
#!/bin/sh
export FLASK_APP=lanfrank.py
export FLASK_DEBUG=1
export FLASK_ENV=development
flask run --host=0.0.0.0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment