29 from cubicweb import CW_SOFTWARE_ROOT as BASEDIR, BadCommandUsage |
29 from cubicweb import CW_SOFTWARE_ROOT as BASEDIR, BadCommandUsage |
30 from cubicweb.toolsutils import Command, copy_skeleton, underline_title |
30 from cubicweb.toolsutils import Command, copy_skeleton, underline_title |
31 from cubicweb.schema import CONSTRAINTS |
31 from cubicweb.schema import CONSTRAINTS |
32 from cubicweb.web.webconfig import WebConfiguration |
32 from cubicweb.web.webconfig import WebConfiguration |
33 from cubicweb.server.serverconfig import ServerConfiguration |
33 from cubicweb.server.serverconfig import ServerConfiguration |
|
34 from yams import BASE_TYPES |
|
35 from cubicweb.schema import (META_RTYPES, SCHEMA_TYPES, SYSTEM_RTYPES, |
|
36 WORKFLOW_TYPES, INTERNAL_TYPES) |
34 |
37 |
35 |
38 |
36 class DevCubeConfiguration(ServerConfiguration, WebConfiguration): |
39 class DevCubeConfiguration(ServerConfiguration, WebConfiguration): |
37 """dummy config to get full library schema and entities""" |
40 """dummy config to get full library schema and entities""" |
38 creating = True |
41 creating = True |
626 arguments = '<cube>' |
629 arguments = '<cube>' |
627 options = [('output-file', {'type':'file', 'default': None, |
630 options = [('output-file', {'type':'file', 'default': None, |
628 'metavar': '<file>', 'short':'o', 'help':'output image file', |
631 'metavar': '<file>', 'short':'o', 'help':'output image file', |
629 'input':False}), |
632 'input':False}), |
630 ('viewer', {'type': 'string', 'default':None, |
633 ('viewer', {'type': 'string', 'default':None, |
631 'short': "w", 'metavar':'<cmd>', |
634 'short': "d", 'metavar':'<cmd>', |
632 'help':'command use to view the generated file (empty for none)'} |
635 'help':'command use to view the generated file (empty for none)'} |
|
636 ), |
|
637 ('show-meta', {'action': 'store_true', 'default':False, |
|
638 'short': "m", 'metavar': "<yN>", |
|
639 'help':'include meta and internal entities in schema'} |
|
640 ), |
|
641 ('show-workflow', {'action': 'store_true', 'default':False, |
|
642 'short': "w", 'metavar': "<yN>", |
|
643 'help':'include workflow entities in schema'} |
|
644 ), |
|
645 ('show-cw-user', {'action': 'store_true', 'default':False, |
|
646 'metavar': "<yN>", |
|
647 'help':'include cubicweb user entities in schema'} |
|
648 ), |
|
649 ('exclude-type', {'type':'string', 'default':'', |
|
650 'short': "x", 'metavar': "<types>", |
|
651 'help':'coma separated list of entity types to remove from view'} |
|
652 ), |
|
653 ('include-type', {'type':'string', 'default':'', |
|
654 'short': "i", 'metavar': "<types>", |
|
655 'help':'coma separated list of entity types to include in view'} |
633 ), |
656 ), |
634 ] |
657 ] |
635 |
658 |
636 def run(self, args): |
659 def run(self, args): |
637 from logilab.common.textutils import splitstrip |
660 from logilab.common.textutils import splitstrip |
643 |
666 |
644 out, viewer = self['output-file'], self['viewer'] |
667 out, viewer = self['output-file'], self['viewer'] |
645 if out is None: |
668 if out is None: |
646 tmp_file = NamedTemporaryFile(suffix=".svg") |
669 tmp_file = NamedTemporaryFile(suffix=".svg") |
647 out = tmp_file.name |
670 out = tmp_file.name |
648 schema2dot.schema2dot(schema, out, |
671 |
649 #skiptypes=("identity",) |
672 skiptypes = BASE_TYPES | SCHEMA_TYPES |
650 ) |
673 if not self['show-meta']: |
|
674 skiptypes |= META_RTYPES | SYSTEM_RTYPES | INTERNAL_TYPES |
|
675 if not self['show-workflow']: |
|
676 skiptypes |= WORKFLOW_TYPES |
|
677 if not self['show-cw-user']: |
|
678 skiptypes |= set(('CWUser', 'CWGroup', 'EmailAddress')) |
|
679 skiptypes |= set(self['exclude-type'].split(',')) |
|
680 skiptypes -= set(self['include-type'].split(',')) |
|
681 |
|
682 schema2dot.schema2dot(schema, out, skiptypes=skiptypes) |
|
683 |
651 if viewer: |
684 if viewer: |
652 p = Popen((viewer, out)) |
685 p = Popen((viewer, out)) |
653 p.wait() |
686 p.wait() |
654 |
687 |
655 register_commands((UpdateCubicWebCatalogCommand, |
688 register_commands((UpdateCubicWebCatalogCommand, |