def init_config_parser(self, **kwargs): conf_data = getattr(self, 'confparser_data', {}) conf_data.update(kwargs.get('confparser_data', {})) if len(conf_data): self.__config_object_legacy = False conf_type = conf_data.get('confparser_type', 'INI') cls = CONFPARSER_TYPES.get(conf_type) self._confparser = cls(conf_data=conf_data) else: self.__config_object_legacy = True conf_type = kwargs.get('confparser_type', getattr(self, 'confparser_type', 'INI')) cls = CONFPARSER_TYPES.get(conf_type) _conf_filename = kwargs.get('_conf_filename', build_conf_filename()) self._confsection = kwargs.get( 'confsection', getattr(self.__class__, '_confsection', None)) self._save_config_file = kwargs.get('_save_config_file', True) conf_data = { 'filename': _conf_filename, 'section': self._confsection, 'read_only': not self._save_config_file } self._confparser = cls(conf_data=conf_data) GLOBAL_CONFIG.bind(update=self._CONF_ON_GLOBAL_CONFIG_UPDATE)
def build_conf_filename(): cfilename = GLOBAL_CONFIG.get('conf_filename') if cfilename: return cfilename app = GLOBAL_CONFIG.get('app_name') if app is None: return False #app = sys.argv[0].split('.py')[0] return os.path.expanduser('~/.%s.conf' % (app))
def init_config_parser(self, **kwargs): conf_data = getattr(self, 'confparser_data', {}) conf_data.update(kwargs.get('confparser_data', {})) if len(conf_data): self.__config_object_legacy = False conf_type = conf_data.get('confparser_type', 'INI') cls = CONFPARSER_TYPES.get(conf_type) self._confparser = cls(conf_data=conf_data) else: self.__config_object_legacy = True conf_type = kwargs.get('confparser_type', getattr(self, 'confparser_type', 'INI')) cls = CONFPARSER_TYPES.get(conf_type) _conf_filename = kwargs.get('_conf_filename', build_conf_filename()) self._confsection = kwargs.get('confsection', getattr(self.__class__, '_confsection', None)) self._save_config_file = kwargs.get('_save_config_file', True) conf_data = {'filename':_conf_filename, 'section':self._confsection, 'read_only':not self._save_config_file} self._confparser = cls(conf_data=conf_data) GLOBAL_CONFIG.bind(update=self._CONF_ON_GLOBAL_CONFIG_UPDATE)