0
## The purpose of this module is to create functions that allows for better syntax
0
## when performing some common and repetitive tasks. For example adding options
0
-def make_option_maker(parser, cmdline_prefix="", env_prefix="", dest_prefix=""):
0
- """Return a function that can be used to add_option with saner syntax.
0
- parser: the parser object that will be used by the returned function
0
- cmdline_prefix: will be used together with the name to build the command
0
- line option. a suffix of -- and a prefix of - will be added so you
0
- do not need to include those (--cmdline_prefix-<name>)
0
- env_prefix: will be used together with the name to specify the environment
0
- variable from which the option will default (ENV_PREFIX_<NAME>)
0
- dest_prefix: will be used together with name to specify the variable name
0
- in which the value of the option will be stored
0
- parser = OptionParser()
0
- omaker = make_option_maker(parser, dest_prefix = "someprefix",
0
- env_prefix = "SOMEPREFIX",
0
- cmdline_prefix = "someprefix")
0
- omaker('foo', action="append", help="collect a list of foo")
0
- omaker('bar', help="store bar", default="Blah")
0
- env_prefix = env_prefix.upper()
0
- if cmdline_prefix and not cmdline_prefix.endswith("-"):
0
- if env_prefix and not env_prefix.endswith("_"):
0
- if dest_prefix and not dest_prefix.endswith("_"):
0
- def option_maker(name, action = "store", help = "", default = None):
0
- """Use the given name, action and help string to add an option"""
0
- _default = os.environ.get(env_prefix + name.upper())
0
- parser.add_option("--" + cmdline_prefix + name.lower(),
0
- action = action, dest = dest_prefix + name.lower(),
0
- help = help + " [" + env_prefix + name.upper() + "]")
0
+modules = ['optparse', 'sqlalchemy']
Comments
No one has commented yet.