diff --git a/Makefile b/Makefile deleted file mode 100644 index 0dd34fa..0000000 --- a/Makefile +++ /dev/null @@ -1,42 +0,0 @@ -all: build build/bin/getconf.py build/bin/gethosts.py build/setup.py - -build/setup.py: setup.py - cp setup.py build/ - -build/bin/getconf.py: build/bin/getconf.2.py build/bin/getconf.3.py - (cd build/bin; ln -sf getconf.2.py getconf.py) - -build/bin/gethosts.py: build/bin/gethosts.2.py build/bin/gethosts.3.py - (cd build/bin; ln -sf gethosts.2.py gethosts.py) - -build/bin/getconf.2.py: bin/getconf.2.py - mkdir -p build/bin - cp bin/getconf.2.py build/bin/ - -build/bin/gethosts.2.py: bin/gethosts.2.py - mkdir -p build/bin - cp bin/gethosts.2.py build/bin/ - -build/bin/getconf.3.py: bin/getconf.2.py - sed '1s/$$/3/' bin/getconf.2.py > $@ - chmod ugo+x $@ - -build/bin/gethosts.3.py: bin/gethosts.2.py - sed '1s/$$/3/' bin/gethosts.2.py > $@ - chmod ugo+x $@ - -build/configtools/__init__.py: configtools/__init__.py - mkdir -p build/configtools - cp configtools/__init__.py build/configtools/ - -prep-for-rpm: build/bin/getconf.2.py build/bin/gethosts.2.py build/setup.py build/configtools/__init__.py - -build: setup.py configtools/__init__.py - python setup.py build - -install: build - python setup.py --skip-build install - -clean: - rm -f configtools/__init__.pyc - rm -rf build diff --git a/bin/getconf.2.py b/bin/getconf.2.py deleted file mode 100755 index 9167128..0000000 --- a/bin/getconf.2.py +++ /dev/null @@ -1,56 +0,0 @@ -#! /usr/bin/env python -from __future__ import print_function - -import sys -import os -import configtools -from optparse import make_option - -def main(conf, args, opts): - if not conf: - return 1 - - if opts.dump: - conf.write(sys.stdout) - return 0 - - if opts.all: - for sec in args: - if conf.has_section(sec): - print("[%s]" % (sec)) - items = conf.items(sec) - items.sort() - for (n, v) in items: - print("%s = %s" % (n, v)) - print() - return 0 - - 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] |-a
[
...]') - conf, files = configtools.init(opts) - if opts.listfiles: - files.reverse() - print(files) - sys.exit(0) - status = main(conf, args, opts) - sys.exit(status) diff --git a/bin/getconf.3.py b/bin/getconf.3.py deleted file mode 100755 index 27fd46e..0000000 --- a/bin/getconf.3.py +++ /dev/null @@ -1,53 +0,0 @@ -#! /usr/bin/env python3 -from __future__ import print_function - -import sys -import os -import configtools -from optparse import make_option - -def main(conf, args, opts): - - if opts.dump: - conf.write(sys.stdout) - return 0 - - if opts.all: - for sec in args: - if conf.has_section(sec): - print("[%s]" % (sec)) - items = conf.items(sec) - items.sort() - for (n, v) in items: - print("%s = %s" % (n, v)) - print() - return 0 - - sep = ',' - if opts.list: - sep = ' ' - - 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] |-a
[
...]') - conf, files = configtools.init(opts) - if opts.listfiles: - files.reverse() - print(files) - sys.exit(0) - status = main(conf, args, opts) - sys.exit(status) diff --git a/bin/getconf.py b/bin/getconf.py deleted file mode 120000 index 911d8c0..0000000 --- a/bin/getconf.py +++ /dev/null @@ -1 +0,0 @@ -getconf.3.py \ No newline at end of file diff --git a/bin/getconf.py b/bin/getconf.py new file mode 100755 index 0000000..8786cef --- /dev/null +++ b/bin/getconf.py @@ -0,0 +1,57 @@ +#! /usr/bin/env python +from __future__ import print_function + +import sys +import os +import configtools +from optparse import make_option + +def main(conf, args, opts): + if opts.dump: + conf.write(sys.stdout) + return 0 + + if opts.all: + for sec in args: + if conf.has_section(sec): + print("[%s]" % (sec)) + items = conf.items(sec) + items.sort() + for (n, v) in items: + print("%s = %s" % (n, v)) + print() + return 0 + + sep = ',' + if opts.list: + sep = ' ' + + 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] |-a
[
...]') + conf, files = configtools.init(opts) + if not conf: + sys.exit(1) + if opts.listfiles: + files.reverse() + print(files) + sys.exit(0) + if args: + status = main(conf, args, opts) + else: + status = 1 + sys.exit(status) diff --git a/bin/gethosts.3.py b/bin/gethosts.3.py deleted file mode 100644 index a333c0e..0000000 --- a/bin/gethosts.3.py +++ /dev/null @@ -1,57 +0,0 @@ -#! /usr/bin/env python3 -from __future__ import print_function - -import sys -import os -import configtools -from optparse import make_option - -def main(conf, args, opts): - - sep = ',' - if opts.list: - sep = ' ' - - hostclasses = configtools.get_host_classes(conf) - if opts.listclasses: - configtools.print_list(hostclasses, sep) - return 0 - - # all hosts - if len(args) == 1 and args[0] == 'all': - opts.all = True - if opts.all: - hosts = [] - for hostclass in hostclasses: - hosts.extend(configtools.get_list(conf.get("hosts", hostclass))) - configtools.print_list(hosts, sep) - 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) diff --git a/bin/gethosts.2.py b/bin/gethosts.py similarity index 97% rename from bin/gethosts.2.py rename to bin/gethosts.py index 9ed46ff..5c2003d 100755 --- a/bin/gethosts.2.py +++ b/bin/gethosts.py @@ -3,13 +3,10 @@ import sys import os -import configtools +import configtools from optparse import make_option def main(conf, args, opts): - if not conf: - return 1 - sep = ',' if opts.list: sep = ' ' @@ -55,5 +52,7 @@ def main(conf, args, opts): 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) diff --git a/intro.org b/intro.org index 5bc47c5..44ba2de 100644 --- a/intro.org +++ b/intro.org @@ -210,4 +210,3 @@ servers = gprfs00[3-8] [fn:1] if necessary, that limitation gives an ugly way to get a literal 'foo[1-3]' by specifying 'foo[][1-3]'. - diff --git a/profile b/profile deleted file mode 100644 index 130dcc0..0000000 --- a/profile +++ /dev/null @@ -1,41 +0,0 @@ -# -*- mode: shell-script -*- -if [[ -z "$TOP" ]]; then - # keep going up until we get to the rpm directory - export TOP=$PWD - while [[ ! -f $TOP/setup.py && ! -d $TOP/configtools ]]; do - TOP=$(dirname $TOP) - if [[ "$TOP" = "/home/$USER" || "$TOP" = "/home" || "$TOP" = "/" ]]; then - break - fi - done -fi -prefix=$TOP - -pathins() { - if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then - PATH="$1:$PATH" - fi -} -ppathins() { - if [ -d "$1" ] && [[ ":$PYTHONPATH:" != *":$1:"* ]]; then - PYTHONPATH="$1:$PYTHONPATH" - fi -} - -# this file is *only* used by unit tests and for in-tree -# development: it is *not* part of the RPM. - -# So *always* use the in-tree version of configtools here. -# prefix better be right at this point -if [[ ! -f $prefix/build/bin/getconf.py ]] -then - echo "Cannot find getconf.py: $prefix/build/bin/getconf.py" -else - (cd $prefix; make > /dev/null 2>&1) - if [[ $? -eq 0 ]]; then - pathins $prefix/build/bin - export PYTHONPATH - ppathins $prefix/build/lib - fi -fi -unset prefix diff --git a/setup.py b/setup.py index fa0c5d4..c9cfd10 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,11 @@ from distutils.core import setup -setup(name='configtools', - version='0.2', - description='Simple tools for using config files', - author='Nick Dokos', - author_email='ndokos@redhat.com', - url='http://foo', +setup(name = 'configtools', + version = '0.3', + description = 'Simple tools for using config files', + author = 'Nick Dokos', + author_email = 'ndokos@redhat.com', + url = 'http://foo', packages = ['configtools'], + scripts = ['bin/getconf.py', 'bin/gethosts.py',], ) diff --git a/unittests b/unittests index c1a2a72..feefd9d 100755 --- a/unittests +++ b/unittests @@ -7,12 +7,34 @@ mkdir -p $tmp # trap "rm -rf $tmp" EXIT INT QUIT +python setup.py build + +# So *always* use the in-tree version of configtools here. +# prefix better be right at this point +if [[ ! -f build/scripts-2.7/getconf.py ]] +then + echo "Cannot find getconf.py: build/scripts-2.7/getconf.py" 1>&2 + exit 1 +fi + +ppathins() { + if [ -d "$1" ] && [[ ":$PYTHONPATH:" != *":$1:"* ]]; then + PYTHONPATH="$1:$PYTHONPATH" + fi +} + +export PYTHONPATH +ppathins $PWD/build/lib + +bin=$PWD/build/scripts-2.7 + function run_test { testnum=$1 shift dir=$1 + shift - eval "$*" > $tmp/test.out 2>&1 + eval "$bin/$dir $*" > $tmp/test.out 2>&1 echo Test $testnum if diff $tmp/test.out gold/$dir/$testnum.out ; then @@ -22,9 +44,6 @@ function run_test { fi } -make -. ./profile - run_test 1 getconf.py --config samples/foo.conf bar foo run_test 2 getconf.py --config samples/foo.conf baz foo run_test 3 getconf.py --config samples/foo.conf -a foo