1 |
65
|
aaronmk
|
# Program options processing
|
2 |
|
|
|
3 |
|
|
import os
|
4 |
|
|
|
5 |
|
|
def env_flag(name): return name in os.environ and os.environ[name] != ''
|
6 |
|
|
|
7 |
135
|
aaronmk
|
def get_env_var(name, default, env_names_ref=None):
|
8 |
|
|
if env_names_ref != None: env_names_ref.append(name)
|
9 |
|
|
return os.getenv(name, default)
|
10 |
|
|
|
11 |
65
|
aaronmk
|
def get_env_vars(names, prefix=None, env_names_ref=None):
|
12 |
|
|
vars_ = {}
|
13 |
|
|
for name in names:
|
14 |
|
|
env_name = name
|
15 |
|
|
if prefix != None: env_name = prefix+'_'+env_name
|
16 |
|
|
if env_names_ref != None: env_names_ref.append(env_name)
|
17 |
130
|
aaronmk
|
try: vars_[name] = os.environ[env_name]
|
18 |
|
|
except KeyError: pass
|
19 |
|
|
return vars_
|
20 |
67
|
aaronmk
|
|
21 |
|
|
def env_usage(env_names, optional=False):
|
22 |
|
|
str_ = 'env'
|
23 |
|
|
for name in env_names:
|
24 |
|
|
str_ += ' '
|
25 |
|
|
if optional: str_ += '['
|
26 |
|
|
str_ += name+'=...'
|
27 |
|
|
if optional: str_ += ']'
|
28 |
|
|
return str_
|