283 return modname |
283 return modname |
284 else: |
284 else: |
285 return 'cubes.' + cube |
285 return 'cubes.' + cube |
286 |
286 |
287 |
287 |
288 def _expand_modname(modname): |
288 def _expand_modname(modname, recursive=True): |
289 """expand modules names `modname` if exists by walking non package submodules |
289 """expand modules names `modname` if exists by recursively walking |
290 and yield (submodname, filepath) including `modname` itself |
290 submodules and subpackages and yield (submodname, filepath) including |
|
291 `modname` itself |
291 |
292 |
292 If the file ends with .pyc or .pyo (python bytecode) also check that the |
293 If the file ends with .pyc or .pyo (python bytecode) also check that the |
293 corresponding source .py file exists before yielding. |
294 corresponding source .py file exists before yielding. |
|
295 |
|
296 If `recursive` is False skip subpackages. |
294 """ |
297 """ |
295 try: |
298 try: |
296 loader = pkgutil.find_loader(modname) |
299 loader = pkgutil.find_loader(modname) |
297 except ImportError: |
300 except ImportError: |
298 return |
301 return |
310 return |
313 return |
311 yield modname, filepath |
314 yield modname, filepath |
312 if loader.is_package(modname): |
315 if loader.is_package(modname): |
313 path = dirname(filepath) |
316 path = dirname(filepath) |
314 for subloader, subname, ispkg in pkgutil.walk_packages([path]): |
317 for subloader, subname, ispkg in pkgutil.walk_packages([path]): |
315 # ignore subpackages (historical behavior) |
318 submodname = '.'.join([modname, subname]) |
316 if not ispkg: |
319 if not ispkg: |
317 filepath = subloader.find_module(subname).get_filename() |
320 filepath = subloader.find_module(subname).get_filename() |
318 if check_source_file(filepath): |
321 if check_source_file(filepath): |
319 yield modname + '.' + subname, filepath |
322 yield submodname, filepath |
|
323 elif recursive: |
|
324 for x in _expand_modname(submodname, recursive=True): |
|
325 yield x |
320 |
326 |
321 |
327 |
322 # persistent options definition |
328 # persistent options definition |
323 PERSISTENT_OPTIONS = ( |
329 PERSISTENT_OPTIONS = ( |
324 ('encoding', |
330 ('encoding', |
817 modnames = [] |
823 modnames = [] |
818 for name in ('bootstrap', 'base', 'workflow', 'Bookmark'): |
824 for name in ('bootstrap', 'base', 'workflow', 'Bookmark'): |
819 modnames.append(('cubicweb', 'cubicweb.schemas.' + name)) |
825 modnames.append(('cubicweb', 'cubicweb.schemas.' + name)) |
820 for cube in reversed(self.cubes()): |
826 for cube in reversed(self.cubes()): |
821 for modname, filepath in _expand_modname( |
827 for modname, filepath in _expand_modname( |
822 '{0}.schema'.format(_cube_modname(cube))): |
828 '{0}.schema'.format(_cube_modname(cube)), |
|
829 recursive=False): |
823 modnames.append((cube, modname)) |
830 modnames.append((cube, modname)) |
824 if self.apphome: |
831 if self.apphome: |
825 apphome = realpath(self.apphome) |
832 apphome = realpath(self.apphome) |
826 for modname, filepath in _expand_modname('schema'): |
833 for modname, filepath in _expand_modname( |
|
834 'schema', recursive=False): |
827 if realpath(filepath).startswith(apphome): |
835 if realpath(filepath).startswith(apphome): |
828 modnames.append(('data', modname)) |
836 modnames.append(('data', modname)) |
829 return modnames |
837 return modnames |
830 |
838 |
831 def appobjects_modnames(self): |
839 def appobjects_modnames(self): |