Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: add an IOC that builds itself from a json file #489

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions caproto/ioc_examples/bucket_of_pvs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python3
from caproto.server import pvproperty, PVGroup, template_arg_parser, run
import json


def ingest_pv_dict(inp):
type_map = {'float': float,
'int': int}
body = {}
for (i, (k, (dtype, rec_type))) in enumerate(inp.items()):
body[str(i)] = pvproperty(name=k,
dtype=type_map[dtype],
mock_record=rec_type)
tacaswell marked this conversation as resolved.
Show resolved Hide resolved

return type('BucketOPVs', (PVGroup,), body)


if __name__ == '__main__':
parser, split_args = template_arg_parser(
default_prefix='',
desc='An IOC that servers a bucket of disconnected PVs.')

parser.add_argument('--json',
help='The file to read the PVs from',
required=True, type=str)
args = parser.parse_args()
ioc_options, run_options = split_args(args)

with open(args.json, 'r') as fin:
inp = json.load(fin)
klass = ingest_pv_dict(inp)

ioc = klass(**ioc_options)
run(ioc.pvdb, **run_options)