schema.py
branchstable
changeset 2142 098aa2075903
parent 1977 606923dff11b
child 2144 51c84d585456
child 2147 476a75ede2cc
equal deleted inserted replaced
2139:8969443bd21c 2142:098aa2075903
     4 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
     4 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
     6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
     7 """
     7 """
     8 __docformat__ = "restructuredtext en"
     8 __docformat__ = "restructuredtext en"
       
     9 _ = unicode
     9 
    10 
    10 import re
    11 import re
    11 from logging import getLogger
    12 from logging import getLogger
    12 from warnings import warn
    13 from warnings import warn
    13 
    14 
    32 
    33 
    33 _ = unicode
    34 _ = unicode
    34 
    35 
    35 BASEGROUPS = ('managers', 'users', 'guests', 'owners')
    36 BASEGROUPS = ('managers', 'users', 'guests', 'owners')
    36 
    37 
    37 LOGGER = getLogger('cubicweb.schemaloader')
    38 _LOGGER = getLogger('cubicweb.schemaloader')
    38 
    39 
    39 # schema entities created from serialized schema have an eid rproperty
    40 # schema entities created from serialized schema have an eid rproperty
    40 ybo.ETYPE_PROPERTIES += ('eid',)
    41 ybo.ETYPE_PROPERTIES += ('eid',)
    41 ybo.RTYPE_PROPERTIES += ('eid',)
    42 ybo.RTYPE_PROPERTIES += ('eid',)
    42 ybo.RDEF_PROPERTIES += ('eid',)
    43 ybo.RDEF_PROPERTIES += ('eid',)
   634             self.rqlst = parse(self.full_rql, print_errors=False).children[0]
   635             self.rqlst = parse(self.full_rql, print_errors=False).children[0]
   635         except RQLSyntaxError:
   636         except RQLSyntaxError:
   636             raise RQLSyntaxError(expression)
   637             raise RQLSyntaxError(expression)
   637         for mainvar in mainvars.split(','):
   638         for mainvar in mainvars.split(','):
   638             if len(self.rqlst.defined_vars[mainvar].references()) <= 2:
   639             if len(self.rqlst.defined_vars[mainvar].references()) <= 2:
   639                 LOGGER.warn('You did not use the %s variable in your RQL expression %s',
   640                 _LOGGER.warn('You did not use the %s variable in your RQL '
   640                             mainvar, self)
   641                              'expression %s', mainvar, self)
   641 
   642 
   642     def __str__(self):
   643     def __str__(self):
   643         return self.full_rql
   644         return self.full_rql
   644     def __repr__(self):
   645     def __repr__(self):
   645         return '%s(%s)' % (self.__class__.__name__, self.full_rql)
   646         return '%s(%s)' % (self.__class__.__name__, self.full_rql)
   902         return super(BootstrapSchemaLoader, self).load(
   903         return super(BootstrapSchemaLoader, self).load(
   903             path, config.appid, register_base_types=False, **kwargs)
   904             path, config.appid, register_base_types=False, **kwargs)
   904 
   905 
   905     def _load_definition_files(self, cubes=None):
   906     def _load_definition_files(self, cubes=None):
   906         # bootstraping, ignore cubes
   907         # bootstraping, ignore cubes
   907         for filepath in self.include_schema_files('bootstrap'):
   908         filepath = join(self.lib_directory, 'bootstrap.py')
   908             self.info('loading %s', filepath)
   909         self.info('loading %s', filepath)
   909             self.handle_file(filepath)
   910         self.handle_file(filepath)
   910 
   911 
   911     def unhandled_file(self, filepath):
   912     def unhandled_file(self, filepath):
   912         """called when a file without handler associated has been found"""
   913         """called when a file without handler associated has been found"""
   913         self.warning('ignoring file %r', filepath)
   914         self.warning('ignoring file %r', filepath)
   914 
   915 
   928         else:
   929         else:
   929             path = reversed(config.cubes_path())
   930             path = reversed(config.cubes_path())
   930         return super(CubicWebSchemaLoader, self).load(config, path=path, **kwargs)
   931         return super(CubicWebSchemaLoader, self).load(config, path=path, **kwargs)
   931 
   932 
   932     def _load_definition_files(self, cubes):
   933     def _load_definition_files(self, cubes):
   933         for filepath in (self.include_schema_files('bootstrap')
   934         for filepath in (join(self.lib_directory, 'bootstrap.py'),
   934                          + self.include_schema_files('base')
   935                          join(self.lib_directory, 'base.py'),
   935                          + self.include_schema_files('workflow')
   936                          join(self.lib_directory, 'workflow.py'),
   936                          + self.include_schema_files('Bookmark')):
   937                          join(self.lib_directory, 'Bookmark.py')):
   937             self.info('loading %s', filepath)
   938             self.info('loading %s', filepath)
   938             self.handle_file(filepath)
   939             self.handle_file(filepath)
   939         for cube in cubes:
   940         for cube in cubes:
   940             for filepath in self.get_schema_files(cube):
   941             for filepath in self.get_schema_files(cube):
   941                 self.info('loading %s', filepath)
   942                 self.info('loading %s', filepath)