From c06e6de4f3679410e71b57f47fa36f5fff30f3d0 Mon Sep 17 00:00:00 2001 From: Michael Herman Date: Tue, 10 Jun 2014 08:22:34 -0500 Subject: [PATCH] added enviro check --- not_finished.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 not_finished.py diff --git a/not_finished.py b/not_finished.py new file mode 100644 index 0000000..cad918e --- /dev/null +++ b/not_finished.py @@ -0,0 +1,46 @@ +""" +Have multiple environments and need to pass in a config file based on the environment? + +Use this, so you don't pass the wrong config. + +Use: + +#!/usr/bin/python +import enviro_check +class Main: + def __init__(self, configFile): + pass + + def process(self): + print "ok" + +if __name__ == "__main__": + m = Main(entryscript.CONFIGFILE) + m.process() + +""" + + + +#!/usr/bin/python +import os +import sys +ENVIRONMENT = "development" +CONFIGFILE = None + +def getConfigFileForEnv(): + directory = os.path.dirname(__file__) + return { + "development" : "%s/../config/development.cfg" % directory, + "staging" : "%s/../config/staging.cfg" % directory, + "production" : "%s/../config/production.cfg" % directory + }.get(ENVIRONMENT, None) + +CONFIGFILE = getConfigFileForEnv() +if CONFIGFILE is None: + sys.exit("Configuration error! Unknown environment set. \ + Edit configurations.py and set appropriate environment") +print "CONFIGFILE : %s" % CONFIGFILE +if not os.path.exists(CONFIGFILE): + sys.exit("Configuration error! Config file does not exist") +print "configurations ok ......"