Revision 943
Added by Aaron Marcuse-Kubitza almost 13 years ago
lib/opts.py | ||
---|---|---|
4 | 4 |
|
5 | 5 |
import util |
6 | 6 |
|
7 |
def env_flag(name): return name in os.environ and os.environ[name] != '' |
|
7 |
def env_flag(name, env_names_ref=None): |
|
8 |
if env_names_ref != None: env_names_ref.append(name+'=1') |
|
9 |
return name in os.environ and os.environ[name] != '' |
|
8 | 10 |
|
9 | 11 |
def get_env_var(name, default, env_names_ref=None): |
10 |
if env_names_ref != None: env_names_ref.append(name) |
|
12 |
if env_names_ref != None: env_names_ref.append(name+'=...')
|
|
11 | 13 |
return os.getenv(name, default) |
12 | 14 |
|
13 | 15 |
def get_env_vars(names, prefix=None, env_names_ref=None, on_unset=util.noop): |
... | ... | |
15 | 17 |
for name in names: |
16 | 18 |
env_name = name |
17 | 19 |
if prefix != None: env_name = prefix+'_'+env_name |
18 |
if env_names_ref != None: env_names_ref.append(env_name) |
|
20 |
if env_names_ref != None: env_names_ref.append(env_name+'=...')
|
|
19 | 21 |
try: vars_[name] = os.environ[env_name] |
20 | 22 |
except KeyError, e: on_unset(e) |
21 | 23 |
return vars_ |
... | ... | |
25 | 27 |
for name in env_names: |
26 | 28 |
str_ += ' ' |
27 | 29 |
if optional: str_ += '[' |
28 |
str_ += name+'=...'
|
|
30 |
str_ += name |
|
29 | 31 |
if optional: str_ += ']' |
30 | 32 |
return str_ |
Also available in: Unified diff
opts.py: Added env_names usage support to env_flag()