auto-generate output filename if not given as argument
This commit is contained in:
@@ -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)
|
||||
@@ -59,8 +66,6 @@ def main(template_filepath,input_filepath,output_filepath):
|
||||
# print('{}\n'.format(content))
|
||||
# output.write('{}\n'.format(content))
|
||||
|
||||
return 0
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
import argparse
|
||||
@@ -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
|
||||
#template = custom_args.template
|
||||
#input = custom_args.input
|
||||
#output = custom_args.output
|
||||
|
||||
main(template,input,output)
|
||||
main(custom_args)
|
||||
|
||||
Reference in New Issue
Block a user