cubicweb/cwctl.py
changeset 11870 3a84a79c4ed5
parent 11867 c714e55fbce1
child 11878 e42cb31e9301
equal deleted inserted replaced
11869:d8b66e3fd335 11870:3a84a79c4ed5
    18 """the cubicweb-ctl tool, based on logilab.common.clcommands to
    18 """the cubicweb-ctl tool, based on logilab.common.clcommands to
    19 provide a pluggable commands system.
    19 provide a pluggable commands system.
    20 """
    20 """
    21 from __future__ import print_function
    21 from __future__ import print_function
    22 
    22 
    23 
       
    24 
       
    25 # *ctl module should limit the number of import to be imported as quickly as
    23 # *ctl module should limit the number of import to be imported as quickly as
    26 # possible (for cubicweb-ctl reactivity, necessary for instance for usable bash
    24 # possible (for cubicweb-ctl reactivity, necessary for instance for usable bash
    27 # completion). So import locally in command helpers.
    25 # completion). So import locally in command helpers.
    28 import sys
    26 import sys
    29 from warnings import warn, filterwarnings
    27 from warnings import warn, filterwarnings
    30 from os import remove, listdir, system, pathsep
    28 from os import remove, listdir, system, pathsep
    31 from os.path import exists, join, isfile, isdir, dirname, abspath
    29 from os.path import exists, join, isdir, dirname, abspath
    32 
    30 
    33 try:
    31 try:
    34     from os import kill, getpgid
    32     from os import kill, getpgid
    35 except ImportError:
    33 except ImportError:
    36     def kill(*args):
    34     def kill(*args):
    41 from six.moves.urllib.parse import urlparse
    39 from six.moves.urllib.parse import urlparse
    42 
    40 
    43 from logilab.common.clcommands import CommandLine
    41 from logilab.common.clcommands import CommandLine
    44 from logilab.common.shellutils import ASK
    42 from logilab.common.shellutils import ASK
    45 from logilab.common.configuration import merge_options
    43 from logilab.common.configuration import merge_options
    46 from logilab.common.deprecation import deprecated
       
    47 
    44 
    48 from cubicweb import ConfigurationError, ExecutionError, BadCommandUsage
    45 from cubicweb import ConfigurationError, ExecutionError, BadCommandUsage
    49 from cubicweb.cwconfig import CubicWebConfiguration as cwcfg, CWDEV, CONFIGURATIONS
    46 from cubicweb.cwconfig import CubicWebConfiguration as cwcfg, CWDEV, CONFIGURATIONS
    50 from cubicweb.toolsutils import Command, rm, create_dir, underline_title
    47 from cubicweb.toolsutils import Command, rm, create_dir, underline_title
    51 from cubicweb.__pkginfo__ import version
    48 from cubicweb.__pkginfo__ import version
    52 
    49 
    53 # don't check duplicated commands, it occurs when reloading site_cubicweb
    50 # don't check duplicated commands, it occurs when reloading site_cubicweb
    54 CWCTL = CommandLine('cubicweb-ctl', 'The CubicWeb swiss-knife.',
    51 CWCTL = CommandLine('cubicweb-ctl', 'The CubicWeb swiss-knife.',
    55                     version=version, check_duplicated_command=False)
    52                     version=version, check_duplicated_command=False)
       
    53 
    56 
    54 
    57 def wait_process_end(pid, maxtry=10, waittime=1):
    55 def wait_process_end(pid, maxtry=10, waittime=1):
    58     """wait for a process to actually die"""
    56     """wait for a process to actually die"""
    59     import signal
    57     import signal
    60     from time import sleep
    58     from time import sleep
    61     nbtry = 0
    59     nbtry = 0
    62     while nbtry < maxtry:
    60     while nbtry < maxtry:
    63         try:
    61         try:
    64             kill(pid, signal.SIGUSR1)
    62             kill(pid, signal.SIGUSR1)
    65         except (OSError, AttributeError): # XXX win32
    63         except (OSError, AttributeError):  # XXX win32
    66             break
    64             break
    67         nbtry += 1
    65         nbtry += 1
    68         sleep(waittime)
    66         sleep(waittime)
    69     else:
    67     else:
    70         raise ExecutionError('can\'t kill process %s' % pid)
    68         raise ExecutionError('can\'t kill process %s' % pid)
    71 
    69 
       
    70 
    72 def list_instances(regdir):
    71 def list_instances(regdir):
    73     if isdir(regdir):
    72     if isdir(regdir):
    74         return sorted(idir for idir in listdir(regdir) if isdir(join(regdir, idir)))
    73         return sorted(idir for idir in listdir(regdir) if isdir(join(regdir, idir)))
    75     else:
    74     else:
    76         return []
    75         return []
       
    76 
    77 
    77 
    78 def detect_available_modes(templdir):
    78 def detect_available_modes(templdir):
    79     modes = []
    79     modes = []
    80     for fname in ('schema', 'schema.py'):
    80     for fname in ('schema', 'schema.py'):
    81         if exists(join(templdir, fname)):
    81         if exists(join(templdir, fname)):