devtools/devctl.py
changeset 145 d5acef862c58
parent 133 6ad5e7eb06ff
child 155 9ed6db94a087
equal deleted inserted replaced
144:3159772915c4 145:d5acef862c58
   360         """run the command with its specific arguments"""
   360         """run the command with its specific arguments"""
   361         from cubicweb.devtools.livetest import runserver
   361         from cubicweb.devtools.livetest import runserver
   362         runserver()
   362         runserver()
   363 
   363 
   364 
   364 
   365 class NewTemplateCommand(Command):
   365 class NewCubeCommand(Command):
   366     """Create a new cube.
   366     """Create a new cube.
   367 
   367 
   368     <cubename>
   368     <cubename>
   369       the name of the new cube
   369       the name of the new cube
   370     """
   370     """
   371     name = 'newcube'
   371     name = 'newcube'
   372     arguments = '<cubename>'
   372     arguments = '<cubename>'
       
   373 
       
   374     options = (
       
   375         ("verbose",
       
   376          {'short': 'v', 'type' : 'yn', 'metavar': '<verbose>',
       
   377           'default': 'n',
       
   378           'help': 'verbose mode: will ask all possible configuration questions',
       
   379           }
       
   380          ),
       
   381         )
   373 
   382 
   374     
   383     
   375     def run(self, args):
   384     def run(self, args):
   376         if len(args) != 1:
   385         if len(args) != 1:
   377             raise BadCommandUsage("exactly one argument (cube name) is expected")
   386             raise BadCommandUsage("exactly one argument (cube name) is expected")
   378         cubename, = args
   387         cubename, = args
   379         if ServerConfiguration.mode != "dev":
   388         if ServerConfiguration.mode != "dev":
   380             self.fail("you can only create new cubes in development mode")
   389             self.fail("you can only create new cubes in development mode")
       
   390         verbose = self.get('verbose')
   381         cubedir = ServerConfiguration.CUBES_DIR
   391         cubedir = ServerConfiguration.CUBES_DIR
   382         if not isdir(cubedir):
   392         if not isdir(cubedir):
   383             print "creating apps directory", cubedir
   393             print "creating apps directory", cubedir
   384             try:
   394             try:
   385                 mkdir(cubedir)
   395                 mkdir(cubedir)
   387                 self.fail("failed to create directory %r\n(%s)" % (cubedir, err))
   397                 self.fail("failed to create directory %r\n(%s)" % (cubedir, err))
   388         cubedir = join(cubedir, cubename)
   398         cubedir = join(cubedir, cubename)
   389         if exists(cubedir):
   399         if exists(cubedir):
   390             self.fail("%s already exists !" % (cubedir))
   400             self.fail("%s already exists !" % (cubedir))
   391         skeldir = join(BASEDIR, 'skeleton')
   401         skeldir = join(BASEDIR, 'skeleton')
   392         distname = raw_input('Debian name for your cube (just type enter to use the cube name): ').strip()
   402         if verbose:
   393         if not distname:
   403             distname = raw_input('Debian name for your cube (just type enter to use the cube name): ').strip()
       
   404             if not distname:
       
   405                 distname = 'cubicweb-%s' % cubename.lower()
       
   406             elif not distname.startswith('cubicweb-'):
       
   407                 if confirm('do you mean cubicweb-%s ?' % distname):
       
   408                     distname = 'cubicweb-' + distname
       
   409         else:
   394             distname = 'cubicweb-%s' % cubename.lower()
   410             distname = 'cubicweb-%s' % cubename.lower()
   395         elif not distname.startswith('cubicweb-'):
   411         
   396             if confirm('do you mean cubicweb-%s ?' % distname):
   412         longdesc = shortdesc = raw_input('Enter a short description for your cube: ')
   397                 distname = 'cubicweb-' + distname
   413         if verbose:
   398         shortdesc = raw_input('Enter a short description for your cube: ')
   414             longdesc = raw_input('Enter a long description (or nothing if you want to reuse the short one): ')
   399         longdesc = raw_input('Enter a long description (or nothing if you want to reuse the short one): ')
   415         if verbose:
   400         includes = self._ask_for_dependancies()
   416             includes = self._ask_for_dependancies()
   401         if len(includes) == 1:
   417             if len(includes) == 1:
   402             dependancies = '%r,' % includes[0]
   418                 dependancies = '%r,' % includes[0]
       
   419             else:
       
   420                 dependancies = ', '.join(repr(cube) for cube in includes)
   403         else:
   421         else:
   404             dependancies = ', '.join(repr(cube) for cube in includes)
   422             dependancies = ''
   405         from mx.DateTime import now
   423         from mx.DateTime import now
   406         context = {'cubename' : cubename,
   424         context = {'cubename' : cubename,
   407                    'distname' : distname,
   425                    'distname' : distname,
   408                    'shortdesc' : shortdesc,
   426                    'shortdesc' : shortdesc,
   409                    'longdesc' : longdesc or shortdesc,
   427                    'longdesc' : longdesc or shortdesc,
   429     
   447     
   430         
   448         
   431 register_commands((UpdateCubicWebCatalogCommand,
   449 register_commands((UpdateCubicWebCatalogCommand,
   432                    UpdateTemplateCatalogCommand,
   450                    UpdateTemplateCatalogCommand,
   433                    LiveServerCommand,
   451                    LiveServerCommand,
   434                    NewTemplateCommand,
   452                    NewCubeCommand,
   435                    ))
   453                    ))