Пример #1
0
def load(filepaths, fields=[]):
    '''
    Load YAML settings from a list of file paths given.

        - File paths in the list gets the priority by their orders
          of the list.
        - If fields are set, only the selected fields are loaded in the
          returned object. For example, fields=['users', 'hosts'] will
          eliminate all of the other loaded fields except for them.
    '''
    filepath = _locate_file(filepaths)

    # TODO:
    # Add support to load the selected fields only.
    # It could take some time if you had a very large amount of fields.
    # Currently, all settings are loaded and then pruned out.
    # --------------------------------------------
    # load settings into a YAMLDict object
    yaml_dict = yamldict.load(open(filepath))
    # if set, limit the YAMLDict object to only the selected fields
    if fields:
        yaml_dict.limit(fields)
    # --------------------------------------------

    # return YAMLDict object
    return yaml_dict
Пример #2
0
def load(filepaths, fields=[]):
    '''
    Load YAML settings from a list of file paths given.

        - File paths in the list gets the priority by their orders
          of the list.
        - If fields are set, only the selected fields are loaded in the
          returned object. For example, fields=['users', 'hosts'] will
          eliminate all of the other loaded fields except for them.
    '''
    filepath = _locate_file(filepaths)

    # TODO:
    # Add support to load the selected fields only.
    # It could take some time if you had a very large amount of fields.
    # Currently, all settings are loaded and then pruned out.
    # --------------------------------------------
    # load settings into a YAMLDict object
    yaml_dict = yamldict.load(open(filepath))
    # if set, limit the YAMLDict object to only the selected fields
    if fields:
        yaml_dict.limit(fields)
    # --------------------------------------------

    # return YAMLDict object
    return yaml_dict
Пример #3
0
 def _set_env_var(path, node):
     env_path = "{}{}{}".format(
         prefix.upper(), '_' if prefix else '',
         '_'.join([str(key).upper() for key in path]))
     env_val = os.environ.get(env_path, None)
     if env_val is not None:
         # convert the value to a YAML-defined type
         env_dict = yamldict.load('val: {}'.format(env_val))
         return env_dict.val
     else:
         return None
Пример #4
0
 def _set_env_var(path, node):
     env_path = "{0}{1}{2}".format(
         prefix.upper(),
         '_' if prefix else '',
         '_'.join([str(key).upper() for key in path])
     )
     env_val = os.environ.get(env_path, None)
     if env_val is not None:
         # convert the value to a YAML-defined type
         env_dict = yamldict.load('val: {0}'.format(env_val))
         return env_dict.val
     else:
         return None