cubicweb/cwconfig.py
branch3.25
changeset 12078 82d2c1cdf0c2
parent 12053 c3c9f2e1424c
child 12109 425be06bb1e8
equal deleted inserted replaced
12074:f5fee548588d 12078:82d2c1cdf0c2
   272 
   272 
   273 def _cube_pkgname(cube):
   273 def _cube_pkgname(cube):
   274     if not cube.startswith('cubicweb_'):
   274     if not cube.startswith('cubicweb_'):
   275         return 'cubicweb_' + cube
   275         return 'cubicweb_' + cube
   276     return cube
   276     return cube
       
   277 
       
   278 
       
   279 def _cube_modname(cube):
       
   280     modname = _cube_pkgname(cube)
       
   281     loader = pkgutil.find_loader(modname)
       
   282     if loader:
       
   283         return modname
       
   284     else:
       
   285         return 'cubes.' + cube
   277 
   286 
   278 
   287 
   279 def _expand_modname(modname):
   288 def _expand_modname(modname):
   280     """expand modules names `modname` if exists by walking non package submodules
   289     """expand modules names `modname` if exists by walking non package submodules
   281     and yield (submodname, filepath) including `modname` itself
   290     and yield (submodname, filepath) including `modname` itself
   815     def schema_modnames(self):
   824     def schema_modnames(self):
   816         modnames = []
   825         modnames = []
   817         for name in ('bootstrap', 'base', 'workflow', 'Bookmark'):
   826         for name in ('bootstrap', 'base', 'workflow', 'Bookmark'):
   818             modnames.append(('cubicweb', 'cubicweb.schemas.' + name))
   827             modnames.append(('cubicweb', 'cubicweb.schemas.' + name))
   819         for cube in reversed(self.cubes()):
   828         for cube in reversed(self.cubes()):
   820             for modname, filepath in _expand_modname('cubes.{0}.schema'.format(cube)):
   829             for modname, filepath in _expand_modname(
       
   830                     '{0}.schema'.format(_cube_modname(cube))):
   821                 modnames.append((cube, modname))
   831                 modnames.append((cube, modname))
   822         if self.apphome:
   832         if self.apphome:
   823             apphome = realpath(self.apphome)
   833             apphome = realpath(self.apphome)
   824             for modname, filepath in _expand_modname('schema'):
   834             for modname, filepath in _expand_modname('schema'):
   825                 if realpath(filepath).startswith(apphome):
   835                 if realpath(filepath).startswith(apphome):
  1333             appobjects.insert(0, appobjects.pop(index))
  1343             appobjects.insert(0, appobjects.pop(index))
  1334         return appobjects
  1344         return appobjects
  1335 
  1345 
  1336     def appobjects_cube_modnames(self, cube):
  1346     def appobjects_cube_modnames(self, cube):
  1337         modnames = []
  1347         modnames = []
       
  1348         cube_modname = _cube_modname(cube)
  1338         cube_submodnames = self._sorted_appobjects(self.cube_appobject_path)
  1349         cube_submodnames = self._sorted_appobjects(self.cube_appobject_path)
  1339         for name in cube_submodnames:
  1350         for name in cube_submodnames:
  1340             for modname, filepath in _expand_modname('.'.join(['cubes', cube, name])):
  1351             for modname, filepath in _expand_modname('.'.join([cube_modname, name])):
  1341                 modnames.append(modname)
  1352                 modnames.append(modname)
  1342         return modnames
  1353         return modnames
  1343 
  1354 
  1344     def appobjects_modnames(self):
  1355     def appobjects_modnames(self):
  1345         modnames = []
  1356         modnames = []