server/serverconfig.py
changeset 6333 e3994fcc21c3
parent 6139 f76599a96238
parent 6299 51a9494b5efb
child 6427 c8a5ac2d1eaa
equal deleted inserted replaced
6293:df44d7163582 6333:e3994fcc21c3
    43                   'level': 0,
    43                   'level': 0,
    44                   }),
    44                   }),
    45     )
    45     )
    46 
    46 
    47 class SourceConfiguration(Configuration):
    47 class SourceConfiguration(Configuration):
    48     def __init__(self, appid, options):
    48     def __init__(self, appconfig, options):
    49         self.appid = appid # has to be done before super call
    49         self.appconfig = appconfig # has to be done before super call
    50         super(SourceConfiguration, self).__init__(options=options)
    50         super(SourceConfiguration, self).__init__(options=options)
    51 
    51 
    52     # make Method('default_instance_id') usable in db option defs (in native.py)
    52     # make Method('default_instance_id') usable in db option defs (in native.py)
    53     def default_instance_id(self):
    53     def default_instance_id(self):
    54         return self.appid
    54         return self.appconfig.appid
    55 
    55 
    56 def generate_sources_file(appid, sourcesfile, sourcescfg, keys=None):
    56     def input_option(self, option, optdict, inputlevel):
       
    57         if self['db-driver'] == 'sqlite':
       
    58             if option in ('db-user', 'db-password'):
       
    59                 return
       
    60             if option == 'db-name':
       
    61                 optdict = optdict.copy()
       
    62                 optdict['help'] = 'path to the sqlite database'
       
    63                 optdict['default'] = join(self.appconfig.appdatahome,
       
    64                                           self.appconfig.appid + '.sqlite')
       
    65         super(SourceConfiguration, self).input_option(option, optdict, inputlevel)
       
    66 
       
    67 
       
    68 def generate_sources_file(appconfig, sourcesfile, sourcescfg, keys=None):
    57     """serialize repository'sources configuration into a INI like file
    69     """serialize repository'sources configuration into a INI like file
    58 
    70 
    59     the `keys` parameter may be used to sort sections
    71     the `keys` parameter may be used to sort sections
    60     """
    72     """
    61     if keys is None:
    73     if keys is None:
    71             # get a Configuration object
    83             # get a Configuration object
    72             if uri == 'admin':
    84             if uri == 'admin':
    73                 options = USER_OPTIONS
    85                 options = USER_OPTIONS
    74             else:
    86             else:
    75                 options = SOURCE_TYPES[sconfig['adapter']].options
    87                 options = SOURCE_TYPES[sconfig['adapter']].options
    76             _sconfig = SourceConfiguration(appid, options=options)
    88             _sconfig = SourceConfiguration(appconfig, options=options)
    77             for attr, val in sconfig.items():
    89             for attr, val in sconfig.items():
    78                 if attr == 'uri':
    90                 if attr == 'uri':
    79                     continue
    91                     continue
    80                 if attr == 'adapter':
    92                 if attr == 'adapter':
    81                     _sconfig.adapter = val
    93                     _sconfig.adapter = val
   276     def write_sources_file(self, sourcescfg):
   288     def write_sources_file(self, sourcescfg):
   277         sourcesfile = self.sources_file()
   289         sourcesfile = self.sources_file()
   278         if exists(sourcesfile):
   290         if exists(sourcesfile):
   279             import shutil
   291             import shutil
   280             shutil.copy(sourcesfile, sourcesfile + '.bak')
   292             shutil.copy(sourcesfile, sourcesfile + '.bak')
   281         generate_sources_file(self.appid, sourcesfile, sourcescfg,
   293         generate_sources_file(self, sourcesfile, sourcescfg,
   282                               ['admin', 'system'])
   294                               ['admin', 'system'])
   283         restrict_perms_to_user(sourcesfile)
   295         restrict_perms_to_user(sourcesfile)
   284 
   296 
   285     def pyro_enabled(self):
   297     def pyro_enabled(self):
   286         """pyro is always enabled in standalone repository configuration"""
   298         """pyro is always enabled in standalone repository configuration"""