36 def kill(*args): |
36 def kill(*args): |
37 """win32 kill implementation""" |
37 """win32 kill implementation""" |
38 def getpgid(): |
38 def getpgid(): |
39 """win32 getpgid implementation""" |
39 """win32 getpgid implementation""" |
40 |
40 |
41 |
|
42 |
|
43 from logilab.common.clcommands import CommandLine |
41 from logilab.common.clcommands import CommandLine |
44 from logilab.common.shellutils import ASK |
42 from logilab.common.shellutils import ASK |
|
43 from logilab.common.configuration import merge_options |
45 |
44 |
46 from cubicweb import ConfigurationError, ExecutionError, BadCommandUsage |
45 from cubicweb import ConfigurationError, ExecutionError, BadCommandUsage |
47 from cubicweb.utils import support_args |
46 from cubicweb.utils import support_args |
48 from cubicweb.cwconfig import CubicWebConfiguration as cwcfg, CWDEV, CONFIGURATIONS |
47 from cubicweb.cwconfig import CubicWebConfiguration as cwcfg, CWDEV, CONFIGURATIONS |
49 from cubicweb.toolsutils import Command, rm, create_dir, underline_title |
48 from cubicweb.toolsutils import Command, rm, create_dir, underline_title |
844 repo = config.migration_handler().repo_connect() |
843 repo = config.migration_handler().repo_connect() |
845 vcconf = repo.get_versions() |
844 vcconf = repo.get_versions() |
846 for key in sorted(vcconf): |
845 for key in sorted(vcconf): |
847 print key+': %s.%s.%s' % vcconf[key] |
846 print key+': %s.%s.%s' % vcconf[key] |
848 |
847 |
849 |
|
850 class ShellCommand(Command): |
848 class ShellCommand(Command): |
851 """Run an interactive migration shell on an instance. This is a python shell |
849 """Run an interactive migration shell on an instance. This is a python shell |
852 with enhanced migration commands predefined in the namespace. An additional |
850 with enhanced migration commands predefined in the namespace. An additional |
853 argument may be given corresponding to a file containing commands to execute |
851 argument may be given corresponding to a file containing commands to execute |
854 in batch mode. |
852 in batch mode. |
1011 def run(self, args): |
1009 def run(self, args): |
1012 """run the command with its specific arguments""" |
1010 """run the command with its specific arguments""" |
1013 for cube in cwcfg.available_cubes(): |
1011 for cube in cwcfg.available_cubes(): |
1014 print cube |
1012 print cube |
1015 |
1013 |
|
1014 class ConfigureInstanceCommand(InstanceCommand): |
|
1015 """Configure instance. |
|
1016 |
|
1017 <instance>... |
|
1018 identifier of the instance to configure. |
|
1019 """ |
|
1020 name = 'configure' |
|
1021 actionverb = 'configured' |
|
1022 |
|
1023 options = merge_options(InstanceCommand.options + |
|
1024 (('param', |
|
1025 {'short': 'p', 'type' : 'named', 'metavar' : 'key1:value1,key2:value2', |
|
1026 'default': None, |
|
1027 'help': 'set <key> to <value> in configuration file.', |
|
1028 }), |
|
1029 )) |
|
1030 |
|
1031 def configure_instance(self, appid): |
|
1032 if self.config.param is not None: |
|
1033 appcfg = cwcfg.config_for(appid) |
|
1034 for key, value in self.config.param.iteritems(): |
|
1035 try: |
|
1036 appcfg.global_set_option(key, value) |
|
1037 except KeyError: |
|
1038 raise ConfigurationError('unknown configuration key "%s" for mode %s' % (key, appcfg.name)) |
|
1039 appcfg.save() |
|
1040 |
1016 for cmdcls in (ListCommand, |
1041 for cmdcls in (ListCommand, |
1017 CreateInstanceCommand, DeleteInstanceCommand, |
1042 CreateInstanceCommand, DeleteInstanceCommand, |
1018 StartInstanceCommand, StopInstanceCommand, RestartInstanceCommand, |
1043 StartInstanceCommand, StopInstanceCommand, RestartInstanceCommand, |
1019 ReloadConfigurationCommand, StatusCommand, |
1044 ReloadConfigurationCommand, StatusCommand, |
1020 UpgradeInstanceCommand, |
1045 UpgradeInstanceCommand, |
1021 ListVersionsInstanceCommand, |
1046 ListVersionsInstanceCommand, |
1022 ShellCommand, |
1047 ShellCommand, |
1023 RecompileInstanceCatalogsCommand, |
1048 RecompileInstanceCatalogsCommand, |
1024 ListInstancesCommand, ListCubesCommand, |
1049 ListInstancesCommand, ListCubesCommand, |
|
1050 ConfigureInstanceCommand, |
1025 ): |
1051 ): |
1026 CWCTL.register(cmdcls) |
1052 CWCTL.register(cmdcls) |
1027 |
|
1028 |
1053 |
1029 def run(args): |
1054 def run(args): |
1030 """command line tool""" |
1055 """command line tool""" |
1031 import os |
1056 import os |
1032 sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) |
1057 sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) |