Changeset 13:b410c7153d52


Ignore:
Timestamp:
Sep 1, 2013, 12:17:42 PM (7 years ago)
Author:
Stefano Rivera <stefano@…>
Branch:
default
Message:

Option parsing

Location:
nagslang
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • nagslang/constants.py

    r10 r13  
    11SCREEN = (800, 600)
     2
     3DEFAULTS = dict(
     4    debug=False,
     5    sound=True,
     6)
  • nagslang/options.py

    r10 r13  
     1import optparse
     2import os
     3
     4from nagslang.constants import DEFAULTS
     5
     6
     7class AttrDict(dict):
     8    '''A dict with attribute access'''
     9    def __getattr__(self, attr):
     10        return self[attr]
     11
     12
     13options = AttrDict()
     14
     15
    116def parse_args(args):
    2     #TODO
    3     return
     17    options.update(DEFAULTS)
     18
     19    options.debug = 'DEBUG' in os.environ
     20
     21    parser = optparse.OptionParser()
     22    parser.add_option('--no-sound',
     23                      dest='sound', action='store_false', default=True,
     24                      help='Disable sound')
     25    if options.debug:
     26        parser.add_option('--area', help='Initial area')
     27
     28    opts, _ = parser.parse_args(args)
     29
     30    for k in DEFAULTS:
     31        if getattr(opts, k, None) is not None:
     32            options[k] = getattr(opts, k)
Note: See TracChangeset for help on using the changeset viewer.