File tree Expand file tree Collapse file tree 3 files changed +48
-48
lines changed
Expand file tree Collapse file tree 3 files changed +48
-48
lines changed Original file line number Diff line number Diff line change 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 ...."
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 881 . ** 06_execution_time.py** : class used for timing execution of code
991 . ** 07_benchmark_permissions_loading_django.py** : benchmark loading of permissions in Django
10101 . ** 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
12121 . ** 10_find_files_recursively.py** : recursively grab files from a directory
13131 . ** 11_optimize_images_with_wand.py** : recursively grab images from a directory, then optimize them for the web
14141 . ** 12_csv_split.py** : Splits a CSV file into multiple files based on command line arguments.
15151 . ** 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.
You can’t perform that action at this time.
0 commit comments