startup and more
This commit is contained in:
+25
-3
@@ -1,16 +1,18 @@
|
||||
from ..utilities.config import initFromConfigList
|
||||
from epics import PV
|
||||
from .config import components, config
|
||||
from .. import ecocnf
|
||||
from ..aliases import NamespaceCollection
|
||||
import logging
|
||||
|
||||
itglobals = globals()
|
||||
from .config import components, config
|
||||
_namespace = globals()
|
||||
_scope_name = 'bernina'
|
||||
|
||||
alias_namespaces = NamespaceCollection()
|
||||
|
||||
|
||||
for key, value in initFromConfigList(components, lazy=ecocnf.startup_lazy).items():
|
||||
globals()[key] = value
|
||||
_namespace[key] = value
|
||||
|
||||
if not ecocnf.startup_lazy:
|
||||
try:
|
||||
@@ -21,3 +23,23 @@ for key, value in initFromConfigList(components, lazy=ecocnf.startup_lazy).items
|
||||
except:
|
||||
pass
|
||||
alias_namespaces.bernina.store()
|
||||
|
||||
|
||||
def initDevice(name):
|
||||
if name=='all':
|
||||
logging.info(f'initializing all components from {_scope_name}.')
|
||||
name = list(components.keys())
|
||||
if not name in components.keys():
|
||||
raise KeyError(f'Could not find {name} in configuration!')
|
||||
if type(name) is list:
|
||||
for tname in name:
|
||||
initDevice(tname)
|
||||
else:
|
||||
initFromConfigList
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -16,12 +16,12 @@ from ..utilities.config import (
|
||||
Alias,
|
||||
init_device,
|
||||
initFromConfigList,
|
||||
ExperimentConfiguration,
|
||||
Configuration,
|
||||
)
|
||||
|
||||
_eco_lazy_init = False
|
||||
|
||||
config = ExperimentConfiguration(
|
||||
config = Configuration(
|
||||
"/sf/bernina/config/exp/bernina_config_eco.json", name="bernina_config"
|
||||
)
|
||||
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
import logging
|
||||
import json
|
||||
from pathlib import Path
|
||||
from .eco.utilities.config import Configuration
|
||||
|
||||
startup_lazy = False
|
||||
|
||||
scopes = [
|
||||
@@ -5,3 +10,12 @@ scopes = [
|
||||
{"name": "Bernina", "facility": "SwissFEL", "module": "bernina"},
|
||||
{"name": "SwissMX", "facility": "SwissFEL", "module": "swissmx"},
|
||||
]
|
||||
|
||||
|
||||
|
||||
|
||||
settings = Configuration(Path.home() / '.ecorc', name='eco_startup_settings')
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+13
-3
@@ -51,6 +51,17 @@ def init_device(type_string, name, args=[], kwargs={}, verbose=True, lazy=True):
|
||||
raise expt
|
||||
|
||||
|
||||
def get_dependencies(inp):
|
||||
outp = []
|
||||
if isinstance(inp, dict):
|
||||
inp = inp.values()
|
||||
for ta in inp:
|
||||
if isinstance(ta, Component):
|
||||
outp.append(ta.name)
|
||||
elif isinstance(ta, dict) or isinstance(ta, list):
|
||||
outp.append(get_dependencies(ta))
|
||||
return outp
|
||||
|
||||
def replaceComponent(inp, dict_all):
|
||||
if isinstance(inp, list):
|
||||
outp = []
|
||||
@@ -74,7 +85,6 @@ def replaceComponent(inp, dict_all):
|
||||
return inp
|
||||
return outp
|
||||
|
||||
|
||||
def initFromConfigList(config_list, lazy=False):
|
||||
op = {}
|
||||
for td in config_list:
|
||||
@@ -93,7 +103,7 @@ def initFromConfigList(config_list, lazy=False):
|
||||
return op
|
||||
|
||||
|
||||
class ExperimentConfiguration:
|
||||
class Configuration:
|
||||
"""Configuration collector object collecting important settings for arbitrary use,
|
||||
linking to one or few standard config files in the file system. Sould also be used
|
||||
for config file writing."""
|
||||
@@ -144,7 +154,7 @@ def loadConfig(fina):
|
||||
|
||||
def writeConfig(fina, obj):
|
||||
with open(fina, "w") as f:
|
||||
json.dump(obj, f)
|
||||
json.dump(obj, f,indent=4)
|
||||
|
||||
|
||||
def parseChannelListFile(fina):
|
||||
|
||||
+2
-2
@@ -78,9 +78,9 @@ def main():
|
||||
shell.enable_matplotlib()
|
||||
shell()
|
||||
else:
|
||||
from IPython import embed
|
||||
from IPython import start_ipython
|
||||
|
||||
embed()
|
||||
start_ipython()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user