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 |
270 def write_sources_file(self, sourcescfg): |
282 def write_sources_file(self, sourcescfg): |
271 sourcesfile = self.sources_file() |
283 sourcesfile = self.sources_file() |
272 if exists(sourcesfile): |
284 if exists(sourcesfile): |
273 import shutil |
285 import shutil |
274 shutil.copy(sourcesfile, sourcesfile + '.bak') |
286 shutil.copy(sourcesfile, sourcesfile + '.bak') |
275 generate_sources_file(self.appid, sourcesfile, sourcescfg, |
287 generate_sources_file(self, sourcesfile, sourcescfg, |
276 ['admin', 'system']) |
288 ['admin', 'system']) |
277 restrict_perms_to_user(sourcesfile) |
289 restrict_perms_to_user(sourcesfile) |
278 |
290 |
279 def pyro_enabled(self): |
291 def pyro_enabled(self): |
280 """pyro is always enabled in standalone repository configuration""" |
292 """pyro is always enabled in standalone repository configuration""" |