[spambayes-dev] proposal for more uniform option setting from the command line

Skip Montanaro skip at pobox.com
Wed Nov 12 13:05:21 EST 2003

Our command lines still seem to be a mish mash of little hacks.  Everything
of interest can be set via the INI file, but there are only a few options
which can be set via the command line, and not (I don't believe) in a
consistent way across SB apps.

How about instead of only allowing specific options to be overridden on the
command line we use a consistent syntax for overriding *any* option from the
command line?  For example, to set the ["Storage",
"persistent_storage_file"] we could use something like

    -o Storage:persistent_storage_file:~/.hammiedb



The general syntax of an option setting command line arg would then be
section:field:value.  The post-getopt.getopt() code might look something

    from spambayes.Options import options

    for opt, arg in opts:
        elif opt in ('-o', '--option'):

We would then deprecate any command line args used to twiddle options using
any other syntax.  Use of those args would trigger a message to stderr like:

    Deprecated form: "-d ~/hammie.db" found.
    Use "-o Storage:persistent_storage_file:~/hammie.db" instead.

This could be extended further.  Should the user give an incomplete -o flag
such as "-o Storage" or "-o Storage:spam_cache", help about that section or
variable could be emitted:

    saw_help = False
    for opt, arg in opts:
        elif opt in ('-o', '--option'):
            # this would probably be folded into an OptionsClass method
            val = arg.split(':')
            if len(val) < 3:
                options.help(sys.stderr, *val)
                saw_help = True
    if saw_help:
        raise SystemExit

where OptionsClass.OptionsClass.help() would look something like:

    def help(self, stream, sect=None, opt=None):
        if sect is None:
            # dump help about all options
        elif opt is None:
            # dump help about sect
            # dump help about options[sect, opt]


More information about the spambayes-dev mailing list