cwctl.py
brancholdstable
changeset 7074 e4580e5f0703
parent 7028 e8855733b125
child 7129 455b503fb7ff
equal deleted inserted replaced
6749:48f468f33704 7074:e4580e5f0703
    40 
    40 
    41 from logilab.common.clcommands import CommandLine
    41 from logilab.common.clcommands import CommandLine
    42 from logilab.common.shellutils import ASK
    42 from logilab.common.shellutils import ASK
    43 
    43 
    44 from cubicweb import ConfigurationError, ExecutionError, BadCommandUsage
    44 from cubicweb import ConfigurationError, ExecutionError, BadCommandUsage
       
    45 from cubicweb.utils import support_args
    45 from cubicweb.cwconfig import CubicWebConfiguration as cwcfg, CWDEV, CONFIGURATIONS
    46 from cubicweb.cwconfig import CubicWebConfiguration as cwcfg, CWDEV, CONFIGURATIONS
    46 from cubicweb.toolsutils import Command, rm, create_dir, underline_title
    47 from cubicweb.toolsutils import Command, rm, create_dir, underline_title
    47 from cubicweb.__pkginfo__ import version
    48 from cubicweb.__pkginfo__ import version
    48 
    49 
    49 CWCTL = CommandLine('cubicweb-ctl', 'The CubicWeb swiss-knife.', version=version)
    50 if support_args(CommandLine, 'check_duplicated_command'):
       
    51     # don't check duplicated commands, it occurs when reloading site_cubicweb
       
    52     CWCTL = CommandLine('cubicweb-ctl', 'The CubicWeb swiss-knife.',
       
    53                         version=version, check_duplicated_command=False)
       
    54 else:
       
    55     CWCTL = CommandLine('cubicweb-ctl', 'The CubicWeb swiss-knife.',
       
    56                         version=version)
    50 
    57 
    51 def wait_process_end(pid, maxtry=10, waittime=1):
    58 def wait_process_end(pid, maxtry=10, waittime=1):
    52     """wait for a process to actually die"""
    59     """wait for a process to actually die"""
    53     import signal
    60     import signal
    54     from time import sleep
    61     from time import sleep
   233             for cube in cwcfg.available_cubes():
   240             for cube in cwcfg.available_cubes():
   234                 try:
   241                 try:
   235                     tinfo = cwcfg.cube_pkginfo(cube)
   242                     tinfo = cwcfg.cube_pkginfo(cube)
   236                     tversion = tinfo.version
   243                     tversion = tinfo.version
   237                     cfgpb.add_cube(cube, tversion)
   244                     cfgpb.add_cube(cube, tversion)
   238                 except ConfigurationError:
   245                 except (ConfigurationError, AttributeError), ex:
   239                     tinfo = None
   246                     tinfo = None
   240                     tversion = '[missing cube information]'
   247                     tversion = '[missing cube information: %s]' % ex
   241                 print '* %s %s' % (cube.ljust(namesize), tversion)
   248                 print '* %s %s' % (cube.ljust(namesize), tversion)
   242                 if self.config.verbose:
   249                 if self.config.verbose:
   243                     if tinfo:
   250                     if tinfo:
   244                         descr = getattr(tinfo, 'description', '')
   251                         descr = getattr(tinfo, 'description', '')
   245                         if not descr:
   252                         if not descr:
   492         pidf = config['pid-file']
   499         pidf = config['pid-file']
   493         if exists(pidf) and not self['force']:
   500         if exists(pidf) and not self['force']:
   494             msg = "%s seems to be running. Remove %s by hand if necessary or use \
   501             msg = "%s seems to be running. Remove %s by hand if necessary or use \
   495 the --force option."
   502 the --force option."
   496             raise ExecutionError(msg % (appid, pidf))
   503             raise ExecutionError(msg % (appid, pidf))
   497         helper.start_server(config)
   504         if helper.start_server(config) == 1:
       
   505             print 'instance %s started' % appid
   498 
   506 
   499 
   507 
   500 def init_cmdline_log_threshold(config, loglevel):
   508 def init_cmdline_log_threshold(config, loglevel):
   501     if loglevel is not None:
   509     if loglevel is not None:
   502         config.global_set_option('log-threshold', loglevel.upper())
   510         config.global_set_option('log-threshold', loglevel.upper())
   654       given, upgrade them all.
   662       given, upgrade them all.
   655     """
   663     """
   656     name = 'upgrade'
   664     name = 'upgrade'
   657     actionverb = 'upgraded'
   665     actionverb = 'upgraded'
   658     options = InstanceCommand.options + (
   666     options = InstanceCommand.options + (
   659         ('force-componant-version',
   667         ('force-cube-version',
   660          {'short': 't', 'type' : 'csv', 'metavar': 'cube1=X.Y.Z,cube2=X.Y.Z',
   668          {'short': 't', 'type' : 'named', 'metavar': 'cube1:X.Y.Z,cube2:X.Y.Z',
   661           'default': None,
   669           'default': None,
   662           'help': 'force migration from the indicated  version for the specified cube.'}),
   670           'help': 'force migration from the indicated version for the specified cube(s).'}),
       
   671 
   663         ('force-cubicweb-version',
   672         ('force-cubicweb-version',
   664          {'short': 'e', 'type' : 'string', 'metavar': 'X.Y.Z',
   673          {'short': 'e', 'type' : 'string', 'metavar': 'X.Y.Z',
   665           'default': None,
   674           'default': None,
   666           'help': 'force migration from the indicated cubicweb version.'}),
   675           'help': 'force migration from the indicated cubicweb version.'}),
   667 
   676 
   711             pass
   720             pass
   712         # get instance and installed versions for the server and the componants
   721         # get instance and installed versions for the server and the componants
   713         mih = config.migration_handler()
   722         mih = config.migration_handler()
   714         repo = mih.repo_connect()
   723         repo = mih.repo_connect()
   715         vcconf = repo.get_versions()
   724         vcconf = repo.get_versions()
   716         if self.config.force_componant_version:
   725         if self.config.force_cube_version:
   717             packversions = {}
   726             for cube, version in self.config.force_cube_version.iteritems():
   718             for vdef in self.config.force_componant_version:
   727                 vcconf[cube] = Version(version)
   719                 componant, version = vdef.split('=')
       
   720                 packversions[componant] = Version(version)
       
   721             vcconf.update(packversions)
       
   722         toupgrade = []
   728         toupgrade = []
   723         for cube in config.cubes():
   729         for cube in config.cubes():
   724             installedversion = config.cube_version(cube)
   730             installedversion = config.cube_version(cube)
   725             try:
   731             try:
   726                 applversion = vcconf[cube]
   732                 applversion = vcconf[cube]