ccplugin.py
changeset 11645 2a949974002d
parent 11644 41bd2b316228
child 11647 7f2cfe9f79cb
equal deleted inserted replaced
11644:41bd2b316228 11645:2a949974002d
    36 
    36 
    37     options = (
    37     options = (
    38         ('no-daemon',
    38         ('no-daemon',
    39          {'action': 'store_true',
    39          {'action': 'store_true',
    40           'help': 'Run the server in the foreground.'}),
    40           'help': 'Run the server in the foreground.'}),
       
    41         ('debug-mode',
       
    42          {'action': 'store_true',
       
    43           'help': 'Activate the repository debug mode ('
       
    44                   'logs in the console and the debug toolbar).'
       
    45                   ' Implies --no-daemon'}),
    41         ('debug',
    46         ('debug',
    42          {'short': 'D', 'action': 'store_true',
    47          {'short': 'D', 'action': 'store_true',
    43           'help': 'Activate the debug tools and '
    48           'help': 'Equals to "--debug-mode --no-daemon --reload"'}),
    44                   'run the server in the foreground.'}),
       
    45         ('reload',
    49         ('reload',
    46          {'action': 'store_true',
    50          {'action': 'store_true',
    47           'help': 'Restart the server if any source file is changed'}),
    51           'help': 'Restart the server if any source file is changed'}),
    48         ('reload-interval',
    52         ('reload-interval',
    49          {'type': 'int', 'default': 1,
    53          {'type': 'int', 'default': 1,
    64     def info(self, msg):
    68     def info(self, msg):
    65         print('INFO - %s' % msg)
    69         print('INFO - %s' % msg)
    66 
    70 
    67     def ordered_instances(self):
    71     def ordered_instances(self):
    68         instances = super(PyramidStartHandler, self).ordered_instances()
    72         instances = super(PyramidStartHandler, self).ordered_instances()
    69         if (self['debug'] or self['reload']) and len(instances) > 1:
    73         if (self['debug-mode'] or self['debug'] or self['reload']) \
       
    74                 and len(instances) > 1:
    70             raise BadCommandUsage(
    75             raise BadCommandUsage(
    71                 '--debug and --reload can be used on a single instance only')
    76                 '--debug-mode, --debug and --reload can be used on a single '
       
    77                 'instance only')
    72         return instances
    78         return instances
    73 
    79 
    74     def quote_first_command_arg(self, arg):
    80     def quote_first_command_arg(self, arg):
    75         """
    81         """
    76         There's a bug in Windows when running an executable that's
    82         There's a bug in Windows when running an executable that's
   239                     yield f
   245                     yield f
   240 
   246 
   241     def pyramid_instance(self, appid):
   247     def pyramid_instance(self, appid):
   242         self._needreload = False
   248         self._needreload = False
   243 
   249 
   244         if self['reload'] and not os.environ.get(self._reloader_environ_key):
   250         debugmode = self['debug-mode'] or self['debug']
       
   251         autoreload = self['reload'] or self['debug']
       
   252         daemonize = not (self['no-daemon'] or debugmode or autoreload)
       
   253 
       
   254         if autoreload and not os.environ.get(self._reloader_environ_key):
   245             return self.restart_with_reloader()
   255             return self.restart_with_reloader()
   246 
   256 
   247         cwconfig = cwcfg.config_for(appid, debugmode=self['debug'])
   257         cwconfig = cwcfg.config_for(appid, debugmode=debugmode)
   248 
   258 
   249         if self['reload']:
   259         if autoreload:
   250             _turn_sigterm_into_systemexit()
   260             _turn_sigterm_into_systemexit()
   251             self.debug('Running reloading file monitor')
   261             self.debug('Running reloading file monitor')
   252             extra_files = [sys.argv[0], cwconfig.main_config_file()]
   262             extra_files = [sys.argv[0], cwconfig.main_config_file()]
   253             extra_files.extend(self.i18nfiles(cwconfig))
   263             extra_files.extend(self.i18nfiles(cwconfig))
   254             self.install_reloader(
   264             self.install_reloader(
   255                 self['reload-interval'], extra_files,
   265                 self['reload-interval'], extra_files,
   256                 filelist_path=os.environ.get(
   266                 filelist_path=os.environ.get(
   257                     self._reloader_filelist_environ_key))
   267                     self._reloader_filelist_environ_key))
   258 
   268 
   259         if not (self['no-daemon'] or self['reload'] or self['debug']):
   269         if daemonize:
   260             self.daemonize(cwconfig['pid-file'])
   270             self.daemonize(cwconfig['pid-file'])
   261             self.record_pid(cwconfig['pid-file'])
   271             self.record_pid(cwconfig['pid-file'])
   262 
   272 
   263         init_cmdline_log_threshold(cwconfig, self['loglevel'])
   273         init_cmdline_log_threshold(cwconfig, self['loglevel'])
   264 
   274