From 048eb137d17435283f977c37cf098a899ca685ed Mon Sep 17 00:00:00 2001 From: Simon Billinge Date: Thu, 9 May 2024 19:10:38 -0400 Subject: [PATCH] att --- xpdsim/__init__.py | 6 ++++- xpdsim/build_sim_db.py | 59 ++++++++++++++++++++++++++++++------------ xpdsim/movers.py | 3 ++- 3 files changed, 50 insertions(+), 18 deletions(-) diff --git a/xpdsim/__init__.py b/xpdsim/__init__.py index cf704c7..cee7abb 100644 --- a/xpdsim/__init__.py +++ b/xpdsim/__init__.py @@ -10,7 +10,11 @@ __version__ = '0.1.2' pyfai_path = rs_fn('xpdsim', 'data/pyfai/pyFAI_calib.yml') - +# first initial attempt to fix the pgkg_resources issue +#pyfai_path = importlib_resources.files('xpdsim') / 'resource.dat' +#with importlib_resources.as_file(ref) as path: + # Do something with path. After the with-statement exits, any + # temporary file created will be immediately cleaned up. sim_db_dir, db = build_sim_db() # default is sqlite db.reg.register_handler('NPY_SEQ', NumpySeqHandler) diff --git a/xpdsim/build_sim_db.py b/xpdsim/build_sim_db.py index 08920f2..2ff6bc7 100644 --- a/xpdsim/build_sim_db.py +++ b/xpdsim/build_sim_db.py @@ -1,25 +1,52 @@ """this module exists for simulation environment""" import os import tempfile - +from databroker import Broker +from tiled.config import parse_configs +import yaml def build_sim_db(sim_db_dir=None): - from databroker import Broker if not sim_db_dir: sim_db_dir = tempfile.mkdtemp() config = { - 'metadatastore': { - 'module': 'databroker.headersource.sqlite', - 'class': 'MDS', - 'config': { - 'directory': sim_db_dir, - 'timezone': 'US/Eastern'} - }, - 'assets': { - 'module': 'databroker.assets.sqlite', - 'class': 'Registry', - 'config': { - 'dbpath': os.path.join(sim_db_dir, 'assets.sqlite')} + "authentication": {"allow_anonymous_access": True}, + # The default is false. Set to true to enable any HTTP client that can + # connect to _read_. An API key is still required to write. + "trees": [{ + "path": "/", + "tree": "catalog", + "args": { + "uri": "sqlite+aiosqlite:////storage/catalog.db", + "writable_storage": sim_db_dir, + # This creates the database if it does not exist. This is convenient, but in + # a horizonally-scaled deployment, this can be a race condition and multiple + # containers may simultanouesly attempt to create the database. + # If that is a problem, set this to false, and run: + # + # tiled catalog init URI + # + # separately. + "init_if_not_exists": True + } + }] + # 'metadatastore': { + # 'module': 'databroker.headersource.sqlite', + # 'class': 'MDS', + # 'config': { + # 'directory': sim_db_dir, + # 'timezone': 'US/Eastern'} + # }, + # 'assets': { + # 'module': 'databroker.assets.sqlite', + # 'class': 'Registry', + # 'config': { + # 'dbpath': os.path.join(sim_db_dir, 'assets.sqlite')} } - } - return sim_db_dir, Broker.from_config(config) + + with open(os.path.join(sim_db_dir, 'test_sim.yml'), 'w') as f: + yaml.dump(config, f, default_flow_style=False) + + print(sim_db_dir) + parse_configs(sim_db_dir) + db = Broker.named('test_sim') + return sim_db_dir, db diff --git a/xpdsim/movers.py b/xpdsim/movers.py index 16f09a5..d42b652 100644 --- a/xpdsim/movers.py +++ b/xpdsim/movers.py @@ -1,4 +1,5 @@ -from ophyd.sim import SynAxis, SynSignal, Device, Component +from ophyd.sim import SynAxis, SynSignal +from ophyd.device import Device, Component cs700 = SynAxis(name='cs700', value=300) cs700.readback.name = 'temperature'