Start of some game board stuff.
[naja.git] / naja / options.py
1 import optparse
2 import os
3
4 from naja.attrdict import AttrDict
5 from naja.constants import DEFAULTS
6
7
8 options = AttrDict()
9
10
11 def parse_args(args):
12     '''
13     Parse arguments and store them in the options dictionary.
14
15     Note: If you add arguments, you need to add an appropriate default to the
16     DEFAULTS dict.
17     '''
18     options.update(DEFAULTS)
19
20     options.debug = 'DEBUG' in os.environ
21
22     parser = optparse.OptionParser()
23     parser.add_option('--no-sound',
24                       dest='sound', action='store_false', default=True,
25                       help='Disable all sound, including music')
26
27     parser.add_option('--no-music',
28                       dest='music', action='store_false', default=True,
29                       help='Disable music (but not sound)')
30
31     opts, _ = parser.parse_args(args)
32
33     for k in DEFAULTS:
34         if getattr(opts, k, None) is not None:
35             options[k] = getattr(opts, k)