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

Parse_lists_and_dicts_from_string #112

Open
wants to merge 1 commit into
base: INTER_wip
Choose a base branch
from
Open
Changes from all commits
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
16 changes: 14 additions & 2 deletions technique/reflectometry/instrument_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
except ImportError:
from mocks import g

from ast import literal_eval


class InstrumentConstant(object):
"""
Expand Down Expand Up @@ -80,7 +82,17 @@ def get_reflectometry_value(value_name):
"""
pv_name = "REFL_01:CONST:{}".format(value_name)
value = g.get_pv(pv_name, is_local=True)
if value is None:
raise IOError("PV {} does not exist".format(pv_name))

if isinstance(value, str)
try:
# this will try and convert from str to dict/list
value = literal_eval(value)
except ValueError:
# probably OK, just return the original string
return value
except SyntaxError:
# Not ok, raise here, a list has probably not been finished with a ] or similar
raise Exception(f"Constant {value_name} cannot be parsed, evaluating {value} threw an exception")


return value