def export_env(filename='.env'):
data=['heroku', 'config:set']
+ unset=['heroku', 'config:unset']
with open(filename, 'r') as config:
for line in config.readlines():
# ignore whitespace padding
tmp = line.split('=')
# further ignore whitespace padding that was around the =
tmp = map(str.strip, tmp)
+ if len(tmp[0]) and tmp[0][0] == '#':
+ # the heroku CLI cannot return if a variable is not yet set
+ # or if it has been set to the empty string.
+ # delete commented-out variables to be safe.
+ unset.append(tmp[0][1:])
# check for nonempty variable and content
- if len(tmp) == 2 and len(tmp[0]) and len(tmp[1]):
+ elif len(tmp) == 2 and len(tmp[0]) and len(tmp[1]):
+
data.append('{0}={1}'.format(*tmp))
- return subprocess.check_call(data)
+ # run heroku configuration
+ subprocess.check_call(data)
+ subprocess.check_call(unset)
+ # check_call fires an exception on failure.
+ # if we're here, both calls succeeded.
+ return 0
if __name__ == '__main__':
import sys