Skip to content

Commit 0fb024c

Browse files
committed
added config evironment check
1 parent 8138de6 commit 0fb024c

File tree

3 files changed

+48
-48
lines changed

3 files changed

+48
-48
lines changed

15_check_my_environment.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""
2+
Pass in a config file based on your environment.
3+
4+
Example:
5+
6+
import check_my_environment
7+
8+
9+
class Main:
10+
def __init__(self, configFile):
11+
pass
12+
13+
def process(self):
14+
print "ok"
15+
16+
if __name__ == "__main__":
17+
m = Main(some_script.CONFIGFILE)
18+
m.process()
19+
20+
"""
21+
22+
23+
import os
24+
import sys
25+
ENVIRONMENT = "development"
26+
CONFIGFILE = None
27+
28+
29+
def get_config_file():
30+
directory = os.path.dirname(__file__)
31+
return {
32+
"development": "{}/../config/development.cfg".format(directory),
33+
"staging": "{}/../config/staging.cfg".format(directory),
34+
"production": "{}/../config/production.cfg".format(directory)
35+
}.get(ENVIRONMENT, None)
36+
37+
CONFIGFILE = get_config_file()
38+
39+
if CONFIGFILE is None:
40+
sys.exit("Configuration error! Unknown environment set. \
41+
Edit config.py and set appropriate environment")
42+
print "Config file: {}".format(CONFIGFILE)
43+
if not os.path.exists(CONFIGFILE):
44+
sys.exit("Configuration error! Config file does not exist")
45+
print "Congig ok ...."

not_finished.py

-46
This file was deleted.

readme.md

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

0 commit comments

Comments
 (0)