Changeset 4376

Show
Ignore:
Timestamp:
03/15/09 17:06:31 (4 years ago)
Author:
gpolo
Message:

Added utility function to correctly get the desired value of UMIT_DEVELOPMENT env var.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/umit/core/Utils.py

    r4240 r4376  
    3333except ImportError: 
    3434    pass 
     35 
     36def development_mode(default=True): 
     37    """ 
     38    Returns True if the environment var UMIT_DEVELOPMENT is set to true, 
     39    'true' (case insensitive) or some number different than 0 are considered 
     40    as true, False otherwise. 
     41 
     42    If the env var is not set, then the default value governs the return 
     43    value. If you want UMIT_DEVELOPMENT to be True by default, call this 
     44    function with default=True (default). 
     45    """ 
     46    val = os.environ.get('UMIT_DEVELOPMENT', default) 
     47    try: 
     48        val = int(val) 
     49    except ValueError: 
     50        if val.lower() == 'true': 
     51            return True 
     52    else: 
     53        if val: 
     54            return True 
     55 
     56    return False 
    3557 
    3658