26 import os |
26 import os |
27 import logging |
27 import logging |
28 import subprocess |
28 import subprocess |
29 |
29 |
30 from logilab.common import nullobject |
30 from logilab.common import nullobject |
31 from logilab.common.configuration import Configuration |
31 from logilab.common.configuration import Configuration, merge_options |
32 from logilab.common.shellutils import ASK, generate_password |
32 from logilab.common.shellutils import ASK, generate_password |
33 |
33 |
34 from cubicweb import AuthenticationError, ExecutionError, ConfigurationError |
34 from cubicweb import AuthenticationError, ExecutionError, ConfigurationError |
35 from cubicweb.toolsutils import Command, CommandHandler, underline_title |
35 from cubicweb.toolsutils import Command, CommandHandler, underline_title |
36 from cubicweb.cwctl import CWCTL, check_options_consistency |
36 from cubicweb.cwctl import CWCTL, check_options_consistency, ConfigureInstanceCommand |
37 from cubicweb.server import SOURCE_TYPES |
37 from cubicweb.server import SOURCE_TYPES |
38 from cubicweb.server.repository import Repository |
38 from cubicweb.server.repository import Repository |
39 from cubicweb.server.serverconfig import ( |
39 from cubicweb.server.serverconfig import ( |
40 USER_OPTIONS, ServerConfiguration, SourceConfiguration, |
40 USER_OPTIONS, ServerConfiguration, SourceConfiguration, |
41 ask_source_config, generate_source_config) |
41 ask_source_config, generate_source_config) |
1094 DBDumpCommand, DBRestoreCommand, DBCopyCommand, |
1094 DBDumpCommand, DBRestoreCommand, DBCopyCommand, |
1095 AddSourceCommand, CheckRepositoryCommand, RebuildFTICommand, |
1095 AddSourceCommand, CheckRepositoryCommand, RebuildFTICommand, |
1096 SynchronizeInstanceSchemaCommand, SynchronizeSourceCommand, SchemaDiffCommand, |
1096 SynchronizeInstanceSchemaCommand, SynchronizeSourceCommand, SchemaDiffCommand, |
1097 ): |
1097 ): |
1098 CWCTL.register(cmdclass) |
1098 CWCTL.register(cmdclass) |
|
1099 |
|
1100 # extend configure command to set options in sources config file ############### |
|
1101 |
|
1102 db_options = ( |
|
1103 ('db', |
|
1104 {'short': 'd', 'type' : 'named', 'metavar' : 'key1:value1,key2:value2', |
|
1105 'default': None, |
|
1106 'help': 'set <key> to <value> in "source" configuration file.', |
|
1107 }), |
|
1108 ) |
|
1109 |
|
1110 ConfigureInstanceCommand.options = merge_options( |
|
1111 ConfigureInstanceCommand.options + db_options) |
|
1112 |
|
1113 configure_instance = ConfigureInstanceCommand.configure_instance |
|
1114 def configure_instance2(self, appid): |
|
1115 configure_instance(self, appid) |
|
1116 if self.config.db is not None: |
|
1117 appcfg = ServerConfiguration.config_for(appid) |
|
1118 srccfg = appcfg.read_sources_file() |
|
1119 for key, value in self.config.db.iteritems(): |
|
1120 try: |
|
1121 srccfg['system'][key] = value |
|
1122 except KeyError: |
|
1123 raise ConfigurationError('unknown configuration key "%s" for source' % key) |
|
1124 admcfg = Configuration(options=USER_OPTIONS) |
|
1125 admcfg['login'] = srccfg['admin']['login'] |
|
1126 admcfg['password'] = srccfg['admin']['password'] |
|
1127 srccfg['admin'] = admcfg |
|
1128 appcfg.write_sources_file(srccfg) |
|
1129 ConfigureInstanceCommand.configure_instance = configure_instance2 |