-
Notifications
You must be signed in to change notification settings - Fork 0
/
Configuration.py
executable file
·29 lines (27 loc) · 983 Bytes
/
Configuration.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
import sys
import re
import ConfigParser
class Configuration:
"""Provides access to configuration"""
def __init__(self):
self.config=ConfigParser.ConfigParser()
def configure(self,fn):
self.config.read([fn,])
def checkRequiredArguments(opts, parser):
"""Checks for missing command line options:
Args:
opts(Values) - optparse.Values
parser(OptionParser) - optparse.OptionParser
"""
missing_options = []
for option in parser.option_list:
if re.match(r'.*\(required\)$', option.help) and eval('opts.' + option.dest) == None:
missing_options.extend(option._long_opts)
if len(missing_options) > 0:
parser.error('Missing option: ' + str(missing_options))
if __name__=="__main__":
config=Configuration()
config.configure(sys.argv[1])
print config.config.sections()
print config.config.get("main_db", "hostname")
print config.config.get("query", "OSG_flocking_probe_list")