Skip to content
Snippets Groups Projects
Commit 2770ec66 authored by Karim Ahmed's avatar Karim Ahmed
Browse files

make max-pulses a list not a str

parent b38be252
No related branches found
No related tags found
1 merge request!174Feat/range pulse idxs
......@@ -10,7 +10,8 @@ available_options = {
"blc-noise": bool,
"dont-zero-nans": bool,
"dont-zero-orange": bool,
"max-pulses": str},
"max-pulses": list,
"calfile": str},
}
parser = argparse.ArgumentParser(
......@@ -41,7 +42,12 @@ detector = args["detector"]
if detector is not None:
for option, typ in available_options[detector].items():
parser.add_argument(f"--{option}", type=typ)
if typ == list:
print(typ)
nargs = '+'
else:
nargs = None
parser.add_argument(f"--{option}", type=typ, nargs=nargs)
if add_help:
sys.argv.append("--help")
......@@ -61,6 +67,9 @@ new_conf = {task: {instrument: {detector: {}}}}
for key, value in args.items():
key = key.replace("_", "-")
if key in available_options[detector] and value is not None:
if isinstance(value, list):
for v in value:
value[value.index(v)] = ''.join(v)
new_conf[task][instrument][detector][key] = value
pyaml = yaml.dump(new_conf, default_flow_style=False)
......
......@@ -239,6 +239,18 @@ async def query_rid(conn, socket, rid):
socket.send(msg.encode())
async def parse_config(cmd, config):
for key, value in config.items():
if isinstance(value, list):
cmd += ["--{}".format(key)]
cmd += [str(v) for v in value]
elif isinstance(value, bool):
cmd += ["--{}".format(key)]
else:
cmd += ["--{}".format(key), str(value)]
return cmd
async def update_job_db(config):
""" Update the job database and send out updates to MDC
......@@ -631,15 +643,8 @@ async def server_runner(config, mode):
if len(run_config):
dconfig["runs"] = ",".join(run_config)
for key, value in dconfig.items():
if not isinstance(value, bool):
if " " in str(value):
cmd += ["--{}".format(key)]
cmd += [str(v) for v in value.split(" ")]
else:
cmd += ["--{}".format(key), str(value)]
else:
cmd += ["--{}".format(key)]
cmd = await parse_config(cmd, dconfig)
ret = await run_correction(job_db, cmd, mode, proposal,
wait_runs[0], rid)
status.append(ret)
......@@ -685,15 +690,9 @@ async def server_runner(config, mode):
detector, _ = detector.split("-")
cmd = ["python", "-m", "xfel_calibrate.calibrate",
detector, "CORRECT"]
for key, value in dconfig.items():
if not isinstance(value, bool):
if " " in str(value):
cmd += ["--{}".format(key)]
cmd += [str(v) for v in value.split(" ")]
else:
cmd += ["--{}".format(key), str(value)]
else:
cmd += ["--{}".format(key)]
cmd = await parse_config(cmd, dconfig)
if priority:
cmd += ["--priority", str(priority)]
ret = await run_correction(job_db, cmd, mode, proposal,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment