Exemple #1
0
def load_config(*paths, overrides=None):
    return _load_config(Options,
                        defaults,
                        parse_config,
                        merge_configs,
                        *paths,
                        overrides=overrides)
Exemple #2
0
def load_config(*paths: str,
                overrides: Optional[Iterable[str]] = None) -> DiffOptions:
    return _load_config(Options,
                        defaults,
                        parse_config,
                        merge_configs,
                        *paths,
                        overrides=overrides)
Exemple #3
0
def load_config(*paths: str,
                overrides: Optional[Iterable[str]] = None,
                hostname: str = '!',
                username: str = '') -> SSHOptions:
    from .options.parse import (create_result_dict, merge_result_dicts,
                                parse_conf_item)
    from .options.utils import (first_seen_positions, get_per_hosts_dict,
                                init_results_dict)

    def merge_dicts(base: Dict[str, Any], vals: Dict[str,
                                                     Any]) -> Dict[str, Any]:
        base_phd = get_per_hosts_dict(base)
        vals_phd = get_per_hosts_dict(vals)
        for hostname in base_phd:
            vals_phd[hostname] = merge_result_dicts(base_phd[hostname],
                                                    vals_phd.get(hostname, {}))
        ans: Dict[str, Any] = vals_phd.pop(vals['hostname'])
        ans['per_host_dicts'] = vals_phd
        return ans

    def parse_config(lines: Iterable[str]) -> Dict[str, Any]:
        ans: Dict[str, Any] = init_results_dict(create_result_dict())
        parse_config_base(lines, parse_conf_item, ans)
        return ans

    overrides = tuple(overrides) if overrides is not None else ()
    first_seen_positions.clear()
    first_seen_positions['*'] = 0
    opts_dict, paths = _load_config(defaults,
                                    parse_config,
                                    merge_dicts,
                                    *paths,
                                    overrides=overrides,
                                    initialize_defaults=init_results_dict)
    phd = get_per_hosts_dict(opts_dict)
    final_dict: Dict[str, Any] = {}
    for hostname_pat in sorted(phd, key=first_seen_positions.__getitem__):
        if host_matches(hostname_pat, hostname, username):
            od = phd[hostname_pat]
            for k, v in od.items():
                if isinstance(v, dict):
                    bv = final_dict.setdefault(k, {})
                    bv.update(v)
                else:
                    final_dict[k] = v
    first_seen_positions.clear()
    return SSHOptions(final_dict)
Exemple #4
0
def load_config(*paths: str,
                overrides: Optional[Iterable[str]] = None) -> DiffOptions:
    from .options.parse import (create_result_dict, merge_result_dicts,
                                parse_conf_item)

    def parse_config(lines: Iterable[str]) -> Dict[str, Any]:
        ans: Dict[str, Any] = create_result_dict()
        parse_config_base(
            lines,
            parse_conf_item,
            ans,
        )
        return ans

    overrides = tuple(overrides) if overrides is not None else ()
    opts_dict, paths = _load_config(defaults,
                                    parse_config,
                                    merge_result_dicts,
                                    *paths,
                                    overrides=overrides)
    opts = DiffOptions(opts_dict)
    opts.config_paths = paths
    opts.config_overrides = overrides
    return opts