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)