2013-08-23 16:39:02 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
import os
|
|
|
|
import yaml
|
|
|
|
import logging
|
|
|
|
|
|
|
|
CONF_FILE = os.path.join(os.environ['HOME'], '.teuthology.yaml')
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class _Config(object):
|
2013-08-26 17:36:01 +00:00
|
|
|
"""
|
|
|
|
This class is intended to unify teuthology's many configuration files and
|
|
|
|
objects. Currently it serves as a convenient interface to
|
|
|
|
~/.teuthology.yaml and nothing else.
|
|
|
|
"""
|
2013-08-23 16:39:02 +00:00
|
|
|
def __init__(self):
|
|
|
|
if not os.path.exists(CONF_FILE):
|
|
|
|
log.debug("%s not found", CONF_FILE)
|
2013-08-26 17:36:01 +00:00
|
|
|
self.__conf = {}
|
2013-08-23 16:39:02 +00:00
|
|
|
return
|
|
|
|
|
2013-08-26 17:36:01 +00:00
|
|
|
self.__conf = yaml.safe_load(file(CONF_FILE))
|
2013-08-23 16:39:02 +00:00
|
|
|
|
2013-08-26 17:36:01 +00:00
|
|
|
# This property declaration exists mainly as an example; it is not
|
|
|
|
# necessary unless you want to, say, define a set method and/or a
|
|
|
|
# docstring.
|
2013-08-23 16:39:02 +00:00
|
|
|
@property
|
|
|
|
def lock_server(self):
|
|
|
|
return self.__conf.get('lock_server')
|
|
|
|
|
2013-08-26 17:36:01 +00:00
|
|
|
# This takes care of any and all of the rest.
|
|
|
|
# If the parameter is defined, return it. Otherwise return None.
|
|
|
|
def __getattr__(self, name):
|
|
|
|
return self.__conf.get(name)
|
2013-08-23 16:39:02 +00:00
|
|
|
|
|
|
|
config = _Config()
|