def get_logging_conf(conf, log_name='log'): """ Check for a log configuration ('log' attribute by default) in `conf`. Supply default values if necessary. Parameters ---------- conf : Struct The configuration object. log_name : str, optional The name of the log configuration attribute in `conf`. Returns ------- log : dict The dictionary {'plot' : <figure_file>, 'text' : <text_log_file>}. One or both values can be None. """ log = conf.get(log_name, None) default_log = {'text' : None, 'plot' : None} if log is None: log = default_log else: set_defaults(log, default_log) return log
def try_set_defaults( obj, attr, defaults ): try: values = getattr( obj, attr ) set_defaults( values, defaults ) except: values = defaults return values
def try_set_defaults(obj, attr, defaults, recur=False): try: values = getattr(obj, attr) except: values = defaults else: if recur and isinstance(values, dict): for key, val in values.iteritems(): set_defaults(val, defaults) else: set_defaults(values, defaults) return values
def get_logging_conf(conf): """ Check for a logging configuration ('log' attribute) in conf. Supply default values if necessary. Returns ------- log : dict The dictionary {'plot' : <figure_file>, 'text' : <text_log_file>}. One or both values can be None. """ get = conf.get_default_attr log = get('log', None) default_log = {'text' : None, 'plot' : None} if log is None: log = default_log else: set_defaults(log, default_log) return log
def get_logging_conf(conf): """ Check for a logging configuration ('log' attribute) in conf. Supply default values if necessary. Returns ------- log : dict The dictionary {'plot' : <figure_file>, 'text' : <text_log_file>}. One or both values can be None. """ get = conf.get_default_attr log = get('log', None) default_log = {'text': None, 'plot': None} if log is None: log = default_log else: set_defaults(log, default_log) return log