devtools/devctl.py
changeset 2615 1ea41b7c0836
parent 2551 91f579b7a1e1
child 2633 bc9386c3b2c9
equal deleted inserted replaced
2614:351f1fcfa53c 2615:1ea41b7c0836
    15 from warnings import warn
    15 from warnings import warn
    16 
    16 
    17 from logilab.common import STD_BLACKLIST
    17 from logilab.common import STD_BLACKLIST
    18 from logilab.common.modutils import get_module_files
    18 from logilab.common.modutils import get_module_files
    19 from logilab.common.textutils import get_csv
    19 from logilab.common.textutils import get_csv
       
    20 from logilab.common.shellutils import ASK
    20 from logilab.common.clcommands import register_commands
    21 from logilab.common.clcommands import register_commands
    21 
    22 
    22 from cubicweb import CW_SOFTWARE_ROOT as BASEDIR, BadCommandUsage, underline_title
    23 from cubicweb import CW_SOFTWARE_ROOT as BASEDIR, BadCommandUsage, underline_title
    23 from cubicweb.__pkginfo__ import version as cubicwebversion
    24 from cubicweb.__pkginfo__ import version as cubicwebversion
    24 from cubicweb.toolsutils import Command, confirm, copy_skeleton
    25 from cubicweb.toolsutils import Command, copy_skeleton
    25 from cubicweb.web.webconfig import WebConfiguration
    26 from cubicweb.web.webconfig import WebConfiguration
    26 from cubicweb.server.serverconfig import ServerConfiguration
    27 from cubicweb.server.serverconfig import ServerConfiguration
    27 
       
    28 
    28 
    29 class DevCubeConfiguration(ServerConfiguration, WebConfiguration):
    29 class DevCubeConfiguration(ServerConfiguration, WebConfiguration):
    30     """dummy config to get full library schema and entities"""
    30     """dummy config to get full library schema and entities"""
    31     creating = True
    31     creating = True
    32     cubicweb_vobject_path = ServerConfiguration.cubicweb_vobject_path | WebConfiguration.cubicweb_vobject_path
    32     cubicweb_vobject_path = ServerConfiguration.cubicweb_vobject_path | WebConfiguration.cubicweb_vobject_path
   481             if len(cubespath) > 1:
   481             if len(cubespath) > 1:
   482                 raise BadCommandUsage("can't guess directory where to put the new cube."
   482                 raise BadCommandUsage("can't guess directory where to put the new cube."
   483                                       " Please specify it using the --directory option")
   483                                       " Please specify it using the --directory option")
   484             cubesdir = cubespath[0]
   484             cubesdir = cubespath[0]
   485         if not isdir(cubesdir):
   485         if not isdir(cubesdir):
   486             print "creating cubes directory", cubesdir
   486             print "-> creating cubes directory", cubesdir
   487             try:
   487             try:
   488                 mkdir(cubesdir)
   488                 mkdir(cubesdir)
   489             except OSError, err:
   489             except OSError, err:
   490                 self.fail("failed to create directory %r\n(%s)" % (cubesdir, err))
   490                 self.fail("failed to create directory %r\n(%s)" % (cubesdir, err))
   491         cubedir = join(cubesdir, cubename)
   491         cubedir = join(cubesdir, cubename)
   492         if exists(cubedir):
   492         if exists(cubedir):
   493             self.fail("%s already exists !" % (cubedir))
   493             self.fail("%s already exists !" % (cubedir))
   494         skeldir = join(BASEDIR, 'skeleton')
   494         skeldir = join(BASEDIR, 'skeleton')
       
   495         default_name = 'cubicweb-%s' % cubename.lower()
   495         if verbose:
   496         if verbose:
   496             distname = raw_input('Debian name for your cube (just type enter to use the cube name): ').strip()
   497             distname = raw_input('Debian name for your cube ? [%s]): ' % default_name).strip()
   497             if not distname:
   498             if not distname:
   498                 distname = 'cubicweb-%s' % cubename.lower()
   499                 distname = default_name
   499             elif not distname.startswith('cubicweb-'):
   500             elif not distname.startswith('cubicweb-'):
   500                 if confirm('do you mean cubicweb-%s ?' % distname):
   501                 if ASK.confirm('Do you mean cubicweb-%s ?' % distname):
   501                     distname = 'cubicweb-' + distname
   502                     distname = 'cubicweb-' + distname
   502         else:
   503         else:
   503             distname = 'cubicweb-%s' % cubename.lower()
   504             distname = default_name
   504 
   505 
   505         longdesc = shortdesc = raw_input('Enter a short description for your cube: ')
   506         longdesc = shortdesc = raw_input('Enter a short description for your cube: ')
   506         if verbose:
   507         if verbose:
   507             longdesc = raw_input('Enter a long description (or nothing if you want to reuse the short one): ')
   508             longdesc = raw_input('Enter a long description (leave empty to reuse the short one): ')
   508         if verbose:
   509         if verbose:
   509             includes = self._ask_for_dependancies()
   510             includes = self._ask_for_dependancies()
   510             if len(includes) == 1:
   511             if len(includes) == 1:
   511                 dependancies = '%r,' % includes[0]
   512                 dependancies = '%r,' % includes[0]
   512             else:
   513             else:
   527         copy_skeleton(skeldir, cubedir, context)
   528         copy_skeleton(skeldir, cubedir, context)
   528 
   529 
   529     def _ask_for_dependancies(self):
   530     def _ask_for_dependancies(self):
   530         includes = []
   531         includes = []
   531         for stdtype in ServerConfiguration.available_cubes():
   532         for stdtype in ServerConfiguration.available_cubes():
   532             ans = raw_input("Depends on cube %s? (N/y/s(kip)/t(ype)"
   533             answer = ASK.ask("Depends on cube %s? " % stdtype,
   533                             % stdtype).lower().strip()
   534                              ('N','y','skip','type'), 'N')
   534             if ans == 'y':
   535             if answer == 'y':
   535                 includes.append(stdtype)
   536                 includes.append(stdtype)
   536             if ans == 't':
   537             if answer == 'type':
   537                 includes = get_csv(raw_input('type dependancies: '))
   538                 includes = get_csv(raw_input('type dependancies: '))
   538                 break
   539                 break
   539             elif ans == 's':
   540             elif answer == 'skip':
   540                 break
   541                 break
   541         return includes
   542         return includes
   542 
   543 
   543 
   544 
   544 class ExamineLogCommand(Command):
   545 class ExamineLogCommand(Command):