def load_module(self, p, module): m = __import__("%s" % module, globals=globals(), fromlist=[None]) # m = None # exec ("import %s as m" % module) in globals() if '_check_conf' not in m.__dict__: app.log_error('No config need for module %s...' % module, state.LOG_INFO) # check and set config values need for module else: for it in m._check_conf: sec, opt, cls, dfl, mod, doc = option(*it) var = "%s_%s" % (sec, opt) if var in self.__dict__ \ and not isinstance(self.__dict__[var], cls): raise TypeError("Option `%s` is not class instance `%s`", var, str(cls)) if var not in self.__dict__: self.__dict__[var] = p.get(sec, opt, dfl, cls) if not mod: # option could not be set via option module continue if sec not in self.options: self.options[sec] = {} if opt not in self.options[sec]: self.options[sec][opt] = {} self.options[sec][opt][module] = (dfl, cls, self.__dict__[var], doc) # endif if '_call_conf' in m.__dict__: app.log_error('Config fn for module %s exist ...' % module, state.LOG_INFO) m._call_conf(self, p)
def load(self, options): if 'morias_config' in options: inifile = options.get('morias_config') # TODO: check if file is readable app.log_error('Read config from file ...', state.LOG_INFO) p = Parser() p.read(inifile) else: app.log_error('Read config from options ...', state.LOG_INFO) p = Options(options) # endif self.debug = p.get('morias', 'debug', False, cls=bool) self.templates = p.get('morias', 'templates', cls=Paths) self.footers = [] # modules could append path for it's footer self.modules = p.get('morias', 'modules', cls=tuple) self.langs = p.get('morias', 'langs', 'en,cs', cls=tuple) self.locales = p.get('morias', 'locales', 'locales/') self.site_name = p.get('site', 'name', "Morias") self.site_description = p.get('site', 'description', "cms") self.site_keywords = p.get('site', 'keywords', '', cls=tuple) self.site_author = p.get('site', 'author', '') self.site_copyright = p.get('site', 'copyright', strftime("%%Y %s" % self.site_author.encode('utf-8'))) self.site_styles = p.get('site', 'styles', '', cls=tuple) self.options = { 'morias': { 'langs': {'morias.core': ('en,cs', list, self.langs, True, '')}, }, 'site': { 'name': {'morias.core': ('Morias', unicode, self.site_name, True, '')}, 'description': {'morias.core': ('cms', unicode, self.site_description, True, '')}, 'keywords': {'morias.core': ('', tuple, self.site_keywords, True, '')}, 'author': {'morias.core': ('', unicode, self.site_author, True, '')}, 'copyright': {'morias.core': ('', unicode, self.site_copyright, True, '')}, } } for module in self.modules: app.log_error('Loading module %s' % module, state.LOG_INFO) self.load_module(p, module) """
def log_info(self, message): """ baypass property for db operations at load modules """ return app.log_error(message, level=state.LOG_INFO)
def log_error(self, message, level=state.LOG_ERR): """ application logger with default state.LOG_ERR log level """ app.log_error(message, level)