server/repository.py
branchstable
changeset 6256 da77d3f95079
parent 6211 e9d125fd1465
child 6257 7eb5f1aed728
equal deleted inserted replaced
6255:e2d51d6ba654 6256:da77d3f95079
   408         return cwuser
   408         return cwuser
   409 
   409 
   410     # public (dbapi) interface ################################################
   410     # public (dbapi) interface ################################################
   411 
   411 
   412     def stats(self): # XXX restrict to managers session?
   412     def stats(self): # XXX restrict to managers session?
       
   413         """Return a dictionary containing some statistics about the repository
       
   414         resources usage.
       
   415 
       
   416         This is a public method, not requiring a session id.
       
   417         """
   413         results = {}
   418         results = {}
   414         querier = self.querier
   419         querier = self.querier
   415         source = self.system_source
   420         source = self.system_source
   416         for size, maxsize, hits, misses, title in (
   421         for size, maxsize, hits, misses, title in (
   417             (len(querier._rql_cache), self.config['rql-cache-size'],
   422             (len(querier._rql_cache), self.config['rql-cache-size'],
   430         results['available_pools'] = self._available_pools.qsize()
   435         results['available_pools'] = self._available_pools.qsize()
   431         results['threads'] = ', '.join(sorted(str(t) for t in threading.enumerate()))
   436         results['threads'] = ', '.join(sorted(str(t) for t in threading.enumerate()))
   432         return results
   437         return results
   433 
   438 
   434     def get_schema(self):
   439     def get_schema(self):
   435         """return the instance schema. This is a public method, not
   440         """Return the instance schema.
   436         requiring a session id
   441 
       
   442         This is a public method, not requiring a session id.
   437         """
   443         """
   438         try:
   444         try:
   439             # necessary to support pickling used by pyro
   445             # necessary to support pickling used by pyro
   440             self.schema.__hashmode__ = 'pickle'
   446             self.schema.__hashmode__ = 'pickle'
   441             return self.schema
   447             return self.schema
   442         finally:
   448         finally:
   443             self.schema.__hashmode__ = None
   449             self.schema.__hashmode__ = None
   444 
   450 
   445     def get_cubes(self):
   451     def get_cubes(self):
   446         """return the list of cubes used by this instance. This is a
   452         """Return the list of cubes used by this instance.
   447         public method, not requiring a session id.
   453 
       
   454         This is a public method, not requiring a session id.
   448         """
   455         """
   449         versions = self.get_versions(not (self.config.creating
   456         versions = self.get_versions(not (self.config.creating
   450                                           or self.config.repairing
   457                                           or self.config.repairing
   451                                           or self.config.quick_start
   458                                           or self.config.quick_start
   452                                           or self.config.mode == 'test'))
   459                                           or self.config.mode == 'test'))
   454         cubes.remove('cubicweb')
   461         cubes.remove('cubicweb')
   455         return cubes
   462         return cubes
   456 
   463 
   457     @cached
   464     @cached
   458     def get_versions(self, checkversions=False):
   465     def get_versions(self, checkversions=False):
   459         """return the a dictionary containing cubes used by this instance
   466         """Return the a dictionary containing cubes used by this instance
   460         as key with their version as value, including cubicweb version. This is a
   467         as key with their version as value, including cubicweb version.
   461         public method, not requiring a session id.
   468 
       
   469         This is a public method, not requiring a session id.
   462         """
   470         """
   463         from logilab.common.changelog import Version
   471         from logilab.common.changelog import Version
   464         vcconf = {}
   472         vcconf = {}
   465         session = self.internal_session()
   473         session = self.internal_session()
   466         try:
   474         try:
   486             session.close()
   494             session.close()
   487         return vcconf
   495         return vcconf
   488 
   496 
   489     @cached
   497     @cached
   490     def source_defs(self):
   498     def source_defs(self):
       
   499         """Return the a dictionary containing source uris as value and a
       
   500         dictionary describing each source as value.
       
   501 
       
   502         This is a public method, not requiring a session id.
       
   503         """
   491         sources = self.config.sources().copy()
   504         sources = self.config.sources().copy()
   492         # remove manager information
   505         # remove manager information
   493         sources.pop('admin', None)
   506         sources.pop('admin', None)
   494         # remove sensitive information
   507         # remove sensitive information
   495         for uri, sourcedef in sources.iteritems():
   508         for uri, sourcedef in sources.iteritems():
   497             self.sources_by_uri[uri].remove_sensitive_information(sourcedef)
   510             self.sources_by_uri[uri].remove_sensitive_information(sourcedef)
   498             sources[uri] = sourcedef
   511             sources[uri] = sourcedef
   499         return sources
   512         return sources
   500 
   513 
   501     def properties(self):
   514     def properties(self):
   502         """return a result set containing system wide properties"""
   515         """Return a result set containing system wide properties.
       
   516 
       
   517         This is a public method, not requiring a session id.
       
   518         """
   503         session = self.internal_session()
   519         session = self.internal_session()
   504         try:
   520         try:
   505             # don't use session.execute, we don't want rset.req set
   521             # don't use session.execute, we don't want rset.req set
   506             return self.querier.execute(session, 'Any K,V WHERE P is CWProperty,'
   522             return self.querier.execute(session, 'Any K,V WHERE P is CWProperty,'
   507                                         'P pkey K, P value V, NOT P for_user U',
   523                                         'P pkey K, P value V, NOT P for_user U',