@@ -15,14 +15,15 @@ def get_modes(ins: dict, type: str) -> list[str]:
1515 return []
1616
1717
18- def generate_instrument_configs (ins_s : str ) -> str :
18+ def generate_instrument_configs (ins_s : str , soar : bool = False ) -> str :
1919 """
2020 Generate instrument models based on the output of the OCS
2121 instrument data endpoint. For LCO, this endpoint resides
2222 at https://observe.lco.global/api/instruments/
2323
2424 Args:
2525 ins_s (str): The input json containing instrument data.
26+ soar (bool): Whether to generate SOAR instruments.
2627
2728 Returns:
2829 str: Generated Python Pydantic models as a string.
@@ -36,13 +37,20 @@ def generate_instrument_configs(ins_s: str) -> str:
3637 template = j_env .get_template ("instruments.jinja" )
3738 ins_data = json .loads (ins_s )
3839 instruments = []
40+ if soar :
41+ prefix = ""
42+ filtered = {k : v for k , v in ins_data .items () if "soar" in k .lower ()}
43+ else :
44+ prefix = "Lco"
45+ filtered = {k : v for k , v in ins_data .items () if "soar" not in k .lower ()}
46+
3947 # Instruments endpoint seems inconsistent, this should keep our output consistent
40- ordered = dict (sorted (ins_data .items ()))
48+ ordered = dict (sorted (filtered .items ()))
4149 for instrument_type , ins in ordered .items ():
4250 instruments .append (
4351 {
4452 "instrument_type" : instrument_type ,
45- "class_name" : f"Lco { textcase .pascal (instrument_type )} " ,
53+ "class_name" : f"{ prefix } { textcase .pascal (instrument_type )} " ,
4654 "config_types" : [
4755 c ["code" ] for c in ins ["configuration_types" ].values ()
4856 ],
@@ -58,11 +66,15 @@ def generate_instrument_configs(ins_s: str) -> str:
5866 }
5967 )
6068
61- return template .render (instruments = instruments )
69+ return template .render (instruments = instruments , soar = soar )
6270
6371
6472if __name__ == "__main__" :
73+ try :
74+ soar = sys .argv .pop (1 ) == "soar"
75+ except IndexError :
76+ soar = False
6577 # Accepts input from stdin or a file argument
6678 with fileinput .input () as f :
6779 ins_json = "" .join (list (f ))
68- sys .stdout .write (generate_instrument_configs (ins_json ))
80+ sys .stdout .write (generate_instrument_configs (ins_json , soar = soar ))
0 commit comments