goa/dbmyams.py
changeset 2730 bb6fcb8c5d71
parent 2476 1294a6bdf3bf
child 2735 39c942241b48
equal deleted inserted replaced
2729:d3dbd135f319 2730:bb6fcb8c5d71
   158         return self._live_handlers['.py']
   158         return self._live_handlers['.py']
   159 
   159 
   160 import os
   160 import os
   161 from cubicweb import CW_SOFTWARE_ROOT
   161 from cubicweb import CW_SOFTWARE_ROOT
   162 
   162 
   163 if os.environ.get('APYCOT_ROOT'):
       
   164     SCHEMAS_LIB_DIRECTORY = join(os.environ['APYCOT_ROOT'],
       
   165                                  'local', 'share', 'cubicweb', 'schemas')
       
   166 else:
       
   167     SCHEMAS_LIB_DIRECTORY = join(CW_SOFTWARE_ROOT, 'schemas')
       
   168 
       
   169 def load_schema(config, schemaclasses=None, extrahook=None):
   163 def load_schema(config, schemaclasses=None, extrahook=None):
   170     """high level method to load all the schema for a lax instance"""
   164     """high level method to load all the schema for a lax instance"""
   171     # IMPORTANT NOTE: dbmodel schemas must be imported **BEFORE**
   165     # IMPORTANT NOTE: dbmodel schemas must be imported **BEFORE**
   172     # the loader is instantiated because this is where the dbmodels
   166     # the loader is instantiated because this is where the dbmodels
   173     # are registered in the yams schema
   167     # are registered in the yams schema
   174     for compname in config['included-cubes']:
   168     for compname in config['included-cubes']:
   175         __import__('%s.schema' % compname)
   169         __import__('%s.schema' % compname)
   176     loader = GaeSchemaLoader(use_gauthservice=config['use-google-auth'], db=db)
   170     loader = GaeSchemaLoader(use_gauthservice=config['use-google-auth'], db=db)
   177     loader.lib_directory = SCHEMAS_LIB_DIRECTORY
   171     loader.lib_directory = join(CW_SOFTWARE_ROOT, 'schemas')
   178     if schemaclasses is not None:
   172     if schemaclasses is not None:
   179         for cls in schemaclasses:
   173         for cls in schemaclasses:
   180             loader.load_dbmodel(cls.__name__, goadb.extract_dbmodel(cls))
   174             loader.load_dbmodel(cls.__name__, goadb.extract_dbmodel(cls))
   181     elif config['schema-type'] == 'dbmodel':
   175     elif config['schema-type'] == 'dbmodel':
   182         import schema as appschema
   176         import schema as appschema
   186     for erschema in ('CWGroup', 'CWEType', 'CWRType', 'RQLExpression',
   180     for erschema in ('CWGroup', 'CWEType', 'CWRType', 'RQLExpression',
   187                      'is_', 'is_instance_of',
   181                      'is_', 'is_instance_of',
   188                      'read_permission', 'add_permission',
   182                      'read_permission', 'add_permission',
   189                      'delete_permission', 'update_permission'):
   183                      'delete_permission', 'update_permission'):
   190         loader.import_yams_schema(erschema, 'bootstrap')
   184         loader.import_yams_schema(erschema, 'bootstrap')
   191     loader.handle_file(join(SCHEMAS_LIB_DIRECTORY, 'base.py'))
   185     loader.handle_file(join(CW_SOFTWARE_ROOT, 'schemas', 'base.py'))
   192     cubes = config['included-yams-cubes']
   186     cubes = config['included-yams-cubes']
   193     for cube in reversed(config.expand_cubes(cubes)):
   187     for cube in reversed(config.expand_cubes(cubes)):
   194         config.info('loading cube %s', cube)
   188         config.info('loading cube %s', cube)
   195         loader.import_yams_cube_schema(config.cube_dir(cube))
   189         loader.import_yams_cube_schema(config.cube_dir(cube))
   196     if config['schema-type'] == 'yams':
   190     if config['schema-type'] == 'yams':