[webconfig] refactor/cleanup debug mode management on startup: simply use config.debugmode instead of debug argument everywhere...
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 29 Apr 2010 14:21:57 +0200
changeset 5442 3ed8afbbdf70
parent 5438 2a9181b82806
child 5443 f299ee54d7e0
[webconfig] refactor/cleanup debug mode management on startup: simply use config.debugmode instead of debug argument everywhere...
cwconfig.py
cwctl.py
cwvreg.py
devtools/devctl.py
etwist/server.py
etwist/twctl.py
migration.py
server/repository.py
server/serverctl.py
web/application.py
wsgi/handler.py
--- a/cwconfig.py	Thu Apr 29 11:09:03 2010 +0200
+++ b/cwconfig.py	Thu Apr 29 14:21:57 2010 +0200
@@ -293,8 +293,6 @@
     log_format = '%(asctime)s - (%(name)s) %(levelname)s: %(message)s'
     # nor remove appobjects based on unused interface
     cleanup_interface_sobjects = True
-    # debug mode
-    debugmode = False
 
 
     if (CWDEV and _forced_mode != 'system'):
@@ -660,9 +658,10 @@
                     vregpath.append(path + '.py')
         return vregpath
 
-    def __init__(self):
+    def __init__(self, debugmode=False):
         register_stored_procedures()
         ConfigurationMixIn.__init__(self)
+        self.debugmode = debugmode
         self.adjust_sys_path()
         self.load_defaults()
         self.translations = {}
@@ -680,16 +679,14 @@
         # overriden in CubicWebConfiguration
         self.cls_adjust_sys_path()
 
-    def init_log(self, logthreshold=None, debug=False,
-                 logfile=None, syslog=False):
+    def init_log(self, logthreshold=None, logfile=None, syslog=False):
         """init the log service"""
         if logthreshold is None:
-            if debug:
+            if self.debugmode:
                 logthreshold = 'DEBUG'
             else:
                 logthreshold = self['log-threshold']
-        self.debugmode = debug
-        init_log(debug, syslog, logthreshold, logfile, self.log_format)
+        init_log(self.debugmode, syslog, logthreshold, logfile, self.log_format)
         # configure simpleTal logger
         logging.getLogger('simpleTAL').setLevel(logging.ERROR)
 
@@ -803,12 +800,12 @@
         return mdir
 
     @classmethod
-    def config_for(cls, appid, config=None):
+    def config_for(cls, appid, config=None, debugmode=False):
         """return a configuration instance for the given instance identifier
         """
         config = config or guess_configuration(cls.instance_home(appid))
         configcls = configuration_cls(config)
-        return configcls(appid)
+        return configcls(appid, debugmode)
 
     @classmethod
     def possible_configurations(cls, appid):
@@ -876,9 +873,9 @@
 
     # instance methods used to get instance specific resources #############
 
-    def __init__(self, appid):
+    def __init__(self, appid, debugmode=False):
         self.appid = appid
-        CubicWebNoAppConfiguration.__init__(self)
+        CubicWebNoAppConfiguration.__init__(self, debugmode)
         self._cubes = None
         self._site_loaded = set()
         self.load_file_configuration(self.main_config_file())
@@ -990,12 +987,12 @@
             # init gettext
             self._set_language()
 
-    def init_log(self, logthreshold=None, debug=False, force=False):
+    def init_log(self, logthreshold=None, force=False):
         """init the log service"""
         if not force and hasattr(self, '_logging_initialized'):
             return
         self._logging_initialized = True
-        CubicWebNoAppConfiguration.init_log(self, logthreshold, debug,
+        CubicWebNoAppConfiguration.init_log(self, logthreshold,
                                             logfile=self.get('log-file'))
         # read a config file if it exists
         logconfig = join(self.apphome, 'logging.conf')
--- a/cwctl.py	Thu Apr 29 11:09:03 2010 +0200
+++ b/cwctl.py	Thu Apr 29 14:21:57 2010 +0200
@@ -477,14 +477,13 @@
 
     def start_instance(self, appid):
         """start the instance's server"""
-        debug = self['debug']
         force = self['force']
         loglevel = self['loglevel']
-        config = cwcfg.config_for(appid)
+        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, debug=debug, force=True)
+            config.init_log(loglevel, force=True)
         if self['profile']:
             config.global_set_option('profile', self.config.profile)
         helper = self.config_helper(config, cmdname='start')
@@ -493,7 +492,7 @@
             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, debug)
+        helper.start_server(config)
 
 
 class StopInstanceCommand(InstanceCommand):
--- a/cwvreg.py	Thu Apr 29 11:09:03 2010 +0200
+++ b/cwvreg.py	Thu Apr 29 14:21:57 2010 +0200
@@ -442,10 +442,10 @@
     * contentnavigation XXX to merge with components? to kill?
     """
 
-    def __init__(self, config, debug=None, initlog=True):
+    def __init__(self, config, initlog=True):
         if initlog:
             # first init log service
-            config.init_log(debug=debug)
+            config.init_log()
         super(CubicWebVRegistry, self).__init__(config)
         self.schema = None
         self.initialized = False
--- a/devtools/devctl.py	Thu Apr 29 11:09:03 2010 +0200
+++ b/devtools/devctl.py	Thu Apr 29 14:21:57 2010 +0200
@@ -66,7 +66,7 @@
         return None
     def main_config_file(self):
         return None
-    def init_log(self, debug=None):
+    def init_log(self):
         pass
     def load_configuration(self):
         pass
--- a/etwist/server.py	Thu Apr 29 11:09:03 2010 +0200
+++ b/etwist/server.py	Thu Apr 29 14:21:57 2010 +0200
@@ -122,12 +122,11 @@
 
 
 class CubicWebRootResource(resource.Resource):
-    def __init__(self, config, debug=None):
-        self.debugmode = debug
+    def __init__(self, config):
         self.config = config
         # instantiate publisher here and not in init_publisher to get some
         # checks done before daemonization (eg versions consistency)
-        self.appli = CubicWebPublisher(config, debug=self.debugmode)
+        self.appli = CubicWebPublisher(config)
         self.base_url = config['base-url']
         self.https_url = config['https-url']
         self.children = {}
@@ -210,7 +209,7 @@
     def render(self, request):
         """Render a page from the root resource"""
         # reload modified files in debug mode
-        if self.debugmode:
+        if self.config.debugmode:
             self.appli.vreg.reload_if_needed()
         if self.config['profile']: # default profiler don't trace threads
             return self.render_request(request)
@@ -405,15 +404,15 @@
 LOGGER = getLogger('cubicweb.twisted')
 set_log_methods(CubicWebRootResource, LOGGER)
 
-def run(config, debug):
+def run(config):
     # create the site
-    root_resource = CubicWebRootResource(config, debug)
+    root_resource = CubicWebRootResource(config)
     website = server.Site(root_resource)
     # serve it via standard HTTP on port set in the configuration
     port = config['port'] or 8080
     reactor.listenTCP(port, website)
     logger = getLogger('cubicweb.twisted')
-    if not debug:
+    if not config.debugmode:
         if sys.platform == 'win32':
             raise ConfigurationError("Under windows, you must use the service management "
                                      "commands (e.g : 'net start my_instance)'")
--- a/etwist/twctl.py	Thu Apr 29 11:09:03 2010 +0200
+++ b/etwist/twctl.py	Thu Apr 29 14:21:57 2010 +0200
@@ -32,9 +32,9 @@
     cmdname = 'start'
     cfgname = 'twisted'
 
-    def start_server(self, config, debug):
+    def start_server(self, config):
         from cubicweb.etwist import server
-        server.run(config, debug)
+        server.run(config)
 
 class TWStopHandler(CommandHandler):
     cmdname = 'stop'
--- a/migration.py	Thu Apr 29 11:09:03 2010 +0200
+++ b/migration.py	Thu Apr 29 14:21:57 2010 +0200
@@ -111,7 +111,7 @@
         self.config = config
         if config:
             # no config on shell to a remote instance
-            self.config.init_log(logthreshold=logging.ERROR, debug=True)
+            self.config.init_log(logthreshold=logging.ERROR)
         # 0: no confirmation, 1: only main commands confirmed, 2 ask for everything
         self.verbosity = verbosity
         self.need_wrap = True
--- a/server/repository.py	Thu Apr 29 11:09:03 2010 +0200
+++ b/server/repository.py	Thu Apr 29 14:21:57 2010 +0200
@@ -104,10 +104,10 @@
     XXX protect pyro access
     """
 
-    def __init__(self, config, vreg=None, debug=False):
+    def __init__(self, config, vreg=None):
         self.config = config
         if vreg is None:
-            vreg = cwvreg.CubicWebVRegistry(config, debug)
+            vreg = cwvreg.CubicWebVRegistry(config)
         self.vreg = vreg
         self.pyro_registered = False
         self.info('starting repository from %s', self.config.apphome)
--- a/server/serverctl.py	Thu Apr 29 11:09:03 2010 +0200
+++ b/server/serverctl.py	Thu Apr 29 14:21:57 2010 +0200
@@ -249,9 +249,9 @@
     cmdname = 'start'
     cfgname = 'repository'
 
-    def start_server(self, ctlconf, debug):
+    def start_server(self, ctlconf):
         command = ['cubicweb-ctl start-repository ']
-        if debug:
+        if ctlconf.debugmode:
             command.append('--debug')
         command.append(self.config.appid)
         os.system(' '.join(command))
--- a/web/application.py	Thu Apr 29 11:09:03 2010 +0200
+++ b/web/application.py	Thu Apr 29 14:21:57 2010 +0200
@@ -280,12 +280,12 @@
     to publish HTTP request.
     """
 
-    def __init__(self, config, debug=None,
+    def __init__(self, config,
                  session_handler_fact=CookieSessionHandler,
                  vreg=None):
         self.info('starting web instance from %s', config.apphome)
         if vreg is None:
-            vreg = cwvreg.CubicWebVRegistry(config, debug=debug)
+            vreg = cwvreg.CubicWebVRegistry(config)
         self.vreg = vreg
         # connect to the repository and get instance's schema
         self.repo = config.repository(vreg)
--- a/wsgi/handler.py	Thu Apr 29 11:09:03 2010 +0200
+++ b/wsgi/handler.py	Thu Apr 29 14:21:57 2010 +0200
@@ -100,9 +100,8 @@
     NOTE: no pyro
     """
 
-    def __init__(self, config, debug=None, vreg=None):
-        self.appli = CubicWebPublisher(config, debug=debug, vreg=vreg)
-        self.debugmode = debug
+    def __init__(self, config, vreg=None):
+        self.appli = CubicWebPublisher(config, vreg=vreg)
         self.config = config
         self.base_url = None
 #         self.base_url = config['base-url'] or config.default_base_url()