devtools/devctl.py
branchtls-sprint
changeset 1470 fbdf66a08fbb
parent 1451 982e8616d9a2
child 1502 e25be3c82947
equal deleted inserted replaced
1469:ba9759972b52 1470:fbdf66a08fbb
    84     notice that relation definitions description and static vocabulary
    84     notice that relation definitions description and static vocabulary
    85     should be marked using '_' and extracted using xgettext
    85     should be marked using '_' and extracted using xgettext
    86     """
    86     """
    87     from cubicweb.cwvreg import CubicWebRegistry
    87     from cubicweb.cwvreg import CubicWebRegistry
    88     cube = cubedir and split(cubedir)[-1]
    88     cube = cubedir and split(cubedir)[-1]
    89     config = DevDepConfiguration(cube)
    89     libconfig = DevDepConfiguration(cube)
    90     cleanup_sys_modules(config)
    90     libconfig.cleanup_interface_sobjects = False
       
    91     cleanup_sys_modules(libconfig)
    91     if cubedir:
    92     if cubedir:
    92         libschema = config.load_schema()
       
    93         config = DevCubeConfiguration(cube)
    93         config = DevCubeConfiguration(cube)
    94         schema = config.load_schema()
    94         schema = config.load_schema()
    95     else:
    95     else:
    96         schema = config.load_schema()
    96         schema = config.load_schema()
    97         libschema = None
    97         config = libconfig
    98         config.cleanup_interface_sobjects = False
    98         libconfig = None
    99     vreg = CubicWebRegistry(config)
    99     vreg = CubicWebRegistry(config)
   100     # set_schema triggers objects registrations
   100     # set_schema triggers objects registrations
   101     vreg.set_schema(schema)
   101     vreg.set_schema(schema)
   102     w(DEFAULT_POT_HEAD)
   102     w(DEFAULT_POT_HEAD)
   103     _generate_schema_pot(w, vreg, schema, libschema=libschema, cube=cube)
   103     _generate_schema_pot(w, vreg, schema, libconfig=libconfig, cube=cube)
   104 
   104 
   105 
   105 
   106 def _generate_schema_pot(w, vreg, schema, libschema=None, cube=None):
   106 def _generate_schema_pot(w, vreg, schema, libconfig=None, cube=None):
   107     from cubicweb.common.i18n import add_msg
   107     from cubicweb.common.i18n import add_msg
   108     w('# schema pot file, generated on %s\n' % datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
   108     w('# schema pot file, generated on %s\n' % datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
   109     w('# \n')
   109     w('# \n')
   110     w('# singular and plural forms for each entity type\n')
   110     w('# singular and plural forms for each entity type\n')
   111     w('\n')
   111     w('\n')
   112     if libschema is not None:
   112     if libconfig is not None:
       
   113         libschema = libconfig.load_schema()
   113         entities = [e for e in schema.entities() if not e in libschema]
   114         entities = [e for e in schema.entities() if not e in libschema]
   114     else:
   115     else:
   115         entities = schema.entities()
   116         entities = schema.entities()
   116     done = set()
   117     done = set()
   117     for eschema in sorted(entities):
   118     for eschema in sorted(entities):
   168                                                          eschema, role)
   169                                                          eschema, role)
   169                             label2 = "creating %s (%s %s %s %%(linkto)s)" % (
   170                             label2 = "creating %s (%s %s %s %%(linkto)s)" % (
   170                                 teschema, teschema, rschema, eschema)
   171                                 teschema, teschema, rschema, eschema)
   171                         add_msg(w, label)
   172                         add_msg(w, label)
   172                         add_msg(w, label2)
   173                         add_msg(w, label2)
   173     cube = (cube and 'cubes.%s.' % cube or 'cubicweb.')
   174     #cube = (cube and 'cubes.%s.' % cube or 'cubicweb.')
   174     done = set()
   175     done = set()
       
   176     if libconfig is not None:
       
   177         from cubicweb.cwvreg import CubicWebRegistry
       
   178         libvreg = CubicWebRegistry(libconfig)
       
   179         libvreg.set_schema(libschema) # trigger objects registration
       
   180         # prefill done set
       
   181         list(_iter_vreg_objids(libvreg, done))
       
   182     print 'done', done
       
   183     for objid in _iter_vreg_objids(vreg, done):
       
   184         add_msg(w, '%s_description' % objid)
       
   185         add_msg(w, objid)
       
   186 
       
   187 def _iter_vreg_objids(vreg, done, prefix=None):
   175     for reg, objdict in vreg.items():
   188     for reg, objdict in vreg.items():
   176         for objects in objdict.values():
   189         for objects in objdict.values():
   177             for obj in objects:
   190             for obj in objects:
   178                 objid = '%s_%s' % (reg, obj.id)
   191                 objid = '%s_%s' % (reg, obj.id)
   179                 if objid in done:
   192                 if objid in done:
   180                     continue
   193                     break
   181                 if obj.__module__.startswith(cube) and obj.property_defs:
   194                 if obj.property_defs:
   182                     add_msg(w, '%s_description' % objid)
   195                     yield objid
   183                     add_msg(w, objid)
       
   184                     done.add(objid)
   196                     done.add(objid)
       
   197                     break
   185 
   198 
   186 
   199 
   187 def defined_in_library(libschema, etype, rtype, tetype, role):
   200 def defined_in_library(libschema, etype, rtype, tetype, role):
   188     """return true if the given relation definition exists in cubicweb's library
   201     """return true if the given relation definition exists in cubicweb's library
   189     """
   202     """