43 from cubicweb import ConfigurationError, ExecutionError, BadCommandUsage |
43 from cubicweb import ConfigurationError, ExecutionError, BadCommandUsage |
44 from cubicweb.cwconfig import CubicWebConfiguration as cwcfg, CONFIGURATIONS |
44 from cubicweb.cwconfig import CubicWebConfiguration as cwcfg, CONFIGURATIONS |
45 from cubicweb.toolsutils import Command, rm, create_dir, underline_title |
45 from cubicweb.toolsutils import Command, rm, create_dir, underline_title |
46 from cubicweb.__pkginfo__ import version as cw_version |
46 from cubicweb.__pkginfo__ import version as cw_version |
47 |
47 |
|
48 LOG_LEVELS = ('debug', 'info', 'warning', 'error') |
|
49 |
48 # don't check duplicated commands, it occurs when reloading site_cubicweb |
50 # don't check duplicated commands, it occurs when reloading site_cubicweb |
49 CWCTL = CommandLine('cubicweb-ctl', 'The CubicWeb swiss-knife.', |
51 CWCTL = CommandLine('cubicweb-ctl', 'The CubicWeb swiss-knife.', |
50 version=cw_version, check_duplicated_command=False) |
52 version=cw_version, check_duplicated_command=False) |
51 |
53 |
52 |
54 |
125 ("pdb", |
127 ("pdb", |
126 {'action': 'store_true', 'default': False, |
128 {'action': 'store_true', 'default': False, |
127 'help': 'launch pdb on exception', |
129 'help': 'launch pdb on exception', |
128 } |
130 } |
129 ), |
131 ), |
|
132 ("loglevel", |
|
133 {'type': 'choice', 'default': None, 'metavar': '<log level>', |
|
134 'choices': LOG_LEVELS, 'short': 'l', |
|
135 'help': 'allow to specify log level for debugging (choices: %s)' |
|
136 % (', '.join(LOG_LEVELS)), |
|
137 } |
|
138 ), |
130 ) |
139 ) |
131 actionverb = None |
140 actionverb = None |
132 |
141 |
133 def run(self, args): |
142 def run(self, args): |
134 """run the <command>_method on each argument (a list of instance |
143 """run the <command>_method on each argument (a list of instance |
136 """ |
145 """ |
137 appid = args[0] |
146 appid = args[0] |
138 cmdmeth = getattr(self, '%s_instance' % self.name) |
147 cmdmeth = getattr(self, '%s_instance' % self.name) |
139 |
148 |
140 traceback_ = None |
149 traceback_ = None |
|
150 |
|
151 # debugmode=True is to force to have a StreamHandler used instead of |
|
152 # writting the logs into a file in /tmp |
|
153 self.cwconfig = cwcfg.config_for(appid, debugmode=True) |
|
154 |
|
155 # by default loglevel is 'error' but we keep the default value to None |
|
156 # because some subcommands (e.g: pyramid) can override the loglevel in |
|
157 # certain situations if it's not explicitly set by the user and we want |
|
158 # to detect that (the "None" case) |
|
159 if self['loglevel'] is None: |
|
160 init_cmdline_log_threshold(self.cwconfig, 'error') |
|
161 else: |
|
162 init_cmdline_log_threshold(self.cwconfig, self['loglevel']) |
141 |
163 |
142 try: |
164 try: |
143 status = cmdmeth(appid) or 0 |
165 status = cmdmeth(appid) or 0 |
144 except (ExecutionError, ConfigurationError) as ex: |
166 except (ExecutionError, ConfigurationError) as ex: |
145 # we need to do extract this information here for pdb since it is |
167 # we need to do extract this information here for pdb since it is |
606 identifiers of the instances to list versions for. |
627 identifiers of the instances to list versions for. |
607 """ |
628 """ |
608 name = 'versions' |
629 name = 'versions' |
609 |
630 |
610 def versions_instance(self, appid): |
631 def versions_instance(self, appid): |
611 config = cwcfg.config_for(appid) |
632 config = self.cwconfig |
612 # should not raise error if db versions don't match fs versions |
633 # should not raise error if db versions don't match fs versions |
613 config.repairing = True |
634 config.repairing = True |
614 # no need to load all appobjects and schema |
635 # no need to load all appobjects and schema |
615 config.quick_start = True |
636 config.quick_start = True |
616 if hasattr(config, 'set_sources_mode'): |
637 if hasattr(config, 'set_sources_mode'): |
638 """ |
659 """ |
639 name = 'shell' |
660 name = 'shell' |
640 arguments = '<instance> [batch command file(s)] [-- <script arguments>]' |
661 arguments = '<instance> [batch command file(s)] [-- <script arguments>]' |
641 min_args = 1 |
662 min_args = 1 |
642 max_args = None |
663 max_args = None |
643 options = ( |
664 options = merge_options(( |
644 ('system-only', |
665 ('system-only', |
645 {'short': 'S', 'action': 'store_true', |
666 {'short': 'S', 'action': 'store_true', |
646 'help': 'only connect to the system source when the instance is ' |
667 'help': 'only connect to the system source when the instance is ' |
647 'using multiple sources. You can\'t use this option and the ' |
668 'using multiple sources. You can\'t use this option and the ' |
648 '--ext-sources option at the same time.', |
669 '--ext-sources option at the same time.', |
662 {'short': 'f', 'action': 'store_true', |
683 {'short': 'f', 'action': 'store_true', |
663 'help': 'don\'t check instance is up to date.', |
684 'help': 'don\'t check instance is up to date.', |
664 'group': 'local' |
685 'group': 'local' |
665 }), |
686 }), |
666 |
687 |
667 ) |
688 ) + InstanceCommand.options) |
668 |
689 |
669 def _get_mih(self, appid): |
690 def _get_mih(self, appid): |
670 """ returns migration context handler & shutdown function """ |
691 """ returns migration context handler & shutdown function """ |
671 config = cwcfg.config_for(appid) |
692 config = cwcfg.config_for(appid) |
672 if self.config.ext_sources: |
693 if self.config.ext_sources: |
706 <instance> |
727 <instance> |
707 identifier of the instance to consider. |
728 identifier of the instance to consider. |
708 """ |
729 """ |
709 name = 'i18ninstance' |
730 name = 'i18ninstance' |
710 |
731 |
711 @staticmethod |
732 def i18ninstance_instance(self, appid): |
712 def i18ninstance_instance(appid): |
|
713 """recompile instance's messages catalogs""" |
733 """recompile instance's messages catalogs""" |
714 config = cwcfg.config_for(appid) |
734 config = self.cwconfig |
715 config.quick_start = True # notify this is not a regular start |
735 config.quick_start = True # notify this is not a regular start |
716 repo = config.repository() |
736 repo = config.repository() |
717 if config._cubes is None: |
737 if config._cubes is None: |
718 # web only config |
738 # web only config |
719 config.init_cubes(repo.get_cubes()) |
739 config.init_cubes(repo.get_cubes()) |
763 ), |
783 ), |
764 ) |
784 ) |
765 |
785 |
766 def configure_instance(self, appid): |
786 def configure_instance(self, appid): |
767 if self.config.param is not None: |
787 if self.config.param is not None: |
768 appcfg = cwcfg.config_for(appid) |
788 appcfg = self.cwconfig |
769 for key, value in self.config.param.items(): |
789 for key, value in self.config.param.items(): |
770 try: |
790 try: |
771 appcfg.global_set_option(key, value) |
791 appcfg.global_set_option(key, value) |
772 except KeyError: |
792 except KeyError: |
773 raise ConfigurationError( |
793 raise ConfigurationError( |