moved code that deals with sets of PVInfo into separate file/class
This commit is contained in:
@ -4,7 +4,7 @@ from threading import Thread
|
||||
from pcaspy import SimpleServer, Driver
|
||||
|
||||
from context import Context
|
||||
from pvinfo import make_pvinfos, make_pvdb, make_values
|
||||
from pvinfoset import PVInfoSet
|
||||
from managed import delete_managed
|
||||
|
||||
|
||||
@ -57,16 +57,16 @@ class MorIOC(Context):
|
||||
|
||||
|
||||
def serve(self, **kwargs):
|
||||
pvis = make_pvinfos(kwargs, parse_string=False)
|
||||
pvdb = make_pvdb(pvis)
|
||||
pvis = PVInfoSet(kwargs, parse_string=False)
|
||||
pvdb = pvis.pvdb()
|
||||
self.createPV(pvdb)
|
||||
pvvs = make_values(pvis)
|
||||
pvvs = pvis.values()
|
||||
self.setParams(**pvvs)
|
||||
|
||||
|
||||
def host(self, **kwargs):
|
||||
pvis = make_pvinfos(kwargs, parse_string=True)
|
||||
pvdb = make_pvdb(pvis)
|
||||
pvis = PVInfoSet(kwargs, parse_string=True)
|
||||
pvdb = pvis.pvdb()
|
||||
self.createPV(pvdb)
|
||||
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
from managed import is_managed, get_managed_dtype
|
||||
|
||||
|
||||
#PV data type: enum, string, char, float or int
|
||||
DTYPES = {
|
||||
@ -10,15 +8,6 @@ DTYPES = {
|
||||
|
||||
|
||||
|
||||
def make_values(pvinfos):
|
||||
return {pvi.name: pvi.value for pvi in pvinfos}
|
||||
|
||||
|
||||
def make_pvinfos(kwargs, parse_string=True):
|
||||
return [PVInfo(*args, parse_string=parse_string) for args in kwargs.items()]
|
||||
|
||||
|
||||
|
||||
class PVInfo:
|
||||
|
||||
def __init__(self, name, data, parse_string=True):
|
||||
@ -59,23 +48,3 @@ def infer_type(value, parse_string=True): #TODO arrays? strings?
|
||||
|
||||
|
||||
|
||||
def make_pvdb(pvinfos):
|
||||
pvdb = {}
|
||||
for pvi in pvinfos:
|
||||
name = pvi.name
|
||||
|
||||
if is_managed(name):
|
||||
dtype = pvi.dtype
|
||||
managed_dtype = get_managed_dtype(name)
|
||||
if dtype != managed_dtype:
|
||||
print(f"dtype for {name} changed:", managed_dtype, "->", dtype) #TODO what should be done if this happens?
|
||||
# server.deletePV(name) #?
|
||||
continue # no need to re-create
|
||||
|
||||
print("will create", name)
|
||||
pvdb[name] = pvi.to_dict()
|
||||
|
||||
return pvdb
|
||||
|
||||
|
||||
|
||||
|
47
morioc/pvinfoset.py
Normal file
47
morioc/pvinfoset.py
Normal file
@ -0,0 +1,47 @@
|
||||
from pvinfo import PVInfo
|
||||
from managed import is_managed, get_managed_dtype
|
||||
|
||||
|
||||
class PVInfoSet(set):
|
||||
|
||||
def __init__(self, data, parse_string=True):
|
||||
super().__init__(
|
||||
PVInfo(*args, parse_string=parse_string) for args in data.items()
|
||||
)
|
||||
|
||||
def values(self):
|
||||
return make_values(self)
|
||||
|
||||
def pvdb(self):
|
||||
return make_pvdb(self)
|
||||
|
||||
|
||||
|
||||
def make_pvinfos(data, parse_string=True):
|
||||
return [PVInfo(*args, parse_string=parse_string) for args in data.items()]
|
||||
|
||||
|
||||
def make_values(pvinfos):
|
||||
return {pvi.name: pvi.value for pvi in pvinfos}
|
||||
|
||||
|
||||
def make_pvdb(pvinfos):
|
||||
pvdb = {}
|
||||
for pvi in pvinfos:
|
||||
name = pvi.name
|
||||
|
||||
if is_managed(name):
|
||||
dtype = pvi.dtype
|
||||
managed_dtype = get_managed_dtype(name)
|
||||
if dtype != managed_dtype:
|
||||
print(f"dtype for {name} changed:", managed_dtype, "->", dtype) #TODO what should be done if this happens?
|
||||
# server.deletePV(name) #TODO ???
|
||||
continue # no need to re-create
|
||||
|
||||
print("will create", name)
|
||||
pvdb[name] = pvi.to_dict()
|
||||
|
||||
return pvdb
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user