# HG changeset patch # User Pierre-Yves David # Date 1265131485 -3600 # Node ID 101344a6ff9b24c71a0cc0236ce7f8f70771cd80 # Parent e597e0ca67cd16a2569afad67be772e54101a9ca 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. diff -r e597e0ca67cd -r 101344a6ff9b devtools/devctl.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': '', 'short':'o', 'help':'output image file', 'input':False}), ('viewer', {'type': 'string', 'default':None, - 'short': "w", 'metavar':'', + 'short': "d", 'metavar':'', 'help':'command use to view the generated file (empty for none)'} ), + ('show-meta', {'action': 'store_true', 'default':False, + 'short': "m", 'metavar': "", + 'help':'include meta and internal entities in schema'} + ), + ('show-workflow', {'action': 'store_true', 'default':False, + 'short': "w", 'metavar': "", + 'help':'include workflow entities in schema'} + ), + ('show-cw-user', {'action': 'store_true', 'default':False, + 'metavar': "", + 'help':'include cubicweb user entities in schema'} + ), + ('exclude-type', {'type':'string', 'default':'', + 'short': "x", 'metavar': "", + 'help':'coma separated list of entity types to remove from view'} + ), + ('include-type', {'type':'string', 'default':'', + 'short': "i", 'metavar': "", + '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() diff -r e597e0ca67cd -r 101344a6ff9b schema.py --- 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 diff -r e597e0ca67cd -r 101344a6ff9b web/views/schema.py --- 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)):