Improve the schema command with filtering option.
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Tue, 02 Feb 2010 18:24:45 +0100
changeset 4434 101344a6ff9b
parent 4431 e597e0ca67cd
child 4436 294e084f1263
Improve the schema command with filtering option. meta data and workflow data are hidden by default. show-meta and show-workflow option are added to display them. Another "hide-type" option allow to hide additional entities type.
devtools/devctl.py
schema.py
web/views/schema.py
--- a/devtools/devctl.py	Wed Feb 03 09:21:47 2010 +0100
+++ b/devtools/devctl.py	Tue Feb 02 18:24:45 2010 +0100
@@ -31,6 +31,9 @@
 from cubicweb.schema import CONSTRAINTS
 from cubicweb.web.webconfig import WebConfiguration
 from cubicweb.server.serverconfig import ServerConfiguration
+from yams import BASE_TYPES
+from cubicweb.schema import (META_RTYPES, SCHEMA_TYPES, SYSTEM_RTYPES,
+                             WORKFLOW_TYPES, INTERNAL_TYPES)
 
 
 class DevCubeConfiguration(ServerConfiguration, WebConfiguration):
@@ -628,9 +631,29 @@
                  'metavar': '<file>', 'short':'o', 'help':'output image file',
                  'input':False}),
                ('viewer', {'type': 'string', 'default':None,
-                'short': "w", 'metavar':'<cmd>',
+                'short': "d", 'metavar':'<cmd>',
                  'help':'command use to view the generated file (empty for none)'}
                ),
+               ('show-meta', {'action': 'store_true', 'default':False,
+                'short': "m", 'metavar': "<yN>",
+                 'help':'include meta and internal entities in schema'}
+               ),
+               ('show-workflow', {'action': 'store_true', 'default':False,
+                'short': "w", 'metavar': "<yN>",
+                'help':'include workflow entities in schema'}
+               ),
+               ('show-cw-user', {'action': 'store_true', 'default':False,
+                'metavar': "<yN>",
+                'help':'include cubicweb user entities in schema'}
+               ),
+               ('exclude-type', {'type':'string', 'default':'',
+                'short': "x", 'metavar': "<types>",
+                 'help':'coma separated list of entity types to remove from view'}
+               ),
+               ('include-type', {'type':'string', 'default':'',
+                'short': "i", 'metavar': "<types>",
+                 'help':'coma separated list of entity types to include in view'}
+               ),
               ]
 
     def run(self, args):
@@ -645,9 +668,19 @@
         if out is None:
             tmp_file = NamedTemporaryFile(suffix=".svg")
             out = tmp_file.name
-        schema2dot.schema2dot(schema, out,
-            #skiptypes=("identity",)
-            )
+
+        skiptypes = BASE_TYPES | SCHEMA_TYPES
+        if not self['show-meta']:
+            skiptypes |=  META_RTYPES | SYSTEM_RTYPES | INTERNAL_TYPES
+        if not self['show-workflow']:
+            skiptypes |= WORKFLOW_TYPES
+        if not self['show-cw-user']:
+            skiptypes |= set(('CWUser', 'CWGroup', 'EmailAddress'))
+        skiptypes |= set(self['exclude-type'].split(','))
+        skiptypes -= set(self['include-type'].split(','))
+
+        schema2dot.schema2dot(schema, out, skiptypes=skiptypes)
+
         if viewer:
             p = Popen((viewer, out))
             p.wait()
--- a/schema.py	Wed Feb 03 09:21:47 2010 +0100
+++ b/schema.py	Tue Feb 02 18:24:45 2010 +0100
@@ -55,6 +55,12 @@
     'constrained_by', 'cstrtype',
     ))
 
+WORKFLOW_TYPES = set(('Transition', 'State', 'TrInfo', 'Workflow',
+                         'WorkflowTransition', 'BaseTransition',
+                         'SubWorkflowExitPoint'))
+INTERNAL_TYPES = set(('CWProperty', 'CWPermission', 'CWCache', 'ExternalUri'))
+
+
 _LOGGER = getLogger('cubicweb.schemaloader')
 
 # schema entities created from serialized schema have an eid rproperty
--- a/web/views/schema.py	Wed Feb 03 09:21:47 2010 +0100
+++ b/web/views/schema.py	Tue Feb 02 18:24:45 2010 +0100
@@ -14,7 +14,8 @@
 
 from cubicweb.selectors import (implements, yes, match_user_groups,
                                 has_related_entities)
-from cubicweb.schema import META_RTYPES, SCHEMA_TYPES, SYSTEM_RTYPES
+from cubicweb.schema import (META_RTYPES, SCHEMA_TYPES, SYSTEM_RTYPES,
+                             WORKFLOW_TYPES, INTERNAL_TYPES)
 from cubicweb.schemaviewer import SchemaViewer
 from cubicweb.view import EntityView, StartupView
 from cubicweb import tags, uilib
@@ -23,13 +24,9 @@
 from cubicweb.web.views import primary, baseviews, tabs, management
 
 ALWAYS_SKIP_TYPES = BASE_TYPES | SCHEMA_TYPES
-SKIP_TYPES = ALWAYS_SKIP_TYPES | META_RTYPES | SYSTEM_RTYPES
-SKIP_TYPES.update(set(('Transition', 'State', 'TrInfo', 'Workflow',
-                       'WorkflowTransition', 'BaseTransition',
-                       'SubWorkflowExitPoint',
-                       'CWUser', 'CWGroup',
-                       'CWCache', 'CWProperty', 'CWPermission',
-                       'ExternalUri')))
+SKIP_TYPES  = (ALWAYS_SKIP_TYPES | META_RTYPES | SYSTEM_RTYPES | WORKFLOW_TYPES
+               INTERNAL_TYPES)
+SKIP_TYPES.update(set(('CWUser', 'CWGroup')))
 
 def skip_types(req):
     if int(req.form.get('skipmeta', True)):