1#  Copyright (c) 2005-2010 Vladimir Prus.
2#
3#  Use, modification and distribution is subject to the Boost Software
4#  License Version 1.0. (See accompanying file LICENSE_1_0.txt or
5#  http://www.boost.org/LICENSE_1_0.txt)
6
7import sys
8import re
9import b2.util.regex
10
11options = {}
12
13# Set a value for a named option, to be used when not overridden on the command
14# line.
15def set(name, value=None):
16
17    global options
18
19    options[name] = value
20
21def get(name, default_value=None, implied_value=None):
22
23    global options
24
25    matches = b2.util.regex.transform(sys.argv, "--" + re.escape(name) + "=(.*)")
26    if matches:
27        return matches[-1]
28    else:
29        m = b2.util.regex.transform(sys.argv, "--(" + re.escape(name) + ")")
30        if m and implied_value:
31            return implied_value
32        elif options.has_key(name) and options[name] != None:
33            return options[name]
34        else:
35            return default_value
36