X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=snaps%2Ffile_utils.py;h=284ae158474c136bb155c62147259c5cb9d91747;hb=bf6e9492094e73164c98eed148962c7e0023ceb8;hp=58ec55cd69d4085b824f88cfc5d47f92c22ad3e9;hpb=399d3eddd132ed77af569d2532c47624cb7e1168;p=snaps.git diff --git a/snaps/file_utils.py b/snaps/file_utils.py index 58ec55c..284ae15 100644 --- a/snaps/file_utils.py +++ b/snaps/file_utils.py @@ -183,7 +183,7 @@ def read_yaml(config_file_path): logger.debug('Attempting to load configuration file - ' + config_file_path) config_file = None try: - with open(config_file_path) as config_file: + with open(config_file_path, 'r') as config_file: config = yaml.safe_load(config_file) logger.info('Loaded configuration') return config @@ -193,6 +193,20 @@ def read_yaml(config_file_path): config_file.close() +def persist_dict_to_yaml(the_dict, file_name): + """ + Creates a YAML file from a dict + :param the_dict: the dictionary to store + :param conf_dir: the directory used to store the config file + :return: the file object + """ + logger.info('Persisting %s to [%s]', the_dict, file_name) + file_path = os.path.expanduser(file_name) + yaml_from_dict = yaml.dump( + the_dict, default_flow_style=False, default_style='') + return save_string_to_file(yaml_from_dict, file_path) + + def read_os_env_file(os_env_filename): """ Reads the OS environment source file and returns a map of each key/value