-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
42 lines (35 loc) · 1.42 KB
/
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
import traceback
#!/usr/bin/python
#################################################################
# Configuration parser
#################################################################
class Config():
__configParser = None
def __init__(self, file_path="config"):
try:
import sys
import os
if not os.path.exists(file_path) or not os.path.isfile(file_path):
raise Exception("Invalid config file %s" % (file_path))
if sys.version_info[0] < 3:
import ConfigParser
self.__configParser = ConfigParser.RawConfigParser()
else:
import configparser
self.__configParser = configparser.RawConfigParser()
self.__configParser.read(file_path)
except ImportError as ie:
raise Exception("configparser module not available. Please install")
except Exception as e:
traceback.print_exc()
raise Exception("Error parsing " + file_path + ": " + str(e))
def get(self, opt, sec="Main", default=None):
if not self.__configParser:
return None
try:
return self.__configParser.get(sec, opt)
except Exception as e:
traceback.print_exc()
#raise Exception("Error getting config for " + \
# sec + " :" + cfg + ": " + str(e))
return None