server/serverconfig.py
branchstable
changeset 3904 dc7d315165fc
parent 3900 a26f50cb7e70
child 3905 8117ffd92e6a
equal deleted inserted replaced
3903:7967d3766ecf 3904:dc7d315165fc
    32                   'help': "cubicweb manager account's password",
    32                   'help': "cubicweb manager account's password",
    33                   'inputlevel': 0,
    33                   'inputlevel': 0,
    34                   }),
    34                   }),
    35     )
    35     )
    36 
    36 
    37 def generate_sources_file(sourcesfile, sourcescfg, keys=None):
    37 class SourceConfiguration(Configuration):
       
    38     def __init__(self, appid, options):
       
    39         super(SourceConfiguration, self).__init__(options=options)
       
    40         self.appid = appid
       
    41 
       
    42     # make Method('default_instance_id') usable in db option defs (in native.py)
       
    43     def default_instance_id
       
    44         return self.appid
       
    45 
       
    46 def generate_sources_file(appid, sourcesfile, sourcescfg, keys=None):
    38     """serialize repository'sources configuration into a INI like file
    47     """serialize repository'sources configuration into a INI like file
    39 
    48 
    40     the `keys` parameter may be used to sort sections
    49     the `keys` parameter may be used to sort sections
    41     """
    50     """
    42     if keys is None:
    51     if keys is None:
    52             # get a Configuration object
    61             # get a Configuration object
    53             if uri == 'admin':
    62             if uri == 'admin':
    54                 options = USER_OPTIONS
    63                 options = USER_OPTIONS
    55             else:
    64             else:
    56                 options = SOURCE_TYPES[sconfig['adapter']].options
    65                 options = SOURCE_TYPES[sconfig['adapter']].options
    57             _sconfig = Configuration(options=options)
    66             _sconfig = SourceConfiguration(appid, options=options)
    58             for attr, val in sconfig.items():
    67             for attr, val in sconfig.items():
    59                 if attr == 'uri':
    68                 if attr == 'uri':
    60                     continue
    69                     continue
    61                 if attr == 'adapter':
    70                 if attr == 'adapter':
    62                     _sconfig.adapter = val
    71                     _sconfig.adapter = val
   240     def write_sources_file(self, sourcescfg):
   249     def write_sources_file(self, sourcescfg):
   241         sourcesfile = self.sources_file()
   250         sourcesfile = self.sources_file()
   242         if exists(sourcesfile):
   251         if exists(sourcesfile):
   243             import shutil
   252             import shutil
   244             shutil.copy(sourcesfile, sourcesfile + '.bak')
   253             shutil.copy(sourcesfile, sourcesfile + '.bak')
   245         generate_sources_file(sourcesfile, sourcescfg, ['admin', 'system'])
   254         generate_sources_file(self.appid, sourcesfile, sourcescfg,
       
   255                               ['admin', 'system'])
   246         restrict_perms_to_user(sourcesfile)
   256         restrict_perms_to_user(sourcesfile)
   247 
   257 
   248     def pyro_enabled(self):
   258     def pyro_enabled(self):
   249         """pyro is always enabled in standalone repository configuration"""
   259         """pyro is always enabled in standalone repository configuration"""
   250         return True
   260         return True