#!/usr/bin/env python __revision__ = "$Id$" import sys, getopt, string # bit of goofing around with the getopt module to learn how it works # (or doesn't work) # conclusion: distutils needs to parse fairly complicated command lines, eg. # ./setup.py --prefix=/home/me --python=/home/me/bin/python # build --blib=/tmp/pyblib # test --verbose # install # where some options (--prefix, --python) are "global", and others # are apportioned to individual commands. A further possibility is # "global" options that are specified by setup.py. I don't think # the standard 'getopt' module can handle this, although we can # probably rip-off a lot of its code. def try_it (args, opts, long_opts=[]): print "** parsing:", string.join (args, ' ') try: (values, leftovers) = getopt.getopt (args, opts, long_opts) except getopt.error: print "getopt error: %s" % sys.exc_value else: print "values:", string.join (map (repr, values), ' ') print "leftovers:", string.join (leftovers, ' ') try_it (['-a', 'foo', '-x', '-y', 'bar'], 'a:xy') try_it (['-a', 'foo', '-xy', 'bar'], 'a:xy') try_it (['-a', 'foo', '-x', '-y', 'bar'], 'a:xy:') try_it (['-afoo', '-x', '-y', 'bar'], 'a:xy:') try_it (['-a', 'foo', '--extreme', '-y', 'bar'], 'a:xy:') try_it (['-a', 'foo', '--extreme', '-y', 'bar'], 'a:xy:', ['extreme']) try_it (['-a', 'foo', '--extr', '-y', 'bar'], 'a:xy:', ['extreme=', 'extra']) try_it (['-a', 'foo', '-', '-y', '--', 'bar'], 'a:xy:', ['extreme']) try_it (['-a', 'foo', '-y', '--', 'bar'], 'a:xy:', ['extreme']) try_it (['-a', 'foo', '-y', 'baz', '--', 'bar'], 'a:xy:', ['extreme'])