devtools/devctl.py
changeset 4479 f25e61a93c42
parent 4467 0e73d299730a
child 4708 2bd3d03721f3
equal deleted inserted replaced
4478:442fd69ff13b 4479:f25e61a93c42
    34 from yams import BASE_TYPES
    34 from yams import BASE_TYPES
    35 from cubicweb.schema import (META_RTYPES, SCHEMA_TYPES, SYSTEM_RTYPES,
    35 from cubicweb.schema import (META_RTYPES, SCHEMA_TYPES, SYSTEM_RTYPES,
    36                              WORKFLOW_TYPES, INTERNAL_TYPES)
    36                              WORKFLOW_TYPES, INTERNAL_TYPES)
    37 
    37 
    38 
    38 
    39 class DevCubeConfiguration(ServerConfiguration, WebConfiguration):
    39 class DevConfiguration(ServerConfiguration, WebConfiguration):
    40     """dummy config to get full library schema and entities"""
    40     """dummy config to get full library schema and appobjects for
       
    41     a cube or for cubicweb (without a home)
       
    42     """
    41     creating = True
    43     creating = True
    42     cubicweb_appobject_path = ServerConfiguration.cubicweb_appobject_path | WebConfiguration.cubicweb_appobject_path
    44     cleanup_interface_sobjects = False
    43     cube_appobject_path = ServerConfiguration.cube_appobject_path | WebConfiguration.cube_appobject_path
    45 
       
    46     cubicweb_appobject_path = (ServerConfiguration.cubicweb_appobject_path
       
    47                                | WebConfiguration.cubicweb_appobject_path)
       
    48     cube_appobject_path = (ServerConfiguration.cube_appobject_path
       
    49                            | WebConfiguration.cube_appobject_path)
    44 
    50 
    45     def __init__(self, *cubes):
    51     def __init__(self, *cubes):
    46         super(DevCubeConfiguration, self).__init__(cubes[0])
    52         super(DevConfiguration, self).__init__(cubes and cubes[0] or None)
    47         self._cubes = self.reorder_cubes(self.expand_cubes(cubes,
    53         if cubes:
    48                                          with_recommends=True))
    54             self._cubes = self.reorder_cubes(
       
    55                 self.expand_cubes(cubes, with_recommends=True))
       
    56         else:
       
    57             self._cubes = ()
    49 
    58 
    50     @property
    59     @property
    51     def apphome(self):
    60     def apphome(self):
    52         return None
    61         return None
    53     def main_config_file(self):
    62     def main_config_file(self):
    54         return None
    63         return None
    55     def init_log(self, debug=None):
    64     def init_log(self, debug=None):
    56         pass
    65         pass
    57     def load_configuration(self):
    66     def load_configuration(self):
    58         pass
    67         pass
    59 
       
    60 
       
    61 class DevDepConfiguration(DevCubeConfiguration):
       
    62     """configuration to use to generate cubicweb po files or to use as "library" configuration
       
    63     to filter out message ids from cubicweb and dependencies of a cube
       
    64     """
       
    65 
       
    66     def default_log_file(self):
    68     def default_log_file(self):
    67         return None
    69         return None
    68 
    70 
    69 
    71 
    70 def cleanup_sys_modules(config):
    72 def cleanup_sys_modules(config):
    91 
    93 
    92     notice that relation definitions description and static vocabulary
    94     notice that relation definitions description and static vocabulary
    93     should be marked using '_' and extracted using xgettext
    95     should be marked using '_' and extracted using xgettext
    94     """
    96     """
    95     from cubicweb.cwvreg import CubicWebVRegistry
    97     from cubicweb.cwvreg import CubicWebVRegistry
    96     cube = cubedir and split(cubedir)[-1]
       
    97     libconfig = DevDepConfiguration(cube)
       
    98     libconfig.cleanup_interface_sobjects = False
       
    99     cleanup_sys_modules(libconfig)
       
   100     if cubedir:
    98     if cubedir:
   101         config = DevCubeConfiguration(cube)
    99         cube = split(cubedir)[-1]
   102         config.cleanup_interface_sobjects = False
   100         config = DevConfiguration(cube)
       
   101         depcubes = list(config._cubes)
       
   102         depcubes.remove(cube)
       
   103         libconfig = DevConfiguration(*depcubes)
   103     else:
   104     else:
   104         config = libconfig
   105         config = DevConfiguration()
   105         libconfig = None
   106         cube = libconfig = None
       
   107     cleanup_sys_modules(config)
   106     schema = config.load_schema(remove_unused_rtypes=False)
   108     schema = config.load_schema(remove_unused_rtypes=False)
   107     vreg = CubicWebVRegistry(config)
   109     vreg = CubicWebVRegistry(config)
   108     # set_schema triggers objects registrations
   110     # set_schema triggers objects registrations
   109     vreg.set_schema(schema)
   111     vreg.set_schema(schema)
   110     w(DEFAULT_POT_HEAD)
   112     w(DEFAULT_POT_HEAD)
   344     arguments = '[<cube>...]'
   346     arguments = '[<cube>...]'
   345 
   347 
   346     def run(self, args):
   348     def run(self, args):
   347         """run the command with its specific arguments"""
   349         """run the command with its specific arguments"""
   348         if args:
   350         if args:
   349             cubes = [DevCubeConfiguration.cube_dir(cube) for cube in args]
   351             cubes = [DevConfiguration.cube_dir(cube) for cube in args]
   350         else:
   352         else:
   351             cubes = [DevCubeConfiguration.cube_dir(cube) for cube in DevCubeConfiguration.available_cubes()]
   353             cubes = [DevConfiguration.cube_dir(cube)
       
   354                      for cube in DevConfiguration.available_cubes()]
   352             cubes = [cubepath for cubepath in cubes if exists(join(cubepath, 'i18n'))]
   355             cubes = [cubepath for cubepath in cubes if exists(join(cubepath, 'i18n'))]
   353         update_cubes_catalogs(cubes)
   356         update_cubes_catalogs(cubes)
   354 
   357 
   355 
   358 
   356 def update_cubes_catalogs(cubes):
   359 def update_cubes_catalogs(cubes):
   622         total_time = sum(clocktime for clocktime, cputime, occ, rql in stat)*0.01
   625         total_time = sum(clocktime for clocktime, cputime, occ, rql in stat)*0.01
   623         print 'Percentage;Cumulative Time (clock);Cumulative Time (CPU);Occurences;Query'
   626         print 'Percentage;Cumulative Time (clock);Cumulative Time (CPU);Occurences;Query'
   624         for clocktime, cputime, occ, rql in stat:
   627         for clocktime, cputime, occ, rql in stat:
   625             print '%.2f;%.2f;%.2f;%s;%s' % (clocktime/total_time, clocktime, cputime, occ, rql)
   628             print '%.2f;%.2f;%.2f;%s;%s' % (clocktime/total_time, clocktime, cputime, occ, rql)
   626 
   629 
       
   630 
   627 class GenerateSchema(Command):
   631 class GenerateSchema(Command):
   628     """Generate schema image for the given cube"""
   632     """Generate schema image for the given cube"""
   629     name = "schema"
   633     name = "schema"
   630     arguments = '<cube>'
   634     arguments = '<cube>'
   631     options = [('output-file', {'type':'file', 'default': None,
   635     options = [('output-file', {'type':'file', 'default': None,
   658               ]
   662               ]
   659 
   663 
   660     def run(self, args):
   664     def run(self, args):
   661         from logilab.common.textutils import splitstrip
   665         from logilab.common.textutils import splitstrip
   662         cubes = splitstrip(pop_arg(args, 1))
   666         cubes = splitstrip(pop_arg(args, 1))
   663 
   667         dev_conf = DevConfiguration(*cubes)
   664         dev_conf = DevCubeConfiguration(*cubes)
       
   665         schema = dev_conf.load_schema()
   668         schema = dev_conf.load_schema()
   666 
       
   667 
       
   668         out, viewer = self['output-file'], self['viewer']
   669         out, viewer = self['output-file'], self['viewer']
   669         if out is None:
   670         if out is None:
   670             tmp_file = NamedTemporaryFile(suffix=".svg")
   671             tmp_file = NamedTemporaryFile(suffix=".svg")
   671             out = tmp_file.name
   672             out = tmp_file.name
   672 
       
   673         skiptypes = BASE_TYPES | SCHEMA_TYPES
   673         skiptypes = BASE_TYPES | SCHEMA_TYPES
   674         if not self['show-meta']:
   674         if not self['show-meta']:
   675             skiptypes |=  META_RTYPES | SYSTEM_RTYPES | INTERNAL_TYPES
   675             skiptypes |=  META_RTYPES | SYSTEM_RTYPES | INTERNAL_TYPES
   676         if not self['show-workflow']:
   676         if not self['show-workflow']:
   677             skiptypes |= WORKFLOW_TYPES
   677             skiptypes |= WORKFLOW_TYPES
   678         if not self['show-cw-user']:
   678         if not self['show-cw-user']:
   679             skiptypes |= set(('CWUser', 'CWGroup', 'EmailAddress'))
   679             skiptypes |= set(('CWUser', 'CWGroup', 'EmailAddress'))
   680         skiptypes |= set(self['exclude-type'].split(','))
   680         skiptypes |= set(self['exclude-type'].split(','))
   681         skiptypes -= set(self['include-type'].split(','))
   681         skiptypes -= set(self['include-type'].split(','))
   682 
       
   683         schema2dot.schema2dot(schema, out, skiptypes=skiptypes)
   682         schema2dot.schema2dot(schema, out, skiptypes=skiptypes)
   684 
       
   685         if viewer:
   683         if viewer:
   686             p = Popen((viewer, out))
   684             p = Popen((viewer, out))
   687             p.wait()
   685             p.wait()
   688 
   686 
   689 register_commands((UpdateCubicWebCatalogCommand,
   687 register_commands((UpdateCubicWebCatalogCommand,