Mercurial > nagslang
view nagslang/options.py @ 106:bce9cd8a4a8c
FloorLight, linked to a FloorSwitch.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Mon, 02 Sep 2013 13:48:24 +0200 |
parents | 17b233a54651 |
children | 7b121ed73b95 |
line wrap: on
line source
import optparse import os from nagslang.constants import DEFAULTS class AttrDict(dict): '''A dict with attribute access''' def __getattr__(self, attr): return self[attr] options = AttrDict() def parse_args(args): ''' Parse arguments and store them in the options dictionary. Note: If you add arguments, you need to add an appropriate default to the DEFAULTS dict. ''' options.update(DEFAULTS) options.debug = 'DEBUG' in os.environ parser = optparse.OptionParser() parser.add_option('--no-sound', dest='sound', action='store_false', default=True, help='Disable sound') if options.debug: parser.add_option('--area', help='Initial area') opts, _ = parser.parse_args(args) for k in DEFAULTS: if getattr(opts, k, None) is not None: options[k] = getattr(opts, k)