-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_config.py
43 lines (29 loc) · 870 Bytes
/
get_config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python
"""
Process config file
"""
import ConfigParser
import os
def get_config(config_file_name):
"""
Look in directory this script is running for
a config file and parse it
Args:
Name of config file
Returns:
Config object
"""
config = ConfigParser.ConfigParser()
# Check config file exists and can be accessed, then open
try:
this_dir = os.path.dirname(os.path.abspath(__file__))
filepath = this_dir + '/' + config_file_name
print filepath
if not os.path.isfile(filepath):
print "Error - Missing Config File: %s" % (config_file_name)
raise IOError('Config file does not exist')
config.read(filepath)
except IOError:
print "Error - Unable to access config file: %s" % (config_file_name)
exit()
return config