Project

General

Profile

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
    vars_ = {}
9
    for name in names:
10
        env_name = name
11
        if prefix != None: env_name = prefix+'_'+env_name
12
        if env_names_ref != None: env_names_ref.append(env_name)
13
        try: vars_[name] = os.environ[env_name]
14
        except KeyError: pass
15
    return vars_
16

    
17
def env_usage(env_names, optional=False):
18
    str_ = 'env'
19
    for name in env_names:
20
        str_ += ' '
21
        if optional: str_ += '['
22
        str_ += name+'=...'
23
        if optional: str_ += ']'
24
    return str_
(4-4/10)