3 The repository is an abstraction allowing execution of rql queries against |
3 The repository is an abstraction allowing execution of rql queries against |
4 data sources. Most of the work is actually done in helper classes. The |
4 data sources. Most of the work is actually done in helper classes. The |
5 repository mainly: |
5 repository mainly: |
6 |
6 |
7 * brings these classes all together to provide a single access |
7 * brings these classes all together to provide a single access |
8 point to a cubicweb application. |
8 point to a cubicweb instance. |
9 * handles session management |
9 * handles session management |
10 * provides method for pyro registration, to call if pyro is enabled |
10 * provides method for pyro registration, to call if pyro is enabled |
11 |
11 |
12 |
12 |
13 :organization: Logilab |
13 :organization: Logilab |
177 # create the hooks manager |
177 # create the hooks manager |
178 self.hm = HooksManager(self.schema) |
178 self.hm = HooksManager(self.schema) |
179 # open some connections pools |
179 # open some connections pools |
180 self._available_pools = Queue.Queue() |
180 self._available_pools = Queue.Queue() |
181 self._available_pools.put_nowait(ConnectionsPool(self.sources)) |
181 self._available_pools.put_nowait(ConnectionsPool(self.sources)) |
182 if config.read_application_schema: |
182 if config.read_instance_schema: |
183 # normal start: load the application schema from the database |
183 # normal start: load the instance schema from the database |
184 self.fill_schema() |
184 self.fill_schema() |
185 elif config.bootstrap_schema: |
185 elif config.bootstrap_schema: |
186 # usually during repository creation |
186 # usually during repository creation |
187 self.warning("set fs application'schema as bootstrap schema") |
187 self.warning("set fs instance'schema as bootstrap schema") |
188 config.bootstrap_cubes() |
188 config.bootstrap_cubes() |
189 self.set_bootstrap_schema(self.config.load_schema()) |
189 self.set_bootstrap_schema(self.config.load_schema()) |
190 # need to load the Any and CWUser entity types |
190 # need to load the Any and CWUser entity types |
191 self.vreg.schema = self.schema |
191 self.vreg.schema = self.schema |
192 etdirectory = join(CW_SOFTWARE_ROOT, 'entities') |
192 etdirectory = join(CW_SOFTWARE_ROOT, 'entities') |
195 'cubicweb.entities.__init__') |
195 'cubicweb.entities.__init__') |
196 self.vreg.load_file(join(etdirectory, 'authobjs.py'), |
196 self.vreg.load_file(join(etdirectory, 'authobjs.py'), |
197 'cubicweb.entities.authobjs') |
197 'cubicweb.entities.authobjs') |
198 else: |
198 else: |
199 # test start: use the file system schema (quicker) |
199 # test start: use the file system schema (quicker) |
200 self.warning("set fs application'schema") |
200 self.warning("set fs instance'schema") |
201 config.bootstrap_cubes() |
201 config.bootstrap_cubes() |
202 self.set_schema(self.config.load_schema()) |
202 self.set_schema(self.config.load_schema()) |
203 if not config.creating: |
203 if not config.creating: |
204 if 'CWProperty' in self.schema: |
204 if 'CWProperty' in self.schema: |
205 self.vreg.init_properties(self.properties()) |
205 self.vreg.init_properties(self.properties()) |
245 # full reload of all appobjects |
245 # full reload of all appobjects |
246 self.vreg.reset() |
246 self.vreg.reset() |
247 self.vreg.set_schema(schema) |
247 self.vreg.set_schema(schema) |
248 self.hm.set_schema(schema) |
248 self.hm.set_schema(schema) |
249 self.hm.register_system_hooks(self.config) |
249 self.hm.register_system_hooks(self.config) |
250 # application specific hooks |
250 # instance specific hooks |
251 if self.config.application_hooks: |
251 if self.config.instance_hooks: |
252 self.info('loading application hooks') |
252 self.info('loading instance hooks') |
253 self.hm.register_hooks(self.config.load_hooks(self.vreg)) |
253 self.hm.register_hooks(self.config.load_hooks(self.vreg)) |
254 |
254 |
255 def fill_schema(self): |
255 def fill_schema(self): |
256 """lod schema from the repository""" |
256 """lod schema from the repository""" |
257 from cubicweb.server.schemaserial import deserialize_schema |
257 from cubicweb.server.schemaserial import deserialize_schema |
295 # XXX refactor |
295 # XXX refactor |
296 config.core_hooks = False |
296 config.core_hooks = False |
297 config.usergroup_hooks = False |
297 config.usergroup_hooks = False |
298 config.schema_hooks = False |
298 config.schema_hooks = False |
299 config.notification_hooks = False |
299 config.notification_hooks = False |
300 config.application_hooks = False |
300 config.instance_hooks = False |
301 self.set_schema(schema, resetvreg=False) |
301 self.set_schema(schema, resetvreg=False) |
302 config.core_hooks = True |
302 config.core_hooks = True |
303 config.usergroup_hooks = True |
303 config.usergroup_hooks = True |
304 config.schema_hooks = True |
304 config.schema_hooks = True |
305 config.notification_hooks = True |
305 config.notification_hooks = True |
306 config.application_hooks = True |
306 config.instance_hooks = True |
307 |
307 |
308 def start_looping_tasks(self): |
308 def start_looping_tasks(self): |
309 assert isinstance(self._looping_tasks, list), 'already started' |
309 assert isinstance(self._looping_tasks, list), 'already started' |
310 for i, (interval, func) in enumerate(self._looping_tasks): |
310 for i, (interval, func) in enumerate(self._looping_tasks): |
311 self._looping_tasks[i] = task = LoopTask(interval, func) |
311 self._looping_tasks[i] = task = LoopTask(interval, func) |
439 return cwuser |
439 return cwuser |
440 |
440 |
441 # public (dbapi) interface ################################################ |
441 # public (dbapi) interface ################################################ |
442 |
442 |
443 def get_schema(self): |
443 def get_schema(self): |
444 """return the application schema. This is a public method, not |
444 """return the instance schema. This is a public method, not |
445 requiring a session id |
445 requiring a session id |
446 """ |
446 """ |
447 try: |
447 try: |
448 # necessary to support pickling used by pyro |
448 # necessary to support pickling used by pyro |
449 self.schema.__hashmode__ = 'pickle' |
449 self.schema.__hashmode__ = 'pickle' |
450 return self.schema |
450 return self.schema |
451 finally: |
451 finally: |
452 self.schema.__hashmode__ = None |
452 self.schema.__hashmode__ = None |
453 |
453 |
454 def get_cubes(self): |
454 def get_cubes(self): |
455 """return the list of cubes used by this application. This is a |
455 """return the list of cubes used by this instance. This is a |
456 public method, not requiring a session id. |
456 public method, not requiring a session id. |
457 """ |
457 """ |
458 versions = self.get_versions(not (self.config.creating |
458 versions = self.get_versions(not (self.config.creating |
459 or self.config.repairing)) |
459 or self.config.repairing)) |
460 cubes = list(versions) |
460 cubes = list(versions) |
461 cubes.remove('cubicweb') |
461 cubes.remove('cubicweb') |
462 return cubes |
462 return cubes |
463 |
463 |
464 @cached |
464 @cached |
465 def get_versions(self, checkversions=False): |
465 def get_versions(self, checkversions=False): |
466 """return the a dictionary containing cubes used by this application |
466 """return the a dictionary containing cubes used by this instance |
467 as key with their version as value, including cubicweb version. This is a |
467 as key with their version as value, including cubicweb version. This is a |
468 public method, not requiring a session id. |
468 public method, not requiring a session id. |
469 """ |
469 """ |
470 from logilab.common.changelog import Version |
470 from logilab.common.changelog import Version |
471 vcconf = {} |
471 vcconf = {} |
484 if cube != 'cubicweb': |
484 if cube != 'cubicweb': |
485 fsversion = self.config.cube_version(cube) |
485 fsversion = self.config.cube_version(cube) |
486 else: |
486 else: |
487 fsversion = self.config.cubicweb_version() |
487 fsversion = self.config.cubicweb_version() |
488 if version < fsversion: |
488 if version < fsversion: |
489 msg = ('application has %s version %s but %s ' |
489 msg = ('instance has %s version %s but %s ' |
490 'is installed. Run "cubicweb-ctl upgrade".') |
490 'is installed. Run "cubicweb-ctl upgrade".') |
491 raise ExecutionError(msg % (cube, version, fsversion)) |
491 raise ExecutionError(msg % (cube, version, fsversion)) |
492 finally: |
492 finally: |
493 session.close() |
493 session.close() |
494 return vcconf |
494 return vcconf |