def load_yaml_replace_var_local()

in spark-on-eks/source/lib/util/manifest_reader.py [0:0]


def load_yaml_replace_var_local(yaml_file, fields, multi_resource=False, write_output=False):

    file_to_replace=path.join(path.dirname(__file__), yaml_file)
    if not path.exists(file_to_replace):
        print("The file {} does not exist"
            "".format(file_to_replace))
        sys.exit(1)

    try:
        with open(file_to_replace, 'r') as f:
            filedata = f.read()

            for searchwrd, replwrd in fields.items():
                filedata = filedata.replace(searchwrd, replwrd)
            if multi_resource:
                yaml_data = list(yaml.full_load_all(filedata))
            else:
                yaml_data = yaml.full_load(filedata) 
        if write_output:
            with open(file_to_replace, "w") as f:
                yaml.dump(yaml_data, f, default_flow_style=False, allow_unicode = True, sort_keys=False)
    
        # print(yaml_data)
    except request.URLError as e:
        print(e.reason)
        sys.exit(1)

    return yaml_data