-
Notifications
You must be signed in to change notification settings - Fork 1
/
startup.py
executable file
·93 lines (75 loc) · 2.52 KB
/
startup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python
from eco import ecocnf
from eco.utilities.config import Terminal
def main():
import argparse
parser = argparse.ArgumentParser(description="eco startup utility")
parser.add_argument(
"-s",
"--scope",
type=str,
default=None,
help="scope name, usually instrument or beamline",
)
parser.add_argument(
"-a",
"--scopes_available",
action="store_true",
default=False,
help="print available scopes.",
)
parser.add_argument(
"-l", "--lazy", action="store_true", default=False, help="lazy initialisation"
)
parser.add_argument(
"--shell", action="store_true", default=False, help="open eco in ipython shell"
)
parser.add_argument(
"--pylab", type=bool, default=True, help="open ipython shell in pylab mode"
)
arguments = parser.parse_args()
scope = arguments.scope
# scope = 'bernina'
if arguments.scopes_available:
print("{:<15s}{:<15s}{:<15s}".format("module", "name", "facility"))
for ts in ecocnf.scopes:
print(
" {:<14s} {:<14s} {:<14s}".format(
ts["module"], ts["name"], ts["facility"]
)
)
return
print(
" ___ _______\n / -_) __/ _ \ \n Experiment Control \__/\__/\___/ \n\n"
)
term = Terminal(scope=scope)
if scope:
# import importlib
# eco = importlib.import_module('eco')
# mdl = importlib.import_module(scope,package=eco)
# mdl = importlib.import_module('eco.bernina')
if arguments.lazy:
ecocnf.startup_lazy = True
exec(f"import eco.{scope} as {scope}")
# exec(f'{scope}.init(lazy=ecocnf.startup_lazy)')
exec(f"from eco.{scope} import *")
# is there an __all__? if so respect it
# if "__all__" in mdl.__dict__:
# names = mdl.__dict__["__all__"]
# else:
# otherwise we import all names that don't begin with _
# names = [x for x in mdl.__dict__ if not x.startswith("_")]
# now drag them in
# globals().update({k: getattr(mdl, k) for k in names})
term.set_title()
print(arguments)
if arguments.shell:
if arguments.pylab:
print("start pylab with %pylab")
from IPython import embed
embed()
else:
from IPython import embed
embed()
if __name__ == "__main__":
main()