fdutils/config/__init__.py
def copy_yaml_file_without_keys(filename, yaml_data, *keys):
    """ remove information about specified keys like passwords when copying the config file """
    import copy
    yaml_data = copy.deepcopy(yaml_data)

    def get_parent_child(k):
        *parts, child = k.split('.')
        parent = yaml_data
        for p in parts:
            parent = parent.get(p, None)
            if parent is None:
                break
        return parent if parent is not yaml_data else None, child

    with open(filename, 'w') as f:
        for k in keys:
            parent, child = get_parent_child(k)
            if parent and child in parent:
                to_change = parent
            elif parent is None and child in yaml_data:
                to_change = yaml_data
            else:
                continue
            to_change[child] = 'your <{}>'.format(child)

        yaml.dump(yaml_data, f, default_flow_style=False)
 remove information about specified keys like passwords when copying the config file 
remove information about specified keys like passwords when copying the config file
remove information about specified keys like passwords when copying the config file
def copy_yaml_file_without_keys(filename, yaml_data, *keys):
    import copy
    yaml_data = copy.deepcopy(yaml_data)
    def get_parent_child(k):
        *parts, child = k.split('.')
        parent = yaml_data
        for p in parts:
            parent = parent.get(p, None)
            if parent is None:
                break
        return parent if parent is not yaml_data else None, child
    with open(filename, 'w') as f:
        for k in keys:
            parent, child = get_parent_child(k)
            if parent and child in parent:
                to_change = parent
            elif parent is None and child in yaml_data:
                to_change = yaml_data
            else:
                continue
            to_change[child] = 'your <{}>'.format(child)
        yaml.dump(yaml_data, f, default_flow_style=False)
def copy_yaml_file_without_keys ( filename , yaml_data , * keys ) : import copy yaml_data = copy . deepcopy ( yaml_data ) def get_parent_child ( k ) : * parts , child = k . split ( '.' ) parent = yaml_data for p in parts : parent = parent . get ( p , None ) if parent is None : break return parent if parent is not yaml_data else None , child with open ( filename , 'w' ) as f : for k in keys : parent , child = get_parent_child ( k ) if parent and child in parent : to_change = parent elif parent is None and child in yaml_data : to_change = yaml_data else : continue to_change [ child ] = 'your <{}>' . format ( child ) yaml . dump ( yaml_data , f , default_flow_style = False )
remove information about specified keys like passwords when copying the config file
remove information about specified keys like passwords when copying the config file
""" remove information about specified keys like passwords when copying the config file """
filename
yaml_data