server/serverctl.py
changeset 7457 f7c97a3cd121
parent 7398 26695dd703d8
child 7479 b0603fc4ed6d
equal deleted inserted replaced
7456:c54038622fc9 7457:f7c97a3cd121
    22 # *ctl module should limit the number of import to be imported as quickly as
    22 # *ctl module should limit the number of import to be imported as quickly as
    23 # possible (for cubicweb-ctl reactivity, necessary for instance for usable bash
    23 # possible (for cubicweb-ctl reactivity, necessary for instance for usable bash
    24 # completion). So import locally in command helpers.
    24 # completion). So import locally in command helpers.
    25 import sys
    25 import sys
    26 import os
    26 import os
       
    27 import logging
    27 
    28 
    28 from logilab.common import nullobject
    29 from logilab.common import nullobject
    29 from logilab.common.configuration import Configuration
    30 from logilab.common.configuration import Configuration
    30 from logilab.common.shellutils import ASK, generate_password
    31 from logilab.common.shellutils import ASK, generate_password
    31 
    32 
   635         from cubicweb.cwctl import init_cmdline_log_threshold
   636         from cubicweb.cwctl import init_cmdline_log_threshold
   636         from cubicweb.server.server import RepositoryServer
   637         from cubicweb.server.server import RepositoryServer
   637         appid = args[0]
   638         appid = args[0]
   638         debug = self['debug']
   639         debug = self['debug']
   639         if sys.platform == 'win32' and not debug:
   640         if sys.platform == 'win32' and not debug:
   640             from logging import getLogger
   641             logger = logging.getLogger('cubicweb.ctl')
   641             logger = getLogger('cubicweb.ctl')
       
   642             logger.info('Forcing debug mode on win32 platform')
   642             logger.info('Forcing debug mode on win32 platform')
   643             debug = True
   643             debug = True
   644         config = ServerConfiguration.config_for(appid, debugmode=debug)
   644         config = ServerConfiguration.config_for(appid, debugmode=debug)
   645         init_cmdline_log_threshold(config, self['loglevel'])
   645         init_cmdline_log_threshold(config, self['loglevel'])
   646         # create the server
   646         # create the server
   993         config = ServerConfiguration.config_for(appid)
   993         config = ServerConfiguration.config_for(appid)
   994         mih = config.migration_handler()
   994         mih = config.migration_handler()
   995         mih.cmd_synchronize_schema()
   995         mih.cmd_synchronize_schema()
   996 
   996 
   997 
   997 
       
   998 class SynchronizeSourceCommand(Command):
       
   999     """Force a source synchronization.
       
  1000 
       
  1001     <instance>
       
  1002       the identifier of the instance
       
  1003     <source>
       
  1004       the name of the source to synchronize.
       
  1005     """
       
  1006     name = 'source-sync'
       
  1007     arguments = '<instance> <source>'
       
  1008     min_args = max_args = 2
       
  1009 
       
  1010     def run(self, args):
       
  1011         config = ServerConfiguration.config_for(args[0])
       
  1012         config.global_set_option('log-file', None)
       
  1013         config.log_format = '%(levelname)s %(name)s: %(message)s'
       
  1014         logger = logging.getLogger('cubicweb.sources')
       
  1015         logger.setLevel(logging.INFO)
       
  1016         # only retrieve cnx to trigger authentication, close it right away
       
  1017         repo, cnx = repo_cnx(config)
       
  1018         cnx.close()
       
  1019         try:
       
  1020             source = repo.sources_by_uri[args[1]]
       
  1021         except KeyError:
       
  1022             raise ExecutionError('no source named %r' % args[1])
       
  1023         session = repo.internal_session()
       
  1024         stats = source.pull_data(session, force=True, raise_on_error=True)
       
  1025         for key, val in stats.iteritems():
       
  1026             if val:
       
  1027                 print key, ':', val
       
  1028 
       
  1029 
   998 for cmdclass in (CreateInstanceDBCommand, InitInstanceCommand,
  1030 for cmdclass in (CreateInstanceDBCommand, InitInstanceCommand,
   999                  GrantUserOnInstanceCommand, ResetAdminPasswordCommand,
  1031                  GrantUserOnInstanceCommand, ResetAdminPasswordCommand,
  1000                  StartRepositoryCommand,
  1032                  StartRepositoryCommand,
  1001                  DBDumpCommand, DBRestoreCommand, DBCopyCommand,
  1033                  DBDumpCommand, DBRestoreCommand, DBCopyCommand,
  1002                  AddSourceCommand, CheckRepositoryCommand, RebuildFTICommand,
  1034                  AddSourceCommand, CheckRepositoryCommand, RebuildFTICommand,
  1003                  SynchronizeInstanceSchemaCommand,
  1035                  SynchronizeInstanceSchemaCommand, SynchronizeSourceCommand
  1004                  ):
  1036                  ):
  1005     CWCTL.register(cmdclass)
  1037     CWCTL.register(cmdclass)