Esempio n. 1
0
    def get_config_spec(cls):
        '''Load the config specs as ConfigObj object

        It merges the specs of the current class and those of parents classes
        '''
        cfg = None
        spec = cls.get_config_spec_file()

        # If specification (and so defaults) file defined and exists
        if spec and os.path.isfile(spec):

            # Load (temporary) the file
            cfg = configobj.ConfigObj(spec, list_values=False, interpolation=False)

            # NOTE: list_values=False, interpolation=False are set because list values
            #       are handled by the manager (parse error otherwise)

            # If a config section lookup is defined and present, load the section
            sec = cls.get_config_section_name()
            if sec and sec in cfg:
                #cfg = configobj.ConfigObj(cfgspec[sec], list_values=False, interpolation=False)
                cfg = configobj.ConfigObj(cfg[sec])

        # Merge with parents
        pcfg = cls.get_parent_config_spec()
        if cfg is None:
            cfg = pcfg
        elif pcfg is not None:
            cfg = dict_merge(cfg, pcfg, mergesubdicts=False)
        return cfg
Esempio n. 2
0
    def get_config_spec(cls):
        '''Load the config specs as ConfigObj object

        It merges the specs of the current class and those of parents classes
        '''
        cfg = None
        spec = cls.get_config_spec_file()

        # If specification (and so defaults) file defined and exists
        if spec and os.path.isfile(spec):

            # Load (temporary) the file
            cfg = configobj.ConfigObj(spec, list_values=False, interpolation=False)

            # NOTE: list_values=False, interpolation=False are set because list values
            #       are handled by the manager (parse error otherwise)

            # If a config section lookup is defined and present, load the section
            sec = cls.get_config_section_name()
            if sec and sec in cfg:
                #cfg = configobj.ConfigObj(cfgspec[sec], list_values=False, interpolation=False)
                cfg = configobj.ConfigObj(cfg[sec])

        # Merge with parents
        pcfg = cls.get_parent_config_spec()
        if cfg is None:
            cfg = pcfg
        elif pcfg is not None:
            cfg = dict_merge(cfg, pcfg, mergesubdicts=False)
        return cfg
Esempio n. 3
0
 def get_parent_config_spec(cls):
     '''Get the merged config specifications of all parents'''
     cfg = None
     for c in cls.__bases__:
         if not hasattr(c, 'get_config_spec'): continue
         cs = c.get_config_spec()
         if cfg is None:
             cfg = cs
         else:
             cfg = dict_merge(cfg, cs)
     return cfg
Esempio n. 4
0
 def get_parent_config_spec(cls):
     '''Get the merged config specifications of all parents'''
     cfg = None
     for c in cls.__bases__:
         if not hasattr(c, 'get_config_spec'): continue
         cs = c.get_config_spec()
         if cfg is None:
             cfg = cs
         else:
             cfg = dict_merge(cfg, cs)
     return cfg