merge stable
authorAlexandre Fayolle <alexandre.fayolle@logilab.fr>
Tue, 27 Apr 2010 11:25:40 +0200
branchstable
changeset 5416 cd95e4660864
parent 5415 6bb0c3a53589 (current diff)
parent 5414 6eeec78c65f9 (diff)
child 5417 55ff79dad1a6
merge
--- a/etwist/service.py	Tue Apr 27 11:23:20 2010 +0200
+++ b/etwist/service.py	Tue Apr 27 11:25:40 2010 +0200
@@ -1,23 +1,30 @@
 import os
+import sys
 
-import win32serviceutil
-import win32service
-import win32event
+try:
+    import win32serviceutil
+    import win32service
+except ImportError:
+    print 'Win32 extensions for Python are likely not installed.'
+    sys.exit(3)
+
 
 from cubicweb.etwist.server import (CubicWebRootResource, reactor, server,
                                     parsePOSTData, channel)
 
+import logging
 from logging import getLogger, handlers
 from cubicweb import set_log_methods
 from cubicweb.cwconfig import CubicWebConfiguration as cwcfg
 
-logger = getLogger('cubicweb.twisted')
-logger.handlers = [handlers.NTEventLogHandler('cubicweb')]
-
-if not os.environ.get('CW_INSTANCES_DIR'):
-    os.environ['CW_INSTANCES_DIR'] = r'C:\etc\cubicweb.d'
-if not os.environ.get('USERNAME'):
-    os.environ['USERNAME'] = 'cubicweb'
+def _check_env(env):
+    env_vars = ('CW_INSTANCES_DIR', 'CW_INSTANCES_DATA_DIR', 'CW_RUNTIME_DIR')
+    for var in env_vars:
+        if var not in env:
+            raise Exception('The environment variables %s must be set.' % \
+                            ', '.join(env_vars))            
+    if not env.get('USERNAME'):
+        env['USERNAME'] = 'cubicweb'
 
 class CWService(object, win32serviceutil.ServiceFramework):
     _svc_name_ = None
@@ -27,11 +34,13 @@
     def __init__(self, *args, **kwargs):
         win32serviceutil.ServiceFramework.__init__(self, *args, **kwargs)
         cwcfg.load_cwctl_plugins()
+        logger = getLogger('cubicweb')
         set_log_methods(CubicWebRootResource, logger)
         server.parsePOSTData = parsePOSTData
 
     def SvcStop(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)
@@ -39,8 +48,12 @@
     def SvcDoRun(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 site
             config = cwcfg.config_for(self.instance)
             root_resource = CubicWebRootResource(config, False)
--- a/server/sources/native.py	Tue Apr 27 11:23:20 2010 +0200
+++ b/server/sources/native.py	Tue Apr 27 11:25:40 2010 +0200
@@ -216,6 +216,13 @@
           'help': 'database encoding',
           'group': 'native-source', 'inputlevel': 1,
           }),
+        ('db-extra-arguments',
+         {'type' : 'string',
+          'default': '',
+          'help': 'set to "Trusted_Connection" if you are using SQLServer and '
+                  'want trusted authentication for the database connection',
+          'group': 'native-source', 'inputlevel': 2,
+          }),
     )
 
     def __init__(self, repo, appschema, source_config, *args, **kwargs):