[c-c newcube] #1192: simpler cubicweb-ctl newcube, and more
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 08 Apr 2010 11:04:17 +0200
changeset 5184 955ee1b24756
parent 5177 395e1ff018ae
child 5195 e8235b2789fc
[c-c newcube] #1192: simpler cubicweb-ctl newcube, and more * new --layout option, to get 'simple' or 'full' cube * new --licence option to specify license for the cube * added README and sobjects.py template (the later only added in full layout) * fixed python file templates to get proper headers according to the config
devtools/devctl.py
skeleton/README.tmpl
skeleton/__pkginfo__.py.tmpl
skeleton/data/cubes.CUBENAME.css
skeleton/data/cubes.CUBENAME.js
skeleton/entities.py
skeleton/entities.py.tmpl
skeleton/hooks.py.tmpl
skeleton/migration/postcreate.py
skeleton/migration/postcreate.py.tmpl
skeleton/migration/precreate.py
skeleton/migration/precreate.py.tmpl
skeleton/schema.py
skeleton/schema.py.tmpl
skeleton/setup.py
skeleton/sobjects.py.tmpl
skeleton/views.py
skeleton/views.py.tmpl
toolsutils.py
--- a/devtools/devctl.py	Wed Apr 07 14:42:55 2010 +0200
+++ b/devtools/devctl.py	Thu Apr 08 11:04:17 2010 +0200
@@ -22,7 +22,8 @@
 
 from cubicweb.__pkginfo__ import version as cubicwebversion
 from cubicweb import CW_SOFTWARE_ROOT as BASEDIR, BadCommandUsage
-from cubicweb.toolsutils import Command, copy_skeleton, underline_title
+from cubicweb.toolsutils import (SKEL_EXCLUDE, Command,
+                                 copy_skeleton, underline_title)
 from cubicweb.web.webconfig import WebConfiguration
 from cubicweb.server.serverconfig import ServerConfiguration
 
@@ -440,12 +441,19 @@
     """Create a new cube.
 
     <cubename>
-      the name of the new cube
+      the name of the new cube. It should be a valid python module name.
     """
     name = 'newcube'
     arguments = '<cubename>'
 
     options = (
+        ("layout",
+         {'short': 'L', 'type' : 'choice', 'metavar': '<cube layout>',
+          'default': 'simple', 'choices': ('simple', 'full'),
+          'help': 'cube layout. You\'ll get a minimal cube with the "simple" \
+layout, and a full featured cube with "full" layout.',
+          }
+         ),
         ("directory",
          {'short': 'd', 'type' : 'string', 'metavar': '<cubes directory>',
           'help': 'directory where the new cube should be created',
@@ -475,14 +483,28 @@
           'help': 'cube author\'s web site',
           }
          ),
+        ("license",
+         {'short': 'l', 'type' : 'choice', 'metavar': '<license>',
+          'default': 'LGPL', 'choices': ('GPL', 'LGPL', ''),
+          'help': 'cube license',
+          }
+         ),
         )
 
+    LICENSES = {
+        'LGPL': 'GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses',
+        'GPL': 'GNU General Public License, v2.1 - http://www.gnu.org/licenses',
+        '': 'closed source'
+        }
 
     def run(self, args):
+        import re
         from logilab.common.shellutils import ASK
         if len(args) != 1:
             raise BadCommandUsage("exactly one argument (cube name) is expected")
-        cubename, = args
+        cubename = args[0]
+        if not re.match('[_A-Za-z][_A-Za-z0-9]*$', cubename):
+            raise BadCommandUsage("cube name should be a valid python module name")
         verbose = self.get('verbose')
         cubesdir = self.get('directory')
         if not cubesdir:
@@ -533,8 +555,14 @@
                    'author': self['author'],
                    'author-email': self['author-email'],
                    'author-web-site': self['author-web-site'],
+                   'license': self['license'],
+                   'long-license': self.LICENSES[self['license']],
                    }
-        copy_skeleton(skeldir, cubedir, context)
+        exclude = SKEL_EXCLUDE
+        if self['layout'] == 'simple':
+            exclude += ('sobjects.py*', 'precreate.py*', 'realdb_test*',
+                        'cubes.*', 'external_resources*')
+        copy_skeleton(skeldir, cubedir, context, exclude=exclude)
 
     def _ask_for_dependancies(self):
         from logilab.common.shellutils import ASK
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/skeleton/README.tmpl	Thu Apr 08 11:04:17 2010 +0200
@@ -0,0 +1,3 @@
+Summary
+-------
+%(longdesc)s
--- a/skeleton/__pkginfo__.py.tmpl	Wed Apr 07 14:42:55 2010 +0200
+++ b/skeleton/__pkginfo__.py.tmpl	Thu Apr 08 11:04:17 2010 +0200
@@ -7,7 +7,7 @@
 numversion = (0, 1, 0)
 version = '.'.join(str(num) for num in numversion)
 
-license = 'LCL'
+license = '%(license)s'
 
 author = '%(author)s'
 author_email = '%(author-email)s'
@@ -40,6 +40,6 @@
 # Note: here, you'll need to add subdirectories if you want
 # them to be included in the debian package
 
-__depends__ = {'cubicweb': '>= 3.8.0'}
+__depends__ = {'cubicweb': '>= %(version)s'}
 __recommends__ = {}
 
--- a/skeleton/data/cubes.CUBENAME.css	Wed Apr 07 14:42:55 2010 +0200
+++ b/skeleton/data/cubes.CUBENAME.css	Thu Apr 08 11:04:17 2010 +0200
@@ -1,1 +1,1 @@
-/* template specific CSS */
+/* cube-specific CSS */
--- a/skeleton/data/cubes.CUBENAME.js	Wed Apr 07 14:42:55 2010 +0200
+++ b/skeleton/data/cubes.CUBENAME.js	Thu Apr 08 11:04:17 2010 +0200
@@ -1,1 +1,1 @@
-// This contains template-specific javascript
\ No newline at end of file
+// This contains cube-specific javascript
\ No newline at end of file
--- a/skeleton/entities.py	Wed Apr 07 14:42:55 2010 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,7 +0,0 @@
-"""this contains the cube-specific entities' classes
-
-:organization: Logilab
-:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
-:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
-:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
-"""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/skeleton/entities.py.tmpl	Thu Apr 08 11:04:17 2010 +0200
@@ -0,0 +1,7 @@
+"""%(distname)s entity's classes
+
+:organization: %(author)s
+:copyright: %(year)s %(author)s
+:contact: %(author-web-site)s -- mailto:%(author-email)s
+:license: %(long-license)s
+"""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/skeleton/hooks.py.tmpl	Thu Apr 08 11:04:17 2010 +0200
@@ -0,0 +1,7 @@
+"""%(distname)s specific hooks and operations
+
+:organization: %(author)s
+:copyright: %(year)s %(author)s
+:contact: %(author-web-site)s -- mailto:%(author-email)s
+:license: %(long-license)s
+"""
--- a/skeleton/migration/postcreate.py	Wed Apr 07 14:42:55 2010 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,12 +0,0 @@
-# postcreate script. You could setup site properties or a workflow here for example
-"""
-
-:organization: Logilab
-:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
-:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
-:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
-"""
-
-# Example of site property change
-#set_property('ui.site-title', "<sitename>")
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/skeleton/migration/postcreate.py.tmpl	Thu Apr 08 11:04:17 2010 +0200
@@ -0,0 +1,14 @@
+"""%(distname)s postcreate script, executed at instance creation time or when
+the cube is added to an existing instance.
+
+You could setup site properties or a workflow here for example.
+
+:organization: %(author)s
+:copyright: %(year)s %(author)s
+:contact: %(author-web-site)s -- mailto:%(author-email)s
+:license: %(long-license)s
+"""
+
+# Example of site property change
+#set_property('ui.site-title', "<sitename>")
+
--- a/skeleton/migration/precreate.py	Wed Apr 07 14:42:55 2010 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-# Instructions here will be read before reading the schema
-"""
-
-:organization: Logilab
-:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
-:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
-:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
-"""
-# You could create your own groups here, like in :
-#   create_entity('CWGroup', name=u'mygroup')
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/skeleton/migration/precreate.py.tmpl	Thu Apr 08 11:04:17 2010 +0200
@@ -0,0 +1,10 @@
+"""%(distname)s precreate script, executed at instance creation time or when
+the cube is added to an existing instance, before the schema is serialized.
+
+This is typically to create groups referenced by the cube'schema.
+
+:organization: %(author)s
+:copyright: %(year)s %(author)s
+:contact: %(author-web-site)s -- mailto:%(author-email)s
+:license: %(long-license)s
+"""
--- a/skeleton/schema.py	Wed Apr 07 14:42:55 2010 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,8 +0,0 @@
-# cube's specific schema
-"""
-
-:organization: Logilab
-:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
-:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
-:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
-"""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/skeleton/schema.py.tmpl	Thu Apr 08 11:04:17 2010 +0200
@@ -0,0 +1,7 @@
+"""%(distname)s schema
+
+:organization: %(author)s
+:copyright: %(year)s %(author)s
+:contact: %(author-web-site)s -- mailto:%(author-email)s
+:license: %(long-license)s
+"""
--- a/skeleton/setup.py	Wed Apr 07 14:42:55 2010 +0200
+++ b/skeleton/setup.py	Thu Apr 08 11:04:17 2010 +0200
@@ -43,6 +43,8 @@
 
 if exists('README'):
    long_description = file('README').read()
+else:
+   long_description = ''
 
 # import optional features
 import __pkginfo__
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/skeleton/sobjects.py.tmpl	Thu Apr 08 11:04:17 2010 +0200
@@ -0,0 +1,7 @@
+"""%(distname)s repository side views, usually for notification
+
+:organization: %(author)s
+:copyright: %(year)s %(author)s
+:contact: %(author-web-site)s -- mailto:%(author-email)s
+:license: %(long-license)s
+"""
--- a/skeleton/views.py	Wed Apr 07 14:42:55 2010 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,7 +0,0 @@
-"""cube-specific forms/views/actions/components
-
-:organization: Logilab
-:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
-:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
-:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
-"""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/skeleton/views.py.tmpl	Thu Apr 08 11:04:17 2010 +0200
@@ -0,0 +1,7 @@
+"""%(distname)s views/forms/actions/components for web ui
+
+:organization: %(author)s
+:copyright: %(year)s %(author)s
+:contact: %(author-web-site)s -- mailto:%(author-email)s
+:license: %(long-license)s
+"""
--- a/toolsutils.py	Wed Apr 07 14:42:55 2010 +0200
+++ b/toolsutils.py	Thu Apr 08 11:04:17 2010 +0200
@@ -103,10 +103,9 @@
     else:
         print 'no diff between %s and %s' % (appl_file, ref_file)
 
-
+SKEL_EXCLUDE = ('*.py[co]', '*.orig', '*~', '*_flymake.py')
 def copy_skeleton(skeldir, targetdir, context,
-                  exclude=('*.py[co]', '*.orig', '*~', '*_flymake.py'),
-                  askconfirm=False):
+                  exclude=SKEL_EXCLUDE, askconfirm=False):
     import shutil
     from fnmatch import fnmatch
     skeldir = normpath(skeldir)