cubicweb/server/repository.py
changeset 12508 a8c1ea390400
parent 12240 8eb15566142f
child 12542 85194bd49119
equal deleted inserted replaced
12507:211472ab15c8 12508:a8c1ea390400
    34 from logging import getLogger
    34 from logging import getLogger
    35 
    35 
    36 from six.moves import range, queue
    36 from six.moves import range, queue
    37 
    37 
    38 from logilab.common.decorators import cached, clear_cache
    38 from logilab.common.decorators import cached, clear_cache
    39 from logilab.common.deprecation import deprecated
       
    40 
    39 
    41 from yams import BadSchemaDefinition
    40 from yams import BadSchemaDefinition
    42 from rql.utils import rqlvar_maker
    41 from rql.utils import rqlvar_maker
    43 
    42 
    44 from cubicweb import (CW_MIGRATION_MAP,
    43 from cubicweb import (CW_MIGRATION_MAP,
   321         mapping = {'system': self.system_source}
   320         mapping = {'system': self.system_source}
   322         mapping.update((sourceent.name, source)
   321         mapping.update((sourceent.name, source)
   323                        for sourceent, source in self._sources())
   322                        for sourceent, source in self._sources())
   324         return mapping
   323         return mapping
   325 
   324 
   326     @property
       
   327     @deprecated("[3.25] use source_by_eid(<eid>)")
       
   328     def sources_by_eid(self):
       
   329         mapping = {self.system_source.eid: self.system_source}
       
   330         mapping.update((sourceent.eid, source)
       
   331                        for sourceent, source in self._sources())
       
   332         return mapping
       
   333 
       
   334     def _sources(self):
   325     def _sources(self):
   335         if self.config.quick_start:
   326         if self.config.quick_start:
   336             return
   327             return
   337         with self.internal_cnx() as cnx:
   328         with self.internal_cnx() as cnx:
   338             for sourceent in cnx.execute(
   329             for sourceent in cnx.execute(
   514         assert len(rset) == 1, rset
   505         assert len(rset) == 1, rset
   515         return rset.get_entity(0, 0)
   506         return rset.get_entity(0, 0)
   516 
   507 
   517     # public (dbapi) interface ################################################
   508     # public (dbapi) interface ################################################
   518 
   509 
   519     @deprecated("[3.19] use _cw.call_service('repo_stats')")
       
   520     def stats(self):  # XXX restrict to managers session?
       
   521         """Return a dictionary containing some statistics about the repository
       
   522         resources usage.
       
   523 
       
   524         This is a public method, not requiring a session id.
       
   525 
       
   526         This method is deprecated in favor of using _cw.call_service('repo_stats')
       
   527         """
       
   528         with self.internal_cnx() as cnx:
       
   529             return cnx.call_service('repo_stats')
       
   530 
       
   531     @deprecated("[3.19] use _cw.call_service('repo_gc_stats')")
       
   532     def gc_stats(self, nmax=20):
       
   533         """Return a dictionary containing some statistics about the repository
       
   534         memory usage.
       
   535 
       
   536         This is a public method, not requiring a session id.
       
   537 
       
   538         nmax is the max number of (most) referenced object returned as
       
   539         the 'referenced' result
       
   540         """
       
   541         with self.internal_cnx() as cnx:
       
   542             return cnx.call_service('repo_gc_stats', nmax=nmax)
       
   543 
       
   544     def get_schema(self):
   510     def get_schema(self):
   545         """Return the instance schema.
   511         """Return the instance schema.
   546 
   512 
   547         This is a public method, not requiring a session id.
   513         This is a public method, not requiring a session id.
   548         """
   514         """
   559                                           or self.config.mode == 'test'))
   525                                           or self.config.mode == 'test'))
   560         cubes = list(versions)
   526         cubes = list(versions)
   561         cubes.remove('cubicweb')
   527         cubes.remove('cubicweb')
   562         return cubes
   528         return cubes
   563 
   529 
   564     def get_option_value(self, option, foreid=None):
   530     def get_option_value(self, option):
   565         """Return the value for `option` in the configuration.
   531         """Return the value for `option` in the configuration.
   566 
   532 
   567         This is a public method, not requiring a session id.
   533         This is a public method, not requiring a session id.
   568 
   534         """
   569         `foreid` argument is deprecated and now useless (as of 3.19).
       
   570         """
       
   571         if foreid is not None:
       
   572             warn('[3.19] foreid argument is deprecated', DeprecationWarning,
       
   573                  stacklevel=2)
       
   574         # XXX we may want to check we don't give sensible information
   535         # XXX we may want to check we don't give sensible information
   575         return self.config[option]
   536         return self.config[option]
   576 
   537 
   577     @cached
   538     @cached
   578     def get_versions(self, checkversions=False):
   539     def get_versions(self, checkversions=False):
   628         with self.internal_cnx() as cnx:
   589         with self.internal_cnx() as cnx:
   629             # don't use cnx.execute, we don't want rset.req set
   590             # don't use cnx.execute, we don't want rset.req set
   630             return self.querier.execute(cnx, 'Any K,V WHERE P is CWProperty,'
   591             return self.querier.execute(cnx, 'Any K,V WHERE P is CWProperty,'
   631                                         'P pkey K, P value V, NOT P for_user U',
   592                                         'P pkey K, P value V, NOT P for_user U',
   632                                         build_descr=False)
   593                                         build_descr=False)
   633 
       
   634     @deprecated("[3.19] Use session.call_service('register_user') instead'")
       
   635     def register_user(self, login, password, email=None, **kwargs):
       
   636         """check a user with the given login exists, if not create it with the
       
   637         given password. This method is designed to be used for anonymous
       
   638         registration on public web site.
       
   639         """
       
   640         with self.internal_cnx() as cnx:
       
   641             cnx.call_service('register_user', login=login, password=password,
       
   642                              email=email, **kwargs)
       
   643             cnx.commit()
       
   644 
   594 
   645     def find_users(self, fetch_attrs, **query_attrs):
   595     def find_users(self, fetch_attrs, **query_attrs):
   646         """yield user attributes for cwusers matching the given query_attrs
   596         """yield user attributes for cwusers matching the given query_attrs
   647         (the result set cannot survive this method call)
   597         (the result set cannot survive this method call)
   648 
   598