1 # a duct-tape-and-bubble-gum version of foreman's env support
5 def run_in_env(command, filename='.env'):
6 # configure environment as a copy of the current environment
9 # plus vars from the file
10 with open(filename, 'r') as config:
11 for line in config.readlines():
12 # ignore whitespace padding
15 # further ignore whitespace padding that was around the =
16 tmp = map(str.strip, tmp)
17 if len(tmp[0]) and tmp[0][0] == '#':
19 # check for nonempty variable and content
20 elif len(tmp) == 2 and len(tmp[0]) and len(tmp[1]):
21 env[tmp[0]] = tmp[1].strip("'") # drop quotes around values
23 subprocess.check_call(command, env=env)
24 # check_call fires an exception on failure.
25 # if we're here, both calls succeeded.
28 if __name__ == '__main__':
30 sys.exit(run_in_env(sys.argv[1:], '.env'))