-
Notifications
You must be signed in to change notification settings - Fork 1
/
discover_more_catalogs.py
60 lines (47 loc) · 1.87 KB
/
discover_more_catalogs.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
"""
Identify new MongoDB catalogs for the tiled server.
This code prints additional lines that could be added
to the tiled `config.yml` file. The lines describe catalogs
with known intake descriptions that are not already configured
in the `config.yml` file.
"""
import pathlib
import yaml
def tiled_test():
from tiled.client import from_uri
client = from_uri("http://otz:8000", "dask")
cat = client["6idd"]
print(f"{cat=}")
def main():
home = pathlib.Path.home()
# print(f"{home=}")
databroker_configs = home / ".local" / "share" / "intake"
# print(f"exists:{databroker_configs.exists()} {databroker_configs}")
master = {}
for intake_yml in databroker_configs.iterdir():
if intake_yml.is_file() and intake_yml.suffix == ".yml":
# print(f"{item.suffix=} {item=}")
with open(intake_yml) as f:
db_cfg = yaml.load(f, Loader=yaml.Loader)
master.update(**db_cfg["sources"])
# print(f"{len(master)} {list(master.keys())}")
local_config = pathlib.Path(__file__).parent / "config.yml"
# print(f"exists:{local_config.exists()} {local_config}")
with open(local_config) as f:
config = yaml.load(f, Loader=yaml.Loader)
trees = {tree["path"]: tree for tree in config.get("trees", {})}
new_entries = []
for k, source in master.items():
if k not in trees:
if source.get("driver") == "bluesky-mongo-normalized-catalog":
uri = source.get("args", {}).get("metadatastore_db")
if uri is not None:
entry = dict(
path=k,
tree="databroker.mongo_normalized:Tree.from_uri",
args=dict(uri=uri),
)
new_entries.append(entry)
print(yaml.dump(new_entries))
if __name__ == "__main__":
main()