devtools/devctl.py
changeset 9205 ea32e964fbf8
parent 9203 c7ba8e5d2e45
child 9231 d2edd8ac5f33
equal deleted inserted replaced
9149:31ed9dd946d1 9205:ea32e964fbf8
     1 # copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     1 # copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     3 #
     3 #
     4 # This file is part of CubicWeb.
     4 # This file is part of CubicWeb.
     5 #
     5 #
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
   128       % datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
   128       % datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
   129     w('# \n')
   129     w('# \n')
   130     w('# singular and plural forms for each entity type\n')
   130     w('# singular and plural forms for each entity type\n')
   131     w('\n')
   131     w('\n')
   132     vregdone = set()
   132     vregdone = set()
       
   133     afss = vreg['uicfg']['autoform_section']
       
   134     aiams = vreg['uicfg']['actionbox_appearsin_addmenu']
   133     if libconfig is not None:
   135     if libconfig is not None:
       
   136         # processing a cube, libconfig being a config with all its dependencies
       
   137         # (cubicweb incl.)
   134         from cubicweb.cwvreg import CWRegistryStore
   138         from cubicweb.cwvreg import CWRegistryStore
   135         libschema = libconfig.load_schema(remove_unused_rtypes=False)
   139         libschema = libconfig.load_schema(remove_unused_rtypes=False)
   136         afs = vreg['uicfg'].select('autoform_section')
       
   137         appearsin_addmenu = vreg['uicfg'].select('actionbox_appearsin_addmenu')
       
   138         cleanup_sys_modules(libconfig)
   140         cleanup_sys_modules(libconfig)
   139         libvreg = CWRegistryStore(libconfig)
   141         libvreg = CWRegistryStore(libconfig)
   140         libvreg.set_schema(libschema) # trigger objects registration
   142         libvreg.set_schema(libschema) # trigger objects registration
   141         libafs = libvreg['uicfg'].select('autoform_section')
   143         libafss = libvreg['uicfg']['autoform_section']
   142         libappearsin_addmenu = libvreg['uicfg'].select('actionbox_appearsin_addmenu')
   144         libaiams = libvreg['uicfg']['actionbox_appearsin_addmenu']
   143         # prefill vregdone set
   145         # prefill vregdone set
   144         list(_iter_vreg_objids(libvreg, vregdone))
   146         list(_iter_vreg_objids(libvreg, vregdone))
       
   147 
       
   148         def is_in_lib(rtags, eschema, rschema, role, tschema, predicate=bool):
       
   149             return any(predicate(rtag.etype_get(eschema, rschema, role, tschema))
       
   150                        for rtag in rtags)
   145     else:
   151     else:
       
   152         # processing cubicweb itself
   146         libschema = {}
   153         libschema = {}
   147         afs = vreg['uicfg'].select('autoform_section')
       
   148         appearsin_addmenu = vreg['uicfg'].select('actionbox_appearsin_addmenu')
       
   149         for cstrtype in CONSTRAINTS:
   154         for cstrtype in CONSTRAINTS:
   150             add_msg(w, cstrtype)
   155             add_msg(w, cstrtype)
       
   156 
       
   157         is_in_lib = lambda: False
   151     done = set()
   158     done = set()
   152     for eschema in sorted(schema.entities()):
   159     for eschema in sorted(schema.entities()):
   153         if eschema.type in libschema:
   160         if eschema.type in libschema:
   154             done.add(eschema.description)
   161             done.add(eschema.description)
   155     for eschema in sorted(schema.entities()):
   162     for eschema in sorted(schema.entities()):
   167             continue
   174             continue
   168         for rschema, targetschemas, role in eschema.relation_definitions(True):
   175         for rschema, targetschemas, role in eschema.relation_definitions(True):
   169             if rschema.final:
   176             if rschema.final:
   170                 continue
   177                 continue
   171             for tschema in targetschemas:
   178             for tschema in targetschemas:
   172                 fsections = afs.etype_get(eschema, rschema, role, tschema)
   179 
   173                 if 'main_inlined' in fsections and \
   180                 for afs in afss:
   174                        (libconfig is None or not
   181                     fsections = afs.etype_get(eschema, rschema, role, tschema)
   175                         'main_inlined' in libafs.etype_get(
   182                     if 'main_inlined' in fsections and not \
   176                             eschema, rschema, role, tschema)):
   183                             is_in_lib(libafss, eschema, rschema, role, tschema,
   177                     add_msg(w, 'add a %s' % tschema,
   184                                       lambda x: 'main_inlined' in x):
   178                             'inlined:%s.%s.%s' % (etype, rschema, role))
   185                         add_msg(w, 'add a %s' % tschema,
   179                     add_msg(w, str(tschema),
   186                                 'inlined:%s.%s.%s' % (etype, rschema, role))
   180                             'inlined:%s.%s.%s' % (etype, rschema, role))
   187                         add_msg(w, str(tschema),
   181                 if appearsin_addmenu.etype_get(eschema, rschema, role, tschema):
   188                                 'inlined:%s.%s.%s' % (etype, rschema, role))
   182                     if libconfig is not None and libappearsin_addmenu.etype_get(
   189                         break
   183                         eschema, rschema, role, tschema):
   190 
   184                         if eschema in libschema and tschema in libschema:
   191                 for aiam in aiams:
   185                             continue
   192                     if aiam.etype_get(eschema, rschema, role, tschema) and not \
   186                     if role == 'subject':
   193                             is_in_lib(libaiams, eschema, rschema, role, tschema):
   187                         label = 'add %s %s %s %s' % (eschema, rschema,
   194                         if role == 'subject':
   188                                                      tschema, role)
   195                             label = 'add %s %s %s %s' % (eschema, rschema,
   189                         label2 = "creating %s (%s %%(linkto)s %s %s)" % (
   196                                                          tschema, role)
   190                             tschema, eschema, rschema, tschema)
   197                             label2 = "creating %s (%s %%(linkto)s %s %s)" % (
   191                     else:
   198                                 tschema, eschema, rschema, tschema)
   192                         label = 'add %s %s %s %s' % (tschema, rschema,
   199                         else:
   193                                                      eschema, role)
   200                             label = 'add %s %s %s %s' % (tschema, rschema,
   194                         label2 = "creating %s (%s %s %s %%(linkto)s)" % (
   201                                                          eschema, role)
   195                             tschema, tschema, rschema, eschema)
   202                             label2 = "creating %s (%s %s %s %%(linkto)s)" % (
   196                     add_msg(w, label)
   203                                 tschema, tschema, rschema, eschema)
   197                     add_msg(w, label2)
   204                         add_msg(w, label)
       
   205                         add_msg(w, label2)
       
   206                         break
   198             # XXX also generate "creating ...' messages for actions in the
   207             # XXX also generate "creating ...' messages for actions in the
   199             # addrelated submenu
   208             # addrelated submenu
   200     w('# subject and object forms for each relation type\n')
   209     w('# subject and object forms for each relation type\n')
   201     w('# (no object form for final or symmetric relation types)\n')
   210     w('# (no object form for final or symmetric relation types)\n')
   202     w('\n')
   211     w('\n')