Skip to content

Commit c06e6de

Browse files
committed
added enviro check
1 parent ec099c8 commit c06e6de

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

not_finished.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""
2+
Have multiple environments and need to pass in a config file based on the environment?
3+
4+
Use this, so you don't pass the wrong config.
5+
6+
Use:
7+
8+
#!/usr/bin/python
9+
import enviro_check
10+
class Main:
11+
def __init__(self, configFile):
12+
pass
13+
14+
def process(self):
15+
print "ok"
16+
17+
if __name__ == "__main__":
18+
m = Main(entryscript.CONFIGFILE)
19+
m.process()
20+
21+
"""
22+
23+
24+
25+
#!/usr/bin/python
26+
import os
27+
import sys
28+
ENVIRONMENT = "development"
29+
CONFIGFILE = None
30+
31+
def getConfigFileForEnv():
32+
directory = os.path.dirname(__file__)
33+
return {
34+
"development" : "%s/../config/development.cfg" % directory,
35+
"staging" : "%s/../config/staging.cfg" % directory,
36+
"production" : "%s/../config/production.cfg" % directory
37+
}.get(ENVIRONMENT, None)
38+
39+
CONFIGFILE = getConfigFileForEnv()
40+
if CONFIGFILE is None:
41+
sys.exit("Configuration error! Unknown environment set. \
42+
Edit configurations.py and set appropriate environment")
43+
print "CONFIGFILE : %s" % CONFIGFILE
44+
if not os.path.exists(CONFIGFILE):
45+
sys.exit("Configuration error! Config file does not exist")
46+
print "configurations ok ......"

0 commit comments

Comments
 (0)