12 from datetime import datetime |
12 from datetime import datetime |
13 from os import mkdir, chdir, getcwd |
13 from os import mkdir, chdir, getcwd |
14 from os.path import join, exists, abspath, basename, normpath, split, isdir |
14 from os.path import join, exists, abspath, basename, normpath, split, isdir |
15 from copy import deepcopy |
15 from copy import deepcopy |
16 from warnings import warn |
16 from warnings import warn |
|
17 from tempfile import NamedTemporaryFile |
|
18 from subprocess import Popen |
17 |
19 |
18 from logilab.common import STD_BLACKLIST |
20 from logilab.common import STD_BLACKLIST |
19 from logilab.common.modutils import get_module_files |
21 from logilab.common.modutils import get_module_files |
20 from logilab.common.textutils import splitstrip |
22 from logilab.common.textutils import splitstrip |
21 from logilab.common.shellutils import ASK |
23 from logilab.common.shellutils import ASK |
22 from logilab.common.clcommands import register_commands |
24 from logilab.common.clcommands import register_commands, pop_arg |
|
25 |
|
26 from yams import schema2dot |
23 |
27 |
24 from cubicweb.__pkginfo__ import version as cubicwebversion |
28 from cubicweb.__pkginfo__ import version as cubicwebversion |
25 from cubicweb import CW_SOFTWARE_ROOT as BASEDIR, BadCommandUsage |
29 from cubicweb import CW_SOFTWARE_ROOT as BASEDIR, BadCommandUsage |
26 from cubicweb.toolsutils import Command, copy_skeleton, underline_title |
30 from cubicweb.toolsutils import Command, copy_skeleton, underline_title |
27 from cubicweb.schema import CONSTRAINTS |
31 from cubicweb.schema import CONSTRAINTS |
33 """dummy config to get full library schema and entities""" |
37 """dummy config to get full library schema and entities""" |
34 creating = True |
38 creating = True |
35 cubicweb_appobject_path = ServerConfiguration.cubicweb_appobject_path | WebConfiguration.cubicweb_appobject_path |
39 cubicweb_appobject_path = ServerConfiguration.cubicweb_appobject_path | WebConfiguration.cubicweb_appobject_path |
36 cube_appobject_path = ServerConfiguration.cube_appobject_path | WebConfiguration.cube_appobject_path |
40 cube_appobject_path = ServerConfiguration.cube_appobject_path | WebConfiguration.cube_appobject_path |
37 |
41 |
38 def __init__(self, cube): |
42 def __init__(self, *cubes): |
39 super(DevCubeConfiguration, self).__init__(cube) |
43 super(DevCubeConfiguration, self).__init__(cubes[0]) |
40 if cube is None: |
44 self._cubes = self.reorder_cubes(self.expand_cubes(cubes, |
41 self._cubes = () |
45 with_recommends=True)) |
42 else: |
|
43 self._cubes = self.reorder_cubes(self.expand_cubes(self.my_cubes(cube))) |
|
44 |
|
45 def my_cubes(self, cube): |
|
46 return (cube,) + self.cube_dependencies(cube) + self.cube_recommends(cube) |
|
47 |
46 |
48 @property |
47 @property |
49 def apphome(self): |
48 def apphome(self): |
50 return None |
49 return None |
51 def main_config_file(self): |
50 def main_config_file(self): |
58 |
57 |
59 class DevDepConfiguration(DevCubeConfiguration): |
58 class DevDepConfiguration(DevCubeConfiguration): |
60 """configuration to use to generate cubicweb po files or to use as "library" configuration |
59 """configuration to use to generate cubicweb po files or to use as "library" configuration |
61 to filter out message ids from cubicweb and dependencies of a cube |
60 to filter out message ids from cubicweb and dependencies of a cube |
62 """ |
61 """ |
63 |
|
64 def my_cubes(self, cube): |
|
65 return self.cube_dependencies(cube) + self.cube_recommends(cube) |
|
66 |
62 |
67 def default_log_file(self): |
63 def default_log_file(self): |
68 return None |
64 return None |
69 |
65 |
70 |
66 |
622 total_time = sum(clocktime for clocktime, cputime, occ, rql in stat)*0.01 |
618 total_time = sum(clocktime for clocktime, cputime, occ, rql in stat)*0.01 |
623 print 'Percentage;Cumulative Time (clock);Cumulative Time (CPU);Occurences;Query' |
619 print 'Percentage;Cumulative Time (clock);Cumulative Time (CPU);Occurences;Query' |
624 for clocktime, cputime, occ, rql in stat: |
620 for clocktime, cputime, occ, rql in stat: |
625 print '%.2f;%.2f;%.2f;%s;%s' % (clocktime/total_time, clocktime, cputime, occ, rql) |
621 print '%.2f;%.2f;%.2f;%s;%s' % (clocktime/total_time, clocktime, cputime, occ, rql) |
626 |
622 |
|
623 class GenerateSchema(Command): |
|
624 """Generate schema image for the given cube""" |
|
625 name = "schema" |
|
626 arguments = '<cube>' |
|
627 options = [('output-file', {'type':'file', 'default': None, |
|
628 'metavar': '<file>', 'short':'o', 'help':'output image file', |
|
629 'input':False}), |
|
630 ('viewer', {'type': 'string', 'default':None, |
|
631 'short': "w", 'metavar':'<cmd>', |
|
632 'help':'command use to view the generated file (empty for none)'} |
|
633 ), |
|
634 ] |
|
635 |
|
636 def run(self, args): |
|
637 from logilab.common.textutils import splitstrip |
|
638 cubes = splitstrip(pop_arg(args, 1)) |
|
639 |
|
640 dev_conf = DevCubeConfiguration(*cubes) |
|
641 schema = dev_conf.load_schema() |
|
642 |
|
643 |
|
644 out, viewer = self['output-file'], self['viewer'] |
|
645 if out is None: |
|
646 tmp_file = NamedTemporaryFile(suffix=".svg") |
|
647 out = tmp_file.name |
|
648 schema2dot.schema2dot(schema, out, |
|
649 #skiptypes=("identity",) |
|
650 ) |
|
651 if viewer: |
|
652 p = Popen((viewer, out)) |
|
653 p.wait() |
|
654 |
627 register_commands((UpdateCubicWebCatalogCommand, |
655 register_commands((UpdateCubicWebCatalogCommand, |
628 UpdateTemplateCatalogCommand, |
656 UpdateTemplateCatalogCommand, |
629 LiveServerCommand, |
657 LiveServerCommand, |
630 NewCubeCommand, |
658 NewCubeCommand, |
631 ExamineLogCommand, |
659 ExamineLogCommand, |
|
660 GenerateSchema, |
632 )) |
661 )) |