183 import importlib |
183 import importlib |
184 import logging |
184 import logging |
185 import logging.config |
185 import logging.config |
186 import os |
186 import os |
187 from os.path import (exists, join, expanduser, abspath, normpath, |
187 from os.path import (exists, join, expanduser, abspath, normpath, |
188 basename, isdir, dirname, splitext) |
188 basename, isdir, dirname, splitext, realpath) |
189 import pkgutil |
189 import pkgutil |
190 import pkg_resources |
190 import pkg_resources |
191 import re |
191 import re |
192 from smtplib import SMTP |
192 from smtplib import SMTP |
193 import stat |
193 import stat |
271 |
271 |
272 def _cube_pkgname(cube): |
272 def _cube_pkgname(cube): |
273 if not cube.startswith('cubicweb_'): |
273 if not cube.startswith('cubicweb_'): |
274 return 'cubicweb_' + cube |
274 return 'cubicweb_' + cube |
275 return cube |
275 return cube |
|
276 |
|
277 |
|
278 def _expand_modname(modname): |
|
279 """expand modules names `modname` if exists by walking non package submodules |
|
280 and yield (submodname, filepath) including `modname` itself |
|
281 |
|
282 If the file ends with .pyc or .pyo (python bytecode) also check that the |
|
283 corresponding source .py file exists before yielding. |
|
284 """ |
|
285 try: |
|
286 loader = pkgutil.find_loader(modname) |
|
287 except ImportError: |
|
288 return |
|
289 if not loader: |
|
290 return |
|
291 |
|
292 def check_source_file(filepath): |
|
293 if filepath[-4:] in ('.pyc', '.pyo'): |
|
294 if not exists(filepath[:-1]): |
|
295 return False |
|
296 return True |
|
297 |
|
298 filepath = loader.get_filename() |
|
299 if not check_source_file(filepath): |
|
300 return |
|
301 yield modname, filepath |
|
302 if loader.is_package(modname): |
|
303 path = dirname(filepath) |
|
304 for subloader, subname, ispkg in pkgutil.walk_packages([path]): |
|
305 # ignore subpackages (historical behavior) |
|
306 if not ispkg: |
|
307 filepath = subloader.find_module(subname).get_filename() |
|
308 if check_source_file(filepath): |
|
309 yield modname + '.' + subname, filepath |
276 |
310 |
277 |
311 |
278 # persistent options definition |
312 # persistent options definition |
279 PERSISTENT_OPTIONS = ( |
313 PERSISTENT_OPTIONS = ( |
280 ('encoding', |
314 ('encoding', |
772 'backupCount': 52}) |
806 'backupCount': 52}) |
773 else: |
807 else: |
774 init_log(self.debugmode, syslog, logthreshold, logfile, self.log_format) |
808 init_log(self.debugmode, syslog, logthreshold, logfile, self.log_format) |
775 # configure simpleTal logger |
809 # configure simpleTal logger |
776 logging.getLogger('simpleTAL').setLevel(logging.ERROR) |
810 logging.getLogger('simpleTAL').setLevel(logging.ERROR) |
|
811 |
|
812 def schema_modnames(self): |
|
813 modnames = [] |
|
814 for name in ('bootstrap', 'base', 'workflow', 'Bookmark'): |
|
815 modnames.append(('cubicweb', 'cubicweb.schemas.' + name)) |
|
816 for cube in reversed(self.cubes()): |
|
817 for modname, filepath in _expand_modname('cubes.{0}.schema'.format(cube)): |
|
818 modnames.append((cube, modname)) |
|
819 if self.apphome: |
|
820 apphome = realpath(self.apphome) |
|
821 for modname, filepath in _expand_modname('schema'): |
|
822 if realpath(filepath).startswith(apphome): |
|
823 modnames.append(('data', modname)) |
|
824 return modnames |
777 |
825 |
778 def appobjects_path(self): |
826 def appobjects_path(self): |
779 """return a list of files or directories where the registry will look |
827 """return a list of files or directories where the registry will look |
780 for application objects. By default return nothing in NoApp config. |
828 for application objects. By default return nothing in NoApp config. |
781 """ |
829 """ |