Commit 17ea6fbe authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

[webconfig] refactor/cleanup debug mode management on startup: simply use...

[webconfig] refactor/cleanup debug mode management on startup: simply use config.debugmode instead of debug argument everywhere...
parent 2a9181b82806
......@@ -293,8 +293,6 @@ class CubicWebNoAppConfiguration(ConfigurationMixIn):
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 @@ this option is set to yes",
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 @@ this option is set to yes",
# 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 @@ the repository',
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 @@ the repository',
# 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 @@ the repository',
# 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')
......
......@@ -477,14 +477,13 @@ running.'}),
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 @@ running.'}),
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):
......
......@@ -442,10 +442,10 @@ class CubicWebVRegistry(VRegistry):
* 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
......
......@@ -66,7 +66,7 @@ class DevConfiguration(ServerConfiguration, WebConfiguration):
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
......
......@@ -122,12 +122,11 @@ class LongTimeExpiringFile(File):
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 @@ class CubicWebRootResource(resource.Resource):
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 @@ from cubicweb import set_log_methods
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)'")
......
......@@ -32,9 +32,9 @@ class TWStartHandler(CommandHandler):
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'
......
......@@ -111,7 +111,7 @@ class MigrationHelper(object):
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
......
......@@ -104,10 +104,10 @@ class Repository(object):
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)
......
......@@ -249,9 +249,9 @@ class RepositoryStartHandler(CommandHandler):
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))
......
......@@ -280,12 +280,12 @@ class CubicWebPublisher(object):
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)
......
......@@ -100,9 +100,8 @@ class CubicWebWSGIApplication(object):
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()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment