File tree 3 files changed +48
-48
lines changed
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 8
8
1 . ** 06_execution_time.py** : class used for timing execution of code
9
9
1 . ** 07_benchmark_permissions_loading_django.py** : benchmark loading of permissions in Django
10
10
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
12
12
1 . ** 10_find_files_recursively.py** : recursively grab files from a directory
13
13
1 . ** 11_optimize_images_with_wand.py** : recursively grab images from a directory, then optimize them for the web
14
14
1 . ** 12_csv_split.py** : Splits a CSV file into multiple files based on command line arguments.
15
15
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.
You can’t perform that action at this time.
0 commit comments