[repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 21 Jun 2010 15:32:58 +0200
changeset 5814 51cc4b61f9ae
parent 5811 e77cea9721e7
child 5815 282194aa43f3
[repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
cwctl.py
devtools/testlib.py
etwist/server.py
etwist/twctl.py
server/server.py
server/serverctl.py
--- a/cwctl.py	Mon Jun 21 13:23:11 2010 +0200
+++ b/cwctl.py	Mon Jun 21 15:32:58 2010 +0200
@@ -17,9 +17,8 @@
 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
 """the cubicweb-ctl tool, based on logilab.common.clcommands to
 provide a pluggable commands system.
-
+"""
 
-"""
 __docformat__ = "restructuredtext en"
 
 # *ctl module should limit the number of import to be imported as quickly as
@@ -477,24 +476,25 @@
 
     def start_instance(self, appid):
         """start the instance's server"""
-        force = self['force']
-        loglevel = self['loglevel']
         config = cwcfg.config_for(appid, debugmode=self['debug'])
-        if loglevel is not None:
-            loglevel = 'LOG_%s' % loglevel.upper()
-            config.global_set_option('log-threshold', loglevel)
-            config.init_log(loglevel, force=True)
+        init_cmdline_log_threshold(config, self['loglevel'])
         if self['profile']:
             config.global_set_option('profile', self.config.profile)
         helper = self.config_helper(config, cmdname='start')
         pidf = config['pid-file']
-        if exists(pidf) and not force:
+        if exists(pidf) and not self['force']:
             msg = "%s seems to be running. Remove %s by hand if necessary or use \
 the --force option."
             raise ExecutionError(msg % (appid, pidf))
         helper.start_server(config)
 
 
+def init_cmdline_log_threshold(config, loglevel):
+    if loglevel is not None:
+        config.global_set_option('log-threshold', loglevel.upper())
+        config.init_log(config['log-threshold'], force=True)
+
+
 class StopInstanceCommand(InstanceCommand):
     """Stop the given instances.
 
--- a/devtools/testlib.py	Mon Jun 21 13:23:11 2010 +0200
+++ b/devtools/testlib.py	Mon Jun 21 15:32:58 2010 +0200
@@ -15,9 +15,8 @@
 #
 # You should have received a copy of the GNU Lesser General Public License along
 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
-"""this module contains base classes and utilities for cubicweb tests
+"""this module contains base classes and utilities for cubicweb tests"""
 
-"""
 from __future__ import with_statement
 
 __docformat__ = "restructuredtext en"
--- a/etwist/server.py	Mon Jun 21 13:23:11 2010 +0200
+++ b/etwist/server.py	Mon Jun 21 15:32:58 2010 +0200
@@ -15,9 +15,8 @@
 #
 # You should have received a copy of the GNU Lesser General Public License along
 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
-"""twisted server for CubicWeb web instances
+"""twisted server for CubicWeb web instances"""
 
-"""
 __docformat__ = "restructuredtext en"
 
 import sys
--- a/etwist/twctl.py	Mon Jun 21 13:23:11 2010 +0200
+++ b/etwist/twctl.py	Mon Jun 21 15:32:58 2010 +0200
@@ -15,9 +15,7 @@
 #
 # You should have received a copy of the GNU Lesser General Public License along
 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
-"""cubicweb-clt handlers for twisted
-
-"""
+"""cubicweb-clt handlers for twisted"""
 
 from cubicweb.toolsutils import CommandHandler
 from cubicweb.web.webctl import WebCreateHandler
--- a/server/server.py	Mon Jun 21 13:23:11 2010 +0200
+++ b/server/server.py	Mon Jun 21 15:32:58 2010 +0200
@@ -74,10 +74,10 @@
 
 class RepositoryServer(object):
 
-    def __init__(self, config, debug=False):
+    def __init__(self, config):
         """make the repository available as a PyRO object"""
         self.config = config
-        self.repo = Repository(config, debug=debug)
+        self.repo = Repository(config)
         self.ns = None
         self.quiting = None
         # event queue
--- a/server/serverctl.py	Mon Jun 21 13:23:11 2010 +0200
+++ b/server/serverctl.py	Mon Jun 21 15:32:58 2010 +0200
@@ -15,9 +15,10 @@
 #
 # You should have received a copy of the GNU Lesser General Public License along
 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
-"""cubicweb-ctl commands and command handlers specific to the server.serverconfig
+"""cubicweb-ctl commands and command handlers specific to the
+server.serverconfig
+"""
 
-"""
 __docformat__ = 'restructuredtext en'
 
 # *ctl module should limit the number of import to be imported as quickly as
@@ -251,11 +252,12 @@
     cmdname = 'start'
     cfgname = 'repository'
 
-    def start_server(self, ctlconf):
+    def start_server(self, config):
         command = ['cubicweb-ctl start-repository ']
-        if ctlconf.debugmode:
+        if config.debugmode:
             command.append('--debug')
-        command.append(self.config.appid)
+        command.append('--loglevel %s' % config['log-threshold'])
+        command.append(config.appid)
         os.system(' '.join(command))
 
 
@@ -264,8 +266,7 @@
     cfgname = 'repository'
 
     def poststop(self):
-        """if pyro is enabled, ensure the repository is correctly
-        unregistered
+        """if pyro is enabled, ensure the repository is correctly unregistered
         """
         if self.config.pyro_enabled():
             from cubicweb.server.repository import pyro_unregister
@@ -527,22 +528,28 @@
         ('debug',
          {'short': 'D', 'action' : 'store_true',
           'help': 'start server in debug mode.'}),
+        ('loglevel',
+         {'short': 'l', 'type' : 'choice', 'metavar': '<log level>',
+          'default': None, 'choices': ('debug', 'info', 'warning', 'error'),
+          'help': 'debug if -D is set, error otherwise',
+          }),
         )
 
     def run(self, args):
         from logilab.common.daemon import daemonize
+        from cubicweb.cwctl import init_cmdline_log_threshold
         from cubicweb.server.server import RepositoryServer
         appid = pop_arg(args, msg='No instance specified !')
-        config = ServerConfiguration.config_for(appid)
-        if sys.platform == 'win32':
-            if not self.config.debug:
-                from logging import getLogger
-                logger = getLogger('cubicweb.ctl')
-                logger.info('Forcing debug mode on win32 platform')
-                self.config.debug = True
-        debug = self.config.debug
+        debug = self['debug']
+        if sys.platform == 'win32' and not debug:
+            from logging import getLogger
+            logger = getLogger('cubicweb.ctl')
+            logger.info('Forcing debug mode on win32 platform')
+            debug = True
+        config = ServerConfiguration.config_for(appid, debugmode=debug)
+        init_cmdline_log_threshold(config, self['loglevel'])
         # create the server
-        server = RepositoryServer(config, debug)
+        server = RepositoryServer(config)
         # ensure the directory where the pid-file should be set exists (for
         # instance /var/run/cubicweb may be deleted on computer restart)
         pidfile = config['pid-file']