remove duplicate courses to scoreboard counts
[oweals/karmaworld.git] / export_env_to_heroku.py
1 # export a foreman env to heroku
2 import subprocess
3
4 def export_env(filename='.env'):
5     data=['heroku', 'config:set']
6     unset=['heroku', 'config:unset']
7     with open(filename, 'r') as config:
8         for line in config.readlines():
9             # ignore whitespace padding
10             line.strip()
11             tmp = line.split('=')
12             # further ignore whitespace padding that was around the =
13             tmp = map(str.strip, tmp)
14             # Strip any quotes that might show up around the string
15             def striphyphen(somestring):
16                 return somestring.strip("'").strip('"')
17             tmp = map(striphyphen, tmp)
18             if len(tmp[0]) and tmp[0][0] == '#':
19                 # the heroku CLI cannot return if a variable is not yet set
20                 # or if it has been set to the empty string.
21                 # delete commented-out variables to be safe.
22                 unset.append(tmp[0][1:])
23             # check for nonempty variable and content
24             elif len(tmp) == 2 and len(tmp[0]) and len(tmp[1]):
25                     
26                 data.append('{0}={1}'.format(*tmp))
27     # run heroku configuration
28     subprocess.check_call(data)
29     subprocess.check_call(unset)
30     # check_call fires an exception on failure.
31     # if we're here, both calls succeeded.
32     return 0
33
34 if __name__ == '__main__':
35     import sys
36     sys.exit(export_env('.env'))