Skip to content
Snippets Groups Projects

Detect cycle automatically in update_config script

Merged Philipp Schmidt requested to merge feat/update-config-auto-cycle into master
#!/usr/bin/env python3
from pathlib import Path
import argparse
import json
import sys
@@ -12,6 +13,7 @@ import zmq
AGIPD_CONFIGURATIONS = {
"correct":
{
"common-mode": {'type': bool},
"force-hg-if-below": {'type': int},
"rel-gain": {'type': bool},
"xray-gain": {'type': bool},
@@ -112,8 +114,9 @@ required_args.add_argument(
choices=list(AVAILABLE_DETECTORS.keys()))
required_args.add_argument(
'--proposal', type=str,
help='The proposal number, without leading p, but with leading zeros.')
required_args.add_argument('--cycle', type=str, help='The facility cycle.')
help='The proposal number, without leading p, but with leading zeros. ')
required_args.add_argument('--cycle', type=str, help='The facility cycle, '
'detected automatically if omitted')
action_group = required_args.add_mutually_exclusive_group()
action_group.add_argument(
@@ -142,6 +145,22 @@ parser.add_argument(
)
def _find_cycle(proposal: str) -> str:
try:
proposal_no = int(proposal)
except ValueError:
raise ValueError('proposal number cannot be converted to a number')
proposal_path = next(
# /gpfs/exfel/exp/<instrument>/<cycle>/p<proposal>/
Path('/gpfs/exfel/exp').glob(f'*/*/p{proposal_no:06d}'), None)
if proposal_path is None:
raise ValueError('could not locate proposal on GPFS')
return proposal_path.parts[-2]
def _add_available_configs_to_arg_parser(karabo_id: str, action: str):
"""Add the available configuration for the selected detector
to the argument parser.
@@ -264,13 +283,11 @@ def main():
args = vars(parser.parse_args(argv))
if (
instrument is None or
proposal is None or
cycle is None
):
print("Need to define all fields")
if instrument is None or proposal is None:
print("Need to define all required fields")
sys.exit(1)
elif cycle is None:
cycle = _find_cycle(proposal)
new_conf = _create_new_config_from_args_input(
instrument=instrument,
@@ -296,7 +313,7 @@ def main():
"SASEX",
args["karabo_id"],
instrument,
args["cycle"],
cycle,
args["proposal"],
json.dumps(new_conf),
str(args["apply"]),
Loading