devtools/devctl.py
changeset 5184 955ee1b24756
parent 4722 9c13d5db03d9
child 5297 cc747dcef851
equal deleted inserted replaced
5177:395e1ff018ae 5184:955ee1b24756
    20 from logilab.common import STD_BLACKLIST
    20 from logilab.common import STD_BLACKLIST
    21 from logilab.common.clcommands import register_commands, pop_arg
    21 from logilab.common.clcommands import register_commands, pop_arg
    22 
    22 
    23 from cubicweb.__pkginfo__ import version as cubicwebversion
    23 from cubicweb.__pkginfo__ import version as cubicwebversion
    24 from cubicweb import CW_SOFTWARE_ROOT as BASEDIR, BadCommandUsage
    24 from cubicweb import CW_SOFTWARE_ROOT as BASEDIR, BadCommandUsage
    25 from cubicweb.toolsutils import Command, copy_skeleton, underline_title
    25 from cubicweb.toolsutils import (SKEL_EXCLUDE, Command,
       
    26                                  copy_skeleton, underline_title)
    26 from cubicweb.web.webconfig import WebConfiguration
    27 from cubicweb.web.webconfig import WebConfiguration
    27 from cubicweb.server.serverconfig import ServerConfiguration
    28 from cubicweb.server.serverconfig import ServerConfiguration
    28 
    29 
    29 
    30 
    30 class DevConfiguration(ServerConfiguration, WebConfiguration):
    31 class DevConfiguration(ServerConfiguration, WebConfiguration):
   438 
   439 
   439 class NewCubeCommand(Command):
   440 class NewCubeCommand(Command):
   440     """Create a new cube.
   441     """Create a new cube.
   441 
   442 
   442     <cubename>
   443     <cubename>
   443       the name of the new cube
   444       the name of the new cube. It should be a valid python module name.
   444     """
   445     """
   445     name = 'newcube'
   446     name = 'newcube'
   446     arguments = '<cubename>'
   447     arguments = '<cubename>'
   447 
   448 
   448     options = (
   449     options = (
       
   450         ("layout",
       
   451          {'short': 'L', 'type' : 'choice', 'metavar': '<cube layout>',
       
   452           'default': 'simple', 'choices': ('simple', 'full'),
       
   453           'help': 'cube layout. You\'ll get a minimal cube with the "simple" \
       
   454 layout, and a full featured cube with "full" layout.',
       
   455           }
       
   456          ),
   449         ("directory",
   457         ("directory",
   450          {'short': 'd', 'type' : 'string', 'metavar': '<cubes directory>',
   458          {'short': 'd', 'type' : 'string', 'metavar': '<cubes directory>',
   451           'help': 'directory where the new cube should be created',
   459           'help': 'directory where the new cube should be created',
   452           }
   460           }
   453          ),
   461          ),
   473          {'short': 'w', 'type' : 'string', 'metavar': '<web site>',
   481          {'short': 'w', 'type' : 'string', 'metavar': '<web site>',
   474           'default': 'http://www.logilab.fr',
   482           'default': 'http://www.logilab.fr',
   475           'help': 'cube author\'s web site',
   483           'help': 'cube author\'s web site',
   476           }
   484           }
   477          ),
   485          ),
       
   486         ("license",
       
   487          {'short': 'l', 'type' : 'choice', 'metavar': '<license>',
       
   488           'default': 'LGPL', 'choices': ('GPL', 'LGPL', ''),
       
   489           'help': 'cube license',
       
   490           }
       
   491          ),
   478         )
   492         )
   479 
   493 
       
   494     LICENSES = {
       
   495         'LGPL': 'GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses',
       
   496         'GPL': 'GNU General Public License, v2.1 - http://www.gnu.org/licenses',
       
   497         '': 'closed source'
       
   498         }
   480 
   499 
   481     def run(self, args):
   500     def run(self, args):
       
   501         import re
   482         from logilab.common.shellutils import ASK
   502         from logilab.common.shellutils import ASK
   483         if len(args) != 1:
   503         if len(args) != 1:
   484             raise BadCommandUsage("exactly one argument (cube name) is expected")
   504             raise BadCommandUsage("exactly one argument (cube name) is expected")
   485         cubename, = args
   505         cubename = args[0]
       
   506         if not re.match('[_A-Za-z][_A-Za-z0-9]*$', cubename):
       
   507             raise BadCommandUsage("cube name should be a valid python module name")
   486         verbose = self.get('verbose')
   508         verbose = self.get('verbose')
   487         cubesdir = self.get('directory')
   509         cubesdir = self.get('directory')
   488         if not cubesdir:
   510         if not cubesdir:
   489             cubespath = ServerConfiguration.cubes_search_path()
   511             cubespath = ServerConfiguration.cubes_search_path()
   490             if len(cubespath) > 1:
   512             if len(cubespath) > 1:
   531                    'version'  : cubicwebversion,
   553                    'version'  : cubicwebversion,
   532                    'year'  : str(datetime.now().year),
   554                    'year'  : str(datetime.now().year),
   533                    'author': self['author'],
   555                    'author': self['author'],
   534                    'author-email': self['author-email'],
   556                    'author-email': self['author-email'],
   535                    'author-web-site': self['author-web-site'],
   557                    'author-web-site': self['author-web-site'],
       
   558                    'license': self['license'],
       
   559                    'long-license': self.LICENSES[self['license']],
   536                    }
   560                    }
   537         copy_skeleton(skeldir, cubedir, context)
   561         exclude = SKEL_EXCLUDE
       
   562         if self['layout'] == 'simple':
       
   563             exclude += ('sobjects.py*', 'precreate.py*', 'realdb_test*',
       
   564                         'cubes.*', 'external_resources*')
       
   565         copy_skeleton(skeldir, cubedir, context, exclude=exclude)
   538 
   566 
   539     def _ask_for_dependancies(self):
   567     def _ask_for_dependancies(self):
   540         from logilab.common.shellutils import ASK
   568         from logilab.common.shellutils import ASK
   541         from logilab.common.textutils import splitstrip
   569         from logilab.common.textutils import splitstrip
   542         includes = []
   570         includes = []