Revision 932
Added by Aaron Marcuse-Kubitza almost 13 years ago
lib/opts.py | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import os |
4 | 4 |
|
5 |
import util |
|
6 |
|
|
5 | 7 |
def env_flag(name): return name in os.environ and os.environ[name] != '' |
6 | 8 |
|
7 | 9 |
def get_env_var(name, default, env_names_ref=None): |
8 | 10 |
if env_names_ref != None: env_names_ref.append(name) |
9 | 11 |
return os.getenv(name, default) |
10 | 12 |
|
11 |
def get_env_vars(names, prefix=None, env_names_ref=None): |
|
13 |
def get_env_vars(names, prefix=None, env_names_ref=None, on_unset=util.noop):
|
|
12 | 14 |
vars_ = {} |
13 | 15 |
for name in names: |
14 | 16 |
env_name = name |
15 | 17 |
if prefix != None: env_name = prefix+'_'+env_name |
16 | 18 |
if env_names_ref != None: env_names_ref.append(env_name) |
17 | 19 |
try: vars_[name] = os.environ[env_name] |
18 |
except KeyError: pass
|
|
20 |
except KeyError, e: on_unset(e)
|
|
19 | 21 |
return vars_ |
20 | 22 |
|
21 | 23 |
def env_usage(env_names, optional=False): |
Also available in: Unified diff
opts.py: Call an error handler if an env var isn't set