17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
18 """classes to define schemas for CubicWeb""" |
18 """classes to define schemas for CubicWeb""" |
19 |
19 |
20 from __future__ import print_function |
20 from __future__ import print_function |
21 |
21 |
|
22 import pkgutil |
22 import re |
23 import re |
23 from os.path import join, basename |
24 from os.path import join, basename |
24 from hashlib import md5 |
25 from hashlib import md5 |
25 from logging import getLogger |
26 from logging import getLogger |
26 from warnings import warn |
27 from warnings import warn |
1367 """cubicweb specific schema loader, loading only schema necessary to read |
1368 """cubicweb specific schema loader, loading only schema necessary to read |
1368 the persistent schema |
1369 the persistent schema |
1369 """ |
1370 """ |
1370 schemacls = CubicWebSchema |
1371 schemacls = CubicWebSchema |
1371 |
1372 |
1372 def load(self, config, path=(), **kwargs): |
1373 def load(self, config, modnames=(['cubicweb', 'cubicweb.schemas.bootstrap'],), **kwargs): |
1373 """return a Schema instance from the schema definition read |
1374 """return a Schema instance from the schema definition read |
1374 from <directory> |
1375 from <directory> |
1375 """ |
1376 """ |
1376 return super(BootstrapSchemaLoader, self).load( |
1377 return super(BootstrapSchemaLoader, self).load( |
1377 path, config.appid, register_base_types=False, **kwargs) |
1378 modnames, name=config.appid, register_base_types=False, **kwargs) |
1378 |
|
1379 def _load_definition_files(self, cubes=None): |
|
1380 # bootstraping, ignore cubes |
|
1381 filepath = join(cubicweb.CW_SOFTWARE_ROOT, 'schemas', 'bootstrap.py') |
|
1382 self.info('loading %s', filepath) |
|
1383 with tempattr(ybo, 'PACKAGE', 'cubicweb'): # though we don't care here |
|
1384 self.handle_file(filepath) |
|
1385 |
1379 |
1386 def unhandled_file(self, filepath): |
1380 def unhandled_file(self, filepath): |
1387 """called when a file without handler associated has been found""" |
1381 """called when a file without handler associated has been found""" |
1388 self.warning('ignoring file %r', filepath) |
1382 self.warning('ignoring file %r', filepath) |
1389 |
1383 |
1400 def load(self, config, **kwargs): |
1394 def load(self, config, **kwargs): |
1401 """return a Schema instance from the schema definition read |
1395 """return a Schema instance from the schema definition read |
1402 from <directory> |
1396 from <directory> |
1403 """ |
1397 """ |
1404 self.info('loading %s schemas', ', '.join(config.cubes())) |
1398 self.info('loading %s schemas', ', '.join(config.cubes())) |
1405 self.extrapath = config.extrapath |
|
1406 if config.apphome: |
|
1407 path = tuple(reversed([config.apphome] + config.cubes_path())) |
|
1408 else: |
|
1409 path = tuple(reversed(config.cubes_path())) |
|
1410 try: |
1399 try: |
1411 return super(CubicWebSchemaLoader, self).load(config, path=path, **kwargs) |
1400 return super(CubicWebSchemaLoader, self).load(config, config.schema_modnames(), **kwargs) |
1412 finally: |
1401 finally: |
1413 # we've to cleanup modules imported from cubicweb.schemas as well |
1402 # we've to cleanup modules imported from cubicweb.schemas as well |
1414 cleanup_sys_modules([join(cubicweb.CW_SOFTWARE_ROOT, 'schemas')]) |
1403 cleanup_sys_modules([join(cubicweb.CW_SOFTWARE_ROOT, 'schemas')]) |
1415 |
|
1416 def _load_definition_files(self, cubes): |
|
1417 for filepath in (join(cubicweb.CW_SOFTWARE_ROOT, 'schemas', 'bootstrap.py'), |
|
1418 join(cubicweb.CW_SOFTWARE_ROOT, 'schemas', 'base.py'), |
|
1419 join(cubicweb.CW_SOFTWARE_ROOT, 'schemas', 'workflow.py'), |
|
1420 join(cubicweb.CW_SOFTWARE_ROOT, 'schemas', 'Bookmark.py')): |
|
1421 self.info('loading %s', filepath) |
|
1422 with tempattr(ybo, 'PACKAGE', 'cubicweb'): |
|
1423 self.handle_file(filepath) |
|
1424 for cube in cubes: |
|
1425 for filepath in self.get_schema_files(cube): |
|
1426 with tempattr(ybo, 'PACKAGE', basename(cube)): |
|
1427 self.handle_file(filepath) |
|
1428 |
1404 |
1429 # these are overridden by set_log_methods below |
1405 # these are overridden by set_log_methods below |
1430 # only defining here to prevent pylint from complaining |
1406 # only defining here to prevent pylint from complaining |
1431 info = warning = error = critical = exception = debug = lambda msg, *a, **kw: None |
1407 info = warning = error = critical = exception = debug = lambda msg, *a, **kw: None |
1432 |
1408 |