cubicweb/cwctl.py
changeset 12743 a74e77469540
parent 12737 56f7386bc6b9
child 12749 ff63319a1730
equal deleted inserted replaced
12742:ca698656251c 12743:a74e77469540
    38 from logilab.common.clcommands import CommandLine
    38 from logilab.common.clcommands import CommandLine
    39 from logilab.common.shellutils import ASK
    39 from logilab.common.shellutils import ASK
    40 from logilab.common.configuration import merge_options
    40 from logilab.common.configuration import merge_options
    41 from logilab.common.decorators import clear_cache
    41 from logilab.common.decorators import clear_cache
    42 
    42 
    43 from cubicweb import ConfigurationError, ExecutionError, BadCommandUsage
    43 from cubicweb import ConfigurationError, ExecutionError, BadCommandUsage, utils
    44 from cubicweb.cwconfig import CubicWebConfiguration as cwcfg, CONFIGURATIONS
    44 from cubicweb.cwconfig import CubicWebConfiguration as cwcfg, CONFIGURATIONS
    45 from cubicweb.server import set_debug
    45 from cubicweb.server import set_debug
    46 from cubicweb.toolsutils import Command, rm, create_dir, underline_title
    46 from cubicweb.toolsutils import Command, rm, create_dir, underline_title
    47 from cubicweb.__pkginfo__ import version as cw_version
    47 from cubicweb.__pkginfo__ import version as cw_version
    48 
    48 
    98         if cube.startswith(prefix):
    98         if cube.startswith(prefix):
    99             cube = cube[len(prefix):]
    99             cube = cube[len(prefix):]
   100         return cube
   100         return cube
   101 
   101 
   102     return [drop_prefix(cube) for cube in cwcfg.available_cubes()]
   102     return [drop_prefix(cube) for cube in cwcfg.available_cubes()]
   103 
       
   104 
       
   105 def get_pdb():
       
   106     try:
       
   107         import ipdb
       
   108     except ImportError:
       
   109         import pdb
       
   110         return pdb
       
   111     else:
       
   112         return ipdb
       
   113 
   103 
   114 
   104 
   115 class InstanceCommand(Command):
   105 class InstanceCommand(Command):
   116     """base class for command taking one instance id as arguments"""
   106     """base class for command taking one instance id as arguments"""
   117     arguments = '<instance>'
   107     arguments = '<instance>'
   206                 status = 2  # specific error code
   196                 status = 2  # specific error code
   207             else:
   197             else:
   208                 status = ex.code
   198                 status = ex.code
   209 
   199 
   210         if status != 0 and self.config.pdb:
   200         if status != 0 and self.config.pdb:
   211             pdb = get_pdb()
   201             pdb = utils.get_pdb()
   212 
   202 
   213             if traceback_ is not None:
   203             if traceback_ is not None:
   214                 pdb.post_mortem(traceback_)
   204                 pdb.post_mortem(traceback_)
   215             else:
   205             else:
   216                 print("WARNING: Could not access to the traceback because the command return "
   206                 print("WARNING: Could not access to the traceback because the command return "