added config evironment check

This commit is contained in:
Michael Herman 2014-06-12 07:14:45 -05:00
parent 8138de63fe
commit 0fb024c199
3 changed files with 48 additions and 48 deletions

View File

@ -0,0 +1,45 @@
"""
Pass in a config file based on your environment.
Example:
import check_my_environment
class Main:
def __init__(self, configFile):
pass
def process(self):
print "ok"
if __name__ == "__main__":
m = Main(some_script.CONFIGFILE)
m.process()
"""
import os
import sys
ENVIRONMENT = "development"
CONFIGFILE = None
def get_config_file():
directory = os.path.dirname(__file__)
return {
"development": "{}/../config/development.cfg".format(directory),
"staging": "{}/../config/staging.cfg".format(directory),
"production": "{}/../config/production.cfg".format(directory)
}.get(ENVIRONMENT, None)
CONFIGFILE = get_config_file()
if CONFIGFILE is None:
sys.exit("Configuration error! Unknown environment set. \
Edit config.py and set appropriate environment")
print "Config file: {}".format(CONFIGFILE)
if not os.path.exists(CONFIGFILE):
sys.exit("Configuration error! Config file does not exist")
print "Congig ok ...."

View File

@ -1,46 +0,0 @@
"""
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 ......"

View File

@ -8,9 +8,10 @@
1. **06_execution_time.py**: class used for timing execution of code
1. **07_benchmark_permissions_loading_django.py**: benchmark loading of permissions in Django
1. **08_basic_email_web_crawler.py**: web crawler for grabbing emails from a website
1. **09_basic_link_web_crawler.py**: web crawler for grabbing links from a website
1. **09_basic_link_web_crawler.py**: web crawler for grabbing links from a website
1. **10_find_files_recursively.py**: recursively grab files from a directory
1. **11_optimize_images_with_wand.py**: recursively grab images from a directory, then optimize them for the web
1. **12_csv_split.py**: Splits a CSV file into multiple files based on command line arguments.
1. **13_random_name_generator.py**: random name generator
1. ***14_html_to_markdown.sh**: Convert all html files in a single directory to markdown
1. **14_html_to_markdown.sh**: Convert all html files in a single directory to markdown
1. **15_check_my_environment.py**: Pass in a config file based on your environment.