From 0bd15126da9df96836916b2ea8be77bb6791f402 Mon Sep 17 00:00:00 2001 From: Jonathan Dale Date: Fri, 11 Apr 2025 14:28:51 -0400 Subject: [PATCH] auto-generate output filename if not given as argument --- Config_builder.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/Config_builder.py b/Config_builder.py index e942e2b..1f0d125 100644 --- a/Config_builder.py +++ b/Config_builder.py @@ -9,7 +9,9 @@ try: except ImportError: from yaml import Loader -def main(template_filepath,input_filepath,output_filepath): +def main(args: list) -> None: + template_filepath = args.template + input_filepath = args.input with open(input_filepath, 'r') as file: input_devices = file.read() @@ -25,6 +27,11 @@ def main(template_filepath,input_filepath,output_filepath): print('{} is not a valid JSON format!\n'.format(input_filepath)) return 406 + if args.output is not None: + output_filepath = args.output + else: + output_filepath = './output/{}.nso.config'.format(device_info["device"]) + template_path = os.path.dirname(os.path.abspath(template_filepath)) template_filename = os.path.basename(template_filepath) @@ -58,8 +65,6 @@ def main(template_filepath,input_filepath,output_filepath): # print('{}\n'.format(content)) # output.write('{}\n'.format(content)) - - return 0 if __name__ == "__main__": @@ -79,14 +84,14 @@ if __name__ == "__main__": parser.add_argument('-output', help='Output File', - required=True + required=False ) custom_args = parser.parse_known_args()[0] - template = custom_args.template - input = custom_args.input - output = custom_args.output - - main(template,input,output) + #template = custom_args.template + #input = custom_args.input + #output = custom_args.output + + main(custom_args) \ No newline at end of file