From 7ca110dbf96d46d751040f9cd0a108849fb4169e Mon Sep 17 00:00:00 2001 From: Ben Vincent Date: Sat, 4 Nov 2023 20:09:21 +1100 Subject: [PATCH] feat: inject parameters into enc output - add the enc_role parameter as a copy of classes - add the enc_env parameter as a copy of environment --- enc.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/enc.py b/enc.py index 5cd4bd9..2e11abe 100755 --- a/enc.py +++ b/enc.py @@ -28,15 +28,29 @@ def main(): with open(file_path, "r") as f: data = yaml.safe_load(f) - # If the environment is 'testing', remove it from the output + # Initialize 'parameters' if it doesn't exist + if "parameters" not in data: + data["parameters"] = {} + + # Add 'enc_role' parameter with classes data + if "classes" in data: + data["parameters"]["enc_role"] = data["classes"] + + # Copy the environment to the parameters, if it exists + if data.get("environment"): + data["parameters"]["enc_env"] = data["environment"] + + # If the environment is 'testing', remove it if data.get("environment") == "testing": data.pop("environment", None) # Print the YAML without the 'environment' if it was 'testing' print(yaml.dump(data)) + except IOError as e: print("Could not open {}: {}".format(file_path, e), file=sys.stderr) sys.exit(1) + except yaml.YAMLError as e: print("Error in {}: {}".format(file_path, e), file=sys.stderr) sys.exit(1)