[server] make internal_cnx get and keep a connection to the db
- internal_session worked that way
- it's less surprising for users if their internal connections "just
work", rather than having to deal with the cnxset when using low-level
APIs
Includes a backout of 3f62606c01a2 "[repo] Fix register_user" which is
no longer needed.
Depend on logilab-database 1.12.1 to avoid errors due to pointless check
in python's sqlite3 binding.
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr## This file is part of CubicWeb.## CubicWeb is free software: you can redistribute it and/or modify it under the# terms of the GNU Lesser General Public License as published by the Free# Software Foundation, either version 2.1 of the License, or (at your option)# any later version.## CubicWeb is distributed in the hope that it will be useful, but WITHOUT# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more# details.## You should have received a copy of the GNU Lesser General Public License along# with CubicWeb. If not, see <http://www.gnu.org/licenses/>.importosimportsystry:importwin32serviceutilimportwin32serviceexceptImportError:print'Win32 extensions for Python are likely not installed.'sys.exit(3)fromos.pathimportjoinfromcubicweb.etwist.serverimport(CubicWebRootResource,reactor,server)fromlogilab.common.shellutilsimportrmimportloggingfromloggingimportgetLogger,handlersfromcubicwebimportset_log_methodsfromcubicweb.cwconfigimportCubicWebConfigurationascwcfgdef_check_env(env):env_vars=('CW_INSTANCES_DIR','CW_INSTANCES_DATA_DIR','CW_RUNTIME_DIR')forvarinenv_vars:ifvarnotinenv:raiseException('The environment variables %s must be set.'% \', '.join(env_vars))ifnotenv.get('USERNAME'):env['USERNAME']='cubicweb'classCWService(object,win32serviceutil.ServiceFramework):_svc_name_=None_svc_display_name_=Noneinstance=Nonedef__init__(self,*args,**kwargs):win32serviceutil.ServiceFramework.__init__(self,*args,**kwargs)cwcfg.load_cwctl_plugins()logger=getLogger('cubicweb')set_log_methods(CubicWebRootResource,logger)defSvcStop(self):self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)logger=getLogger('cubicweb.twisted')logger.info('stopping %s service'%self.instance)reactor.stop()self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)defSvcDoRun(self):self.ReportServiceStatus(win32service.SERVICE_START_PENDING)logger=getLogger('cubicweb.twisted')handler=handlers.NTEventLogHandler('cubicweb')handler.setLevel(logging.INFO)logger.addHandler(handler)logger.info('starting %s service'%self.instance)try:_check_env(os.environ)# create the siteconfig=cwcfg.config_for(self.instance)config.init_log(force=True)config.debugmode=Falselogger.info('starting cubicweb instance %s ',self.instance)config.info('clear ui caches')forcachedirin('uicache','uicachehttps'):rm(join(config.appdatahome,cachedir,'*'))root_resource=CubicWebRootResource(config)website=server.Site(root_resource)# serve it via standard HTTP on port set in the configurationport=config['port']or8080logger.info('listening on port %s'%port)reactor.listenTCP(port,website)root_resource.init_publisher()root_resource.start_service()logger.info('instance started on %s',root_resource.base_url)self.ReportServiceStatus(win32service.SERVICE_RUNNING)reactor.run()exceptExceptionase:logger.error('service %s stopped (cause: %s)'%(self.instance,e))logger.exception('what happened ...')self.ReportServiceStatus(win32service.SERVICE_STOPPED)