Пример #1
0
def get_configuration():
    config = DEFAULT_CONFIG
    configpath = expand(os.path.join("~", CONFIG_NAME))
    if os.path.isfile(configpath):
        config.update(load_yaml(os.path.join("~", CONFIG_NAME)))
        external_configs = config['settings'].get('external_hooks', [])
        for conf in external_configs:
            if os.path.isfile(expand(conf)):
                newhooks = load_yaml(conf)['hooks']
                if newhooks:
                    config['hooks'].extend(newhooks)
    return config
Пример #2
0
def get_configuration():
    config = DEFAULT_CONFIG
    configpath = expand(os.path.join("~", CONFIG_NAME))
    if os.path.isfile(configpath):
        config.update(load_yaml(os.path.join("~", CONFIG_NAME)))
        external_configs = config['settings'].get('external_hooks', [])
        for conf in external_configs:
            if os.path.isfile(expand(conf)):
                newhooks = load_yaml(conf)['hooks']
                if newhooks:
                    config['hooks'].extend(newhooks)
    return config
Пример #3
0
def add_external_hook(filename,
                      path,
                      hooktype=DEFAULT_TYPE,
                      enter=[],
                      exit=[],
                      unique=False):
    '''
    Will add an external hook to the YAML specfified
    YAML file.
    '''
    if os.path.isfile(expand(filename)):
        config = load_yaml(filename)
        if 'hooks' not in config:
            config['hooks'] = []
    else:
        config = {'hooks': []}
    if unique and config['hooks']:
        removed = []
        for hook in config['hooks']:
            if hook['path'] == path:
                removed.append(hook)
        for hook in removed:
            config['hooks'].remove(hook)
    hook = {'path': path, 'type': hooktype}
    if enter:
        hook['enter'] = enter
    if exit:
        hook['exit'] = exit
    config['hooks'].append(hook)
    save_yaml(filename, config)
Пример #4
0
def add_external_hook(filename, path, hooktype=DEFAULT_TYPE, 
                      enter=[], exit=[], unique=False):
    '''
    Will add an external hook to the YAML specfified
    YAML file.
    '''
    if os.path.isfile(expand(filename)):
        config = load_yaml(filename)
        if 'hooks' not in config:
            config['hooks'] = []
    else:
            config = {'hooks': []}
    if unique and config['hooks']:
        removed = []
        for hook in config['hooks']:
            if hook['path'] == path:
                removed.append(hook)
        for hook in removed:
            config['hooks'].remove(hook)
    hook = {'path': path, 'type': hooktype}
    if enter:
        hook['enter'] = enter
    if exit:
        hook['exit'] = exit
    config['hooks'].append(hook)
    save_yaml(filename, config)
Пример #5
0
def remove_external_hook(filename, path):
    '''
    Removes all hooks for a given path.
    '''
    if os.path.isfile(expand(filename)):
        config = load_yaml(filename)
        config['hooks'] = [h for h in config['hooks'] if h['path'] != path]
        save_yaml(filename, config)
Пример #6
0
def remove_external_hook(filename, path):
    '''
    Removes all hooks for a given path.
    '''
    if os.path.isfile(expand(filename)):
        config = load_yaml(filename)
        config['hooks'] = [h for h in config['hooks'] if h['path'] != path]
        save_yaml(filename, config)
Пример #7
0
def save_yaml(path, config):
    config = expand_config(config)
    config_file = open(expand(path), 'w')
    config_file.write(dump(config, default_flow_style=False))
    config_file.close()
Пример #8
0
def load_yaml(path):
    config_file = open(expand(path), 'r+')
    config = load(config_file, Loader=Loader)
    config_file.close()
    return expand_config(config)
Пример #9
0
def expand_config(config):
    if config['hooks']:
        for hook in config['hooks']:
            hook['path'] = expand(hook['path'])
    return config
Пример #10
0
def save_yaml(path, config):
    config = expand_config(config)
    config_file = open(expand(path), 'w')
    config_file.write(dump(config, default_flow_style=False))
    config_file.close()
Пример #11
0
def load_yaml(path):
    config_file = open(expand(path), 'r+')
    config = load(config_file, Loader=Loader)
    config_file.close()
    return expand_config(config)
Пример #12
0
def expand_config(config):
    if config['hooks']:
        for hook in config['hooks']:
            hook['path'] = expand(hook['path'])
    return config