#!/usr/bin/env python3 import sys import configtools if __name__ == "__main__": opts, args = configtools.parse_args( configtools.options, usage="Usage: getconf.py [options] <item>|-a <section> [<section> ...]", ) conf, files = configtools.init(opts, "_PBENCH_SERVER_CONFIG") status = configtools.main(conf, args, opts, files) sys.exit(status)
return 0 # hosts in a single class if opts.listclass in hostclasses: hosts = configtools.get_list(conf.get("hosts", opts.listclass)) configtools.print_list(hosts, sep) return 0 # otherwise all the args should be classes: gather up their hosts: hosts = [] for a in args: if a in hostclasses: hosts.extend(configtools.get_list(conf.get("hosts", a))) else: return 1 configtools.print_list(hosts, sep) return 0 options = [ make_option("-a", "--all", action="store_true", dest="all", help="print all hosts in all classes"), make_option("-l", "--list", action="store_true", dest="list", help="print it as a shell list, translating commas to spaces"), make_option("-L", "--listclasses", action="store_true", dest="listclasses", help="print the list of host classes"), make_option("-c", "--class", action="store", dest="listclass", help="print the list of hosts in a host class"), ] if __name__ == '__main__': opts, args = configtools.parse_args(options) conf, files = configtools.init(opts) status = main(conf, args, opts) sys.exit(status)
dest="list", help="print it as a shell list, translating commas to spaces"), make_option("-L", "--listfiles", action="store_true", dest="listfiles", help="print the list of config files"), ] if __name__ == '__main__': opts, args = configtools.parse_args( options, usage='Usage:\n' 'getconf.py -d|--dump - dumps the fully-resolved config file.\n' 'getconf.py -L|--listfiles - dumps the list of config files to be resolved.\n' 'getconf.py -a|--all <section> - prints all the items and their values found in the section.\n' 'getconf.py <item> <section> [<section>...] - prints the value of <item> as found in the <section>.\n' ' If there is a list of sections, the <item> is looked\n' ' for in each <section> from left to right: the first\n' ' value found in the scan is printed.' ) conf, files = configtools.init(opts) if not conf: sys.exit(1) if opts.dump: conf.write(sys.stdout) sys.exit(0) if opts.listfiles:
options = [ make_option("-a", "--all", action="store_true", dest="all", help="print all hosts in all classes"), make_option("-l", "--list", action="store_true", dest="list", help="print it as a shell list, translating commas to spaces"), make_option("-L", "--listclasses", action="store_true", dest="listclasses", help="print the list of host classes"), make_option("-c", "--class", action="store", dest="listclass", help="print the list of hosts in a host class"), ] if __name__ == '__main__': opts, args = configtools.parse_args(options) conf, files = configtools.init(opts) if not conf: sys.exit(1) status = main(conf, args, opts) sys.exit(status)
sep = ',' if opts.list: sep = ' ' if args: option = args[0] for sec in args[1:]: if conf.has_section(sec): if conf.has_option(sec, option): configtools.print_list(configtools.get_list(conf.get(sec, option)), sep) return 0 return 1 options = [ make_option("-a", "--all", action="store_true", dest="all", help="print all items in section"), make_option("-d", "--dump", action="store_true", dest="dump", help="print everything"), make_option("-l", "--list", action="store_true", dest="list", help="print it as a shell list, translating commas to spaces"), make_option("-L", "--listfiles", action="store_true", dest="listfiles", help="print the list of config files"), ] if __name__ == '__main__': opts, args = configtools.parse_args(options, usage='Usage: getconf.py [options] <item>|-a <section> [<section> ...]') conf, files = configtools.init(opts) if opts.listfiles: files.reverse() print(files) sys.exit(0) status = main(conf, args, opts) sys.exit(status)