From 9d952a92a4e7a289fac86965d7247b8a9dae6ae7 Mon Sep 17 00:00:00 2001 From: aburston Date: Thu, 17 Dec 2020 02:55:35 -0800 Subject: [PATCH] fixed multiple python3 issues --- write_yaml_files.py | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/write_yaml_files.py b/write_yaml_files.py index 5d1164f..2582b66 100755 --- a/write_yaml_files.py +++ b/write_yaml_files.py @@ -21,26 +21,28 @@ import stat try: - - with open('data.json') as data_file: - data = json.load(data_file) - SafeDumper.add_representer( - type(None), - lambda dumper, value: dumper.represent_scalar(u'tag:yaml.org,2002:null', '') - ) + with open('data.json') as data_file: + data = json.load(data_file) - for filename,conf in data.iteritems(): - if ("group_vars/" in filename or "host_vars/" in filename) and (".yaml" in filename or ".yml" in filename): - try: - yaml_content = yaml.safe_dump(conf,default_flow_style=False,explicit_start = True) - with open(filename, 'w') as outfile: - outfile.write(yaml_content) - os.chmod(filename,"0775") - except: - print("Yaml is not generated") - else: - print("Inavalid File Name Found =====> "+filename) -except: - print("************** No configuration data is received **************************") - pass + SafeDumper.add_representer( + type(None), + lambda dumper, value: dumper.represent_scalar(u'tag:yaml.org,2002:null', '') + ) + + for filename,conf in iter(data.items()): + if ("group_vars/" in filename or "host_vars/" in filename) and (".yaml" in filename or ".yml" in filename): + try: + yaml_content = yaml.safe_dump(conf, default_flow_style=False, explicit_start = True) + with open(filename, 'w') as outfile: + outfile.write(yaml_content) + os.chmod(filename, 0o775) + except Exception as e: + print(e) + print("Yaml is not generated") + else: + print("Inavalid File Name Found =====> " + filename) + +except Exception as e: + print(e) + print("************** No configuration data is received **************************")