Revision 65
Added by Aaron Marcuse-Kubitza about 13 years ago
scripts/lib/opts.py | ||
---|---|---|
1 |
# Program options processing |
|
2 |
|
|
3 |
import os |
|
4 |
|
|
5 |
def env_flag(name): return name in os.environ and os.environ[name] != '' |
|
6 |
|
|
7 |
def get_env_vars(names, prefix=None, env_names_ref=None): |
|
8 |
# Requires that all env vars are set; otherwise returns None |
|
9 |
has_all = True |
|
10 |
vars_ = {} |
|
11 |
for name in names: |
|
12 |
env_name = name |
|
13 |
if prefix != None: env_name = prefix+'_'+env_name |
|
14 |
if env_names_ref != None: env_names_ref.append(env_name) |
|
15 |
if env_name in os.environ: vars_[name] = os.environ[env_name] |
|
16 |
else: has_all = False |
|
17 |
if has_all: return vars_ |
|
18 |
else: return None |
Also available in: Unified diff
Moved options-processing code to opts.py: Added opts.py