devtools/devctl.py
changeset 3293 69c0ba095536
parent 3230 1d25e928c299
parent 3287 19c1011736a6
child 3369 7b88d12b4ee2
--- a/devtools/devctl.py	Tue Sep 15 15:01:41 2009 +0200
+++ b/devtools/devctl.py	Thu Sep 17 15:16:53 2009 +0200
@@ -12,6 +12,7 @@
 from datetime import datetime
 from os import mkdir, chdir, getcwd
 from os.path import join, exists, abspath, basename, normpath, split, isdir
+from copy import deepcopy
 from warnings import warn
 
 from logilab.common import STD_BLACKLIST
@@ -112,93 +113,104 @@
 
 def _generate_schema_pot(w, vreg, schema, libconfig=None, cube=None):
     from cubicweb.common.i18n import add_msg
+    from cubicweb.web import uicfg
+    from cubicweb.schema import META_RTYPES, SYSTEM_RTYPES
+    no_context_rtypes = META_RTYPES | SYSTEM_RTYPES
     w('# schema pot file, generated on %s\n' % datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
     w('# \n')
     w('# singular and plural forms for each entity type\n')
     w('\n')
+    vregdone = set()
     if libconfig is not None:
+        from cubicweb.cwvreg import CubicWebVRegistry, clear_rtag_objects
         libschema = libconfig.load_schema(remove_unused_rtypes=False)
-        entities = [e for e in schema.entities() if not e in libschema]
+        rinlined = deepcopy(uicfg.autoform_is_inlined)
+        appearsin_addmenu = deepcopy(uicfg.actionbox_appearsin_addmenu)
+        clear_rtag_objects()
+        cleanup_sys_modules(libconfig)
+        libvreg = CubicWebVRegistry(libconfig)
+        libvreg.set_schema(libschema) # trigger objects registration
+        librinlined = uicfg.autoform_is_inlined
+        libappearsin_addmenu = uicfg.actionbox_appearsin_addmenu
+        # prefill vregdone set
+        list(_iter_vreg_objids(libvreg, vregdone))
     else:
-        libschema = None
-        entities = schema.entities()
+        libschema = {}
+        rinlined = uicfg.autoform_is_inlined
+        appearsin_addmenu = uicfg.actionbox_appearsin_addmenu
     done = set()
-    for eschema in sorted(entities):
+    for eschema in sorted(schema.entities()):
         etype = eschema.type
-        add_msg(w, etype)
-        add_msg(w, '%s_plural' % etype)
-        if not eschema.is_final():
-            add_msg(w, 'This %s' % etype)
-            add_msg(w, 'New %s' % etype)
-            add_msg(w, 'add a %s' % etype)
-            add_msg(w, 'remove this %s' % etype)
-        if eschema.description and not eschema.description in done:
-            done.add(eschema.description)
-            add_msg(w, eschema.description)
-    w('# subject and object forms for each relation type\n')
-    w('# (no object form for final relation types)\n')
-    w('\n')
-    if libconfig is not None:
-        relations = [r for r in schema.relations() if not r in libschema]
-    else:
-        relations = schema.relations()
-    for rschema in sorted(set(relations)):
-        rtype = rschema.type
-        add_msg(w, rtype)
-        done.add(rtype)
-        if not (schema.rschema(rtype).is_final() or rschema.symetric):
-            add_msg(w, '%s_object' % rtype)
-        if rschema.description and rschema.description not in done:
-            done.add(rschema.description)
-            add_msg(w, rschema.description)
-    w('# add related box generated message\n')
-    w('\n')
-    from cubicweb.web import uicfg
-    appearsin_addmenu = uicfg.actionbox_appearsin_addmenu
-    for eschema in schema.entities():
+        if etype not in libschema:
+            add_msg(w, etype)
+            add_msg(w, '%s_plural' % etype)
+            if not eschema.is_final():
+                add_msg(w, 'This %s' % etype)
+                add_msg(w, 'New %s' % etype)
+            if eschema.description and not eschema.description in done:
+                done.add(eschema.description)
+                add_msg(w, eschema.description)
         if eschema.is_final():
             continue
-        for role, rschemas in (('subject', eschema.subject_relations()),
-                            ('object', eschema.object_relations())):
-            for rschema in rschemas:
-                if rschema.is_final():
-                    continue
-                if libconfig is not None:
-                    librschema = libschema.get(rschema)
-                for teschema in rschema.targets(eschema, role):
-                    if libconfig is not None and librschema is not None:
-                        if role == 'subject':
-                            subjtype, objtype = eschema, teschema
-                        else:
-                            subjtype, objtype = teschema, eschema
-                        if librschema.has_rdef(subjtype, objtype):
-                            continue
-                    if appearsin_addmenu.etype_get(eschema, rschema, role,
-                                                   teschema):
-                        if role == 'subject':
-                            label = 'add %s %s %s %s' % (eschema, rschema,
-                                                         teschema, role)
-                            label2 = "creating %s (%s %%(linkto)s %s %s)" % (
-                                teschema, eschema, rschema, teschema)
-                        else:
-                            label = 'add %s %s %s %s' % (teschema, rschema,
-                                                         eschema, role)
-                            label2 = "creating %s (%s %s %s %%(linkto)s)" % (
-                                teschema, teschema, rschema, eschema)
-                        add_msg(w, label)
-                        add_msg(w, label2)
-    #cube = (cube and 'cubes.%s.' % cube or 'cubicweb.')
-    done = set()
-    if libconfig is not None:
-        from cubicweb.cwvreg import CubicWebVRegistry
-        libvreg = CubicWebVRegistry(libconfig)
-        libvreg.set_schema(libschema) # trigger objects registration
-        # prefill done set
-        list(_iter_vreg_objids(libvreg, done))
-    for objid in _iter_vreg_objids(vreg, done):
+        for rschema, targetschemas, role in eschema.relation_definitions(True):
+            for tschema in targetschemas:
+                if rinlined.etype_get(eschema, rschema, role, tschema) and \
+                       (libconfig is None or not
+                        librinlined.etype_get(eschema, rschema, role, tschema)):
+                    add_msg(w, 'add a %s' % tschema,
+                            'inlined:%s.%s.%s' % (etype, rschema, role))
+                    add_msg(w, 'remove this %s' % tschema,
+                            'inlined:%s:%s:%s' % (etype, rschema, role))
+                if appearsin_addmenu.etype_get(eschema, rschema, role, tschema) and \
+                       (libconfig is None or not
+                        libappearsin_addmenu.etype_get(eschema, rschema, role, tschema)):
+                    if role == 'subject':
+                        label = 'add %s %s %s %s' % (eschema, rschema,
+                                                     tschema, role)
+                        label2 = "creating %s (%s %%(linkto)s %s %s)" % (
+                            tschema, eschema, rschema, tschema)
+                    else:
+                        label = 'add %s %s %s %s' % (tschema, rschema,
+                                                     eschema, role)
+                        label2 = "creating %s (%s %s %s %%(linkto)s)" % (
+                            tschema, tschema, rschema, eschema)
+                    add_msg(w, label)
+                    add_msg(w, label2)
+    w('# subject and object forms for each relation type\n')
+    w('# (no object form for final or symetric relation types)\n')
+    w('\n')
+    for rschema in sorted(schema.relations()):
+        rtype = rschema.type
+        if rtype not in libschema:
+            # bw compat, necessary until all translation of relation are done properly...
+            add_msg(w, rtype)
+            if rschema.description and rschema.description not in done:
+                done.add(rschema.description)
+                add_msg(w, rschema.description)
+            done.add(rtype)
+            librschema = None
+        else:
+            librschema = libschema.rschema(rtype)
+        # add context information only for non-metadata rtypes
+        if rschema not in no_context_rtypes:
+            libsubjects = librschema and librschema.subjects() or ()
+            for subjschema in rschema.subjects():
+                if not subjschema in libsubjects:
+                    add_msg(w, rtype, subjschema.type)
+        if not (schema.rschema(rtype).is_final() or rschema.symetric):
+            if rschema not in no_context_rtypes:
+                libobjects = librschema and librschema.objects() or ()
+                for objschema in rschema.objects():
+                    if not objschema in libobjects:
+                        add_msg(w, '%s_object' % rtype, objschema.type)
+            if rtype not in libschema:
+                # bw compat, necessary until all translation of relation are done properly...
+                add_msg(w, '%s_object' % rtype)
+    for objid in _iter_vreg_objids(vreg, vregdone):
         add_msg(w, '%s_description' % objid)
         add_msg(w, objid)
 
+
 def _iter_vreg_objids(vreg, done, prefix=None):
     for reg, objdict in vreg.items():
         for objects in objdict.values():