server/serverconfig.py
changeset 6139 f76599a96238
parent 6012 d56fd78006cd
parent 6128 fbb8398f80dc
child 6333 e3994fcc21c3
equal deleted inserted replaced
6102:27c47d239739 6139:f76599a96238
    21 
    21 
    22 from os.path import join, exists
    22 from os.path import join, exists
    23 
    23 
    24 from logilab.common.configuration import REQUIRED, Method, Configuration, \
    24 from logilab.common.configuration import REQUIRED, Method, Configuration, \
    25      ini_format_section
    25      ini_format_section
    26 from logilab.common.decorators import wproperty, cached, clear_cache
    26 from logilab.common.decorators import wproperty, cached
    27 
    27 
    28 from cubicweb.toolsutils import read_config, restrict_perms_to_user
    28 from cubicweb.toolsutils import read_config, restrict_perms_to_user
    29 from cubicweb.cwconfig import CubicWebConfiguration, merge_options
    29 from cubicweb.cwconfig import CubicWebConfiguration, merge_options
    30 from cubicweb.server import SOURCE_TYPES
    30 from cubicweb.server import SOURCE_TYPES
    31 
    31 
   160           'group': 'main', 'level': 3,
   160           'group': 'main', 'level': 3,
   161           }),
   161           }),
   162         ('multi-sources-etypes',
   162         ('multi-sources-etypes',
   163          {'type' : 'csv', 'default': (),
   163          {'type' : 'csv', 'default': (),
   164           'help': 'defines which entity types from this repository are used \
   164           'help': 'defines which entity types from this repository are used \
   165 by some other instances. You should set this properly so those instances to \
   165 by some other instances. You should set this properly for these instances to \
   166 detect updates / deletions.',
   166 detect updates / deletions.',
   167           'group': 'main', 'level': 3,
   167           'group': 'main', 'level': 3,
   168           }),
   168           }),
   169 
   169 
   170         ('delay-full-text-indexation',
   170         ('delay-full-text-indexation',
   231     # should some hooks be deactivated during [pre|post]create script execution
   231     # should some hooks be deactivated during [pre|post]create script execution
   232     free_wheel = False
   232     free_wheel = False
   233 
   233 
   234     # list of enables sources when sources restriction is necessary
   234     # list of enables sources when sources restriction is necessary
   235     # (eg repository initialization at least)
   235     # (eg repository initialization at least)
   236     _enabled_sources = None
   236     enabled_sources = None
   237     @wproperty
       
   238     def enabled_sources(self, sourceuris=None):
       
   239         self._enabled_sources = sourceuris
       
   240         clear_cache(self, 'sources')
       
   241 
   237 
   242     def bootstrap_cubes(self):
   238     def bootstrap_cubes(self):
   243         from logilab.common.textutils import splitstrip
   239         from logilab.common.textutils import splitstrip
   244         for line in file(join(self.apphome, 'bootstrap_cubes')):
   240         for line in file(join(self.apphome, 'bootstrap_cubes')):
   245             line = line.strip()
   241             line = line.strip()
   270 
   266 
   271     def sources(self):
   267     def sources(self):
   272         """return a dictionnaries containing sources definitions indexed by
   268         """return a dictionnaries containing sources definitions indexed by
   273         sources'uri
   269         sources'uri
   274         """
   270         """
   275         allsources = self.read_sources_file()
   271         return self.read_sources_file()
   276         if self._enabled_sources is None:
   272 
   277             return allsources
   273     def source_enabled(self, uri):
   278         return dict((uri, config) for uri, config in allsources.items()
   274         return not self.enabled_sources or uri in self.enabled_sources
   279                     if uri in self._enabled_sources or uri == 'admin')
       
   280 
   275 
   281     def write_sources_file(self, sourcescfg):
   276     def write_sources_file(self, sourcescfg):
   282         sourcesfile = self.sources_file()
   277         sourcesfile = self.sources_file()
   283         if exists(sourcesfile):
   278         if exists(sourcesfile):
   284             import shutil
   279             import shutil
   329         else:
   324         else:
   330             known_sources = self.sources()
   325             known_sources = self.sources()
   331             for uri in sources:
   326             for uri in sources:
   332                 assert uri in known_sources, uri
   327                 assert uri in known_sources, uri
   333             enabled_sources = sources
   328             enabled_sources = sources
   334         self._enabled_sources = enabled_sources
   329         self.enabled_sources = enabled_sources
   335         clear_cache(self, 'sources')
       
   336 
   330 
   337     def migration_handler(self, schema=None, interactive=True,
   331     def migration_handler(self, schema=None, interactive=True,
   338                           cnx=None, repo=None, connect=True, verbosity=None):
   332                           cnx=None, repo=None, connect=True, verbosity=None):
   339         """return a migration handler instance"""
   333         """return a migration handler instance"""
   340         from cubicweb.server.migractions import ServerMigrationHelper
   334         from cubicweb.server.migractions import ServerMigrationHelper