class _SMSBase(object): def __init__(self): self._loadConfiguration() self.sender_plugin_name = config.get('sms.sender.plugin', None) self.receiver_plugin_name = config.get('sms.receiver.plugin', None) self._plugin = None self._preparePlugin() def _preparePlugin(self): pass def _loadConfiguration(self): self._config_loader = Configuration(implementation="yml") self._config_loader.loadExtension("sms", getDefaultConfigPath()) try: self._config_loader.load("sms", config.get('project.paths.config')) except ConfigurationNotFound, e: log.error(e)
class CherryPyWebExt(object): """docstring for CherryPyWebExt""" def __init__(self, parent, override_config=None): super(CherryPyWebExt, self).__init__() log.debug("CherryPyWebExt::__init__") self.parent = parent self.dispatcher = None self._loadConfiguration() if override_config: config['cherrypy'].update(override_config.copy()) cherrypy.config.update(config.get('cherrypy.global', {})) if not cherrypy.tools.staticdir.root: cherrypy.config.update({ 'tools.staticdir.root': self.parent.base_path }) route_mounts = config.get('cherrypy.mounts') self._route_config = {} for base_path, routes in self.parent.routes.iteritems(): if not self._route_config.has_key(base_path): self._route_config[base_path] = {} self._route_config[base_path].update({ 'request.dispatch': self._setup_routes(routes) }) for point, conf in route_mounts.iteritems(): if not self._route_config.has_key(point): self._route_config[point] = {} self._route_config[point].update(conf) multilang_config = config.get('cherrypy.multilang') localedir = os.path.join(self.parent.base_path, 'i18n') if multilang_config.get('enabled'): for key, conf in multilang_config.get('map').iteritems(): cherrypy.tree.apps['/'+key] = InGoMultilangApp(conf.get('lang'), localedir, conf.get('path'), self._route_config) if multilang_config.get('default') == key: cherrypy.tree.apps[''] = InGoMultilangApp(conf.get('lang'), localedir, config.get('cherrypy.root_path'), self._route_config) else: cherrypy.tree.apps[''] = InGoMultilangApp(multilang_config.get('default'), localedir, config.get('cherrypy.root_path'), self._route_config) #cherrypy.tree.mount(None, script_name=self.config.get('root_path'), config=self._route_config) self._env = { 'app': cherrypy.request.app, 'ingo_app': self.parent, 'basedir': self.parent.base_path } @property def env(self): return self._env @property def request(self): return cherrypy.request @property def map(self): return self.dispatcher.mapper def run(self): cherrypy.quickstart() def _loadConfiguration(self): self._config_loader = Configuration(implementation="yml") self._config_loader.loadExtension("cherrypy", getDefaultConfigPath()) try: self._config_loader.load("cherrypy", config.get('project.paths.config')) except ConfigurationNotFound, e: log.error(e)
class Project(object): """docstring for Project""" _configurations = [] def __init__(self): super(Project, self).__init__() ingo.register_project(self) self._ingo_root = self.resolvePathForName(__name__) self._ingo_config_path = Path(self._ingo_root) self.base_path = Path(sys.path[0]) self._config_path = self.base_path.child('config') self._config_loader = Configuration(implementation="yml") self._loadInitialConfiguration() self._loadInitialUserConfiguration() config['project']['paths']['config'] = self._config_path config['project']['paths']['root'] = self.base_path self._prepareLoggers() ingo.features.load() # print ingo.features # print "has web app feature", ingo.features.has('web', 'application') # print "has web error controller", ingo.features.has('web', 'controller.error') self._preparePlugins() def initialize(self): pass @classmethod def resolvePathForName(cls, name, path='/'): return resource_filename(name, path) def _loadInitialConfiguration(self): self._config_loader.load("default", self._ingo_config_path, local=False) for name in self._configurations: conf_name = name conf_path = self._ingo_config_path if type(name) is list: conf_name = name[0] conf_path = name[1] self._config_loader.load(conf_name, conf_path, local=False) def _loadInitialUserConfiguration(self): if not self._config_path: return try: self._config_loader.load("default", self._config_path) except ConfigurationNotFound, e: pass for name in self._configurations: conf_name = name if type(name) is list: conf_name = name[0] try: self._config_loader.load(conf_name, self._config_path) except ConfigurationNotFound, e: pass