Пример #1
0
def abiconf_keys(options):
    """Find configuration files containing keywords."""
    configs = get_configs(options)
    if options.keys is None or not options.keys:
        # Print list of available keywords.
        all_keys = set()
        for conf in configs:
            all_keys.update(conf.meta["keywords"])

        cprint(marquee("Available keywords"), "yellow")
        for chunk in chunks(all_keys, 7):
            cprint(", ".join(chunk), "magenta")

    else:
        # Find configuration files containing keywords.
        keys = options.keys
        if is_string(keys): keys = [keys]
        keys = set(keys)
        nfound = 0
        for conf in configs:
            if keys.issubset(conf.meta["keywords"]):
                nfound += 1
                print("")
                cprint(marquee(conf.basename), "yellow")
                if options.verbose:
                    conf.cprint()
                else:
                    pprint(conf.meta)

        if options.verbose == 0 and nfound != 0:
            print("\nUse -v for further information")

    return 0
Пример #2
0
def abiconf_opts(options):
    """List available configure options."""
    confopts = AbinitConfigureOptions.from_myoptions_conf()

    if options.optnames is None or not options.optnames:
        # Print all options.
        cprint(marquee("Available options"), "yellow")
        table = [("name", "default", "status")]

        if options.verbose == 0:
            for opt in confopts.values():
                table.append((opt.name, str(opt.default), opt.status))
            pprint_table(table)
            print("\nUse -v for further information")

        else:
            for opt in confopts.values():
                cprint(marquee(opt.name), "yellow")
                print(opt)

    else:
        for optname in options.optnames:
            opt = confopts[optname]
            cprint(marquee(opt.name), "yellow")
            print(opt)

    return 0
Пример #3
0
def abiconf_list(options):
    """List all configuration files."""
    configs = get_configs(options)

    width = 92
    for i, config in enumerate(configs):
        if options.verbose == 0:
            if i == 0:
                cprint(marquee("Available configuration files"), "yellow")
            print("[%d] %s" % (i, config.basename))
        else:
            cprint(marquee(config.basename, width=width), "yellow")
            config.cprint()
            print(width * "=")

    if options.verbose == 0: print("\nUse -v for further information")
    return 0
Пример #4
0
def abiconf_hostname(options):
    """Find configuration files for this hostname."""
    def show_hostnames():
        cprint(marquee("Available hostnames"), "yellow")
        all_hosts = sorted({conf.meta["hostname"] for conf in configs})
        for chunk in chunks(all_hosts, 7):
            cprint(", ".join(chunk), "blue")

    if options.show_hostnames:
        show_hostnames()
        return 0

    hostname = gethostname() if options.hostname is None else options.hostname
    nfound = 0
    configs = get_configs(options)
    for conf in configs:
        # TODO: Should handle foo.bar.be case
        #if not (hostname in conf.meta["keywords"] or hostname in conf.basename):
        #print(conf)
        if not hostname in conf.meta["hostname"]:
            continue
        nfound += 1
        cprint(marquee(conf.basename), "yellow")
        if options.verbose:
            conf.cprint()
        else:
            pprint(conf.meta)

    if nfound == 0:
        cprint(
            "No configuration file for `%s`. Will print internal list." %
            hostname, "red")
        show_hostnames()
    else:
        if options.verbose == 0: print("\nUse -v for further information")

    return 0
Пример #5
0
 def show_hostnames():
     cprint(marquee("Available hostnames"), "yellow")
     all_hosts = sorted({conf.meta["hostname"] for conf in configs})
     for chunk in chunks(all_hosts, 7):
         cprint(", ".join(chunk), "blue")