Mercurial > nagslang
changeset 16:fe1426d09074
Merge.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Sun, 01 Sep 2013 14:21:13 +0200 |
parents | 17b233a54651 (diff) 980339c28b42 (current diff) |
children | b0644173d0aa |
files | nagslang/constants.py |
diffstat | 2 files changed, 41 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/nagslang/constants.py Sun Sep 01 14:19:55 2013 +0200 +++ b/nagslang/constants.py Sun Sep 01 14:21:13 2013 +0200 @@ -1,2 +1,6 @@ SCREEN = (800, 600) FPS = 40 +DEFAULTS = dict( + debug=False, + sound=True, +)
--- a/nagslang/options.py Sun Sep 01 14:19:55 2013 +0200 +++ b/nagslang/options.py Sun Sep 01 14:21:13 2013 +0200 @@ -1,3 +1,38 @@ +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): - #TODO - return + ''' + 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)