import io
import os

from ConfigParser import RawConfigParser


def apply_env():
    """
    Read the `.env` file and apply it to os.environ just like using `foreman
    run` would.
    """
    env = '[root]\n' + io.open('.env', 'r').read()

    config = RawConfigParser(allow_no_value=True)

    # Use `str` instead of the regular option transform to preserve option case
    config.optionxform = str
    config.readfp(io.StringIO(env), '.env')

    os.environ.update(config.items('root'))

import io
import os

from ConfigParser import RawConfigParser


def apply_env():
    """
    Read the `.env` file and apply it to os.environ just like using `foreman
    run` would.
    """
    try:
        env = '[root]\n' + io.open('.env', 'r').read()
    except IOError:
        return

    config = RawConfigParser(allow_no_value=True)

    # Use `str` instead of the regular option transform to preserve option case
    config.optionxform = str
    config.readfp(io.StringIO(env), '.env')

    os.environ.update(config.items('root'))

Fix crash if .env does not exist
Fix crash if .env does not exist
