From fedc91c07f4e712f95903412ae7456f6b7a7e74f Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Mon, 26 Aug 2013 12:36:01 -0500 Subject: [PATCH] Add a catch-all __getattr__(); add comments --- teuthology/config.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/teuthology/config.py b/teuthology/config.py index 04e2aa299bd..45b0b92add8 100644 --- a/teuthology/config.py +++ b/teuthology/config.py @@ -9,31 +9,29 @@ log = logging.getLogger(__name__) class _Config(object): + """ + 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. + """ def __init__(self): - self.__conf = {} if not os.path.exists(CONF_FILE): log.debug("%s not found", CONF_FILE) + self.__conf = {} return - with file(CONF_FILE) as f: - conf_obj = yaml.safe_load_all(f) - for item in conf_obj: - self.__conf.update(item) + self.__conf = yaml.safe_load(file(CONF_FILE)) + # 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. @property def lock_server(self): return self.__conf.get('lock_server') - @property - def queue_host(self): - return self.__conf.get('queue_host') - - @property - def queue_port(self): - return self.__conf.get('queue_port') - - @property - def sentry_dsn(self): - return self.__conf.get('sentry_dsn') + # 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) config = _Config()