author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 01 Jul 2011 11:51:04 +0200 | |
changeset 7595 | 83872394b5d9 |
parent 7591 | cb6ece9cdb78 |
parent 7593 | 0c1024b3e7fc |
child 7815 | 2a164a9cf81c |
permissions | -rw-r--r-- |
7129
455b503fb7ff
[config] generalise config.creating, allowing to drop set_language class attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7028
diff
changeset
|
1 |
# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5288
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5288
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5288
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5288
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5288
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5288
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5288
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5288
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5288
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5288
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5288
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5288
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5288
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5288
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5288
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
4720
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
18 |
"""the cubicweb-ctl tool, based on logilab.common.clcommands to |
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
19 |
provide a pluggable commands system. |
5814
51cc4b61f9ae
[repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5811
diff
changeset
|
20 |
""" |
0 | 21 |
|
4720
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
22 |
__docformat__ = "restructuredtext en" |
0 | 23 |
|
4718
3dc3ad02d091
avoid module import in c-c plugins module, and remind it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4684
diff
changeset
|
24 |
# *ctl module should limit the number of import to be imported as quickly as |
3dc3ad02d091
avoid module import in c-c plugins module, and remind it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4684
diff
changeset
|
25 |
# possible (for cubicweb-ctl reactivity, necessary for instance for usable bash |
3dc3ad02d091
avoid module import in c-c plugins module, and remind it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4684
diff
changeset
|
26 |
# completion). So import locally in command helpers. |
0 | 27 |
import sys |
5025
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
28 |
from warnings import warn |
3115
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
2905
diff
changeset
|
29 |
from os import remove, listdir, system, pathsep |
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
2905
diff
changeset
|
30 |
try: |
3562 | 31 |
from os import kill, getpgid |
3115
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
2905
diff
changeset
|
32 |
except ImportError: |
4721
8f63691ccb7f
pylint style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4720
diff
changeset
|
33 |
def kill(*args): |
8f63691ccb7f
pylint style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4720
diff
changeset
|
34 |
"""win32 kill implementation""" |
8f63691ccb7f
pylint style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4720
diff
changeset
|
35 |
def getpgid(): |
8f63691ccb7f
pylint style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4720
diff
changeset
|
36 |
"""win32 getpgid implementation""" |
3115
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
2905
diff
changeset
|
37 |
|
6562
34be5986bca0
make stdout and stderr non buffered for cwctl commands (#1330647)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6505
diff
changeset
|
38 |
|
4064
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
39 |
from os.path import exists, join, isfile, isdir, dirname, abspath |
0 | 40 |
|
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
41 |
from logilab.common.clcommands import CommandLine |
2615
1ea41b7c0836
F [dialog] offer to create backup. refactor to use l.c.shellutils.ASK
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2532
diff
changeset
|
42 |
from logilab.common.shellutils import ASK |
1132 | 43 |
|
2790
968108e16066
move underline_title to toolsutils
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2743
diff
changeset
|
44 |
from cubicweb import ConfigurationError, ExecutionError, BadCommandUsage |
6914
5be96d9cbedc
[c-c] lgc 0.54 check for duplicated commands, this may occurs with cw where plugins are automaticall (re)loaded
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6845
diff
changeset
|
45 |
from cubicweb.utils import support_args |
3638
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3619
diff
changeset
|
46 |
from cubicweb.cwconfig import CubicWebConfiguration as cwcfg, CWDEV, CONFIGURATIONS |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
47 |
from cubicweb.toolsutils import Command, rm, create_dir, underline_title |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
48 |
from cubicweb.__pkginfo__ import version |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
49 |
|
6914
5be96d9cbedc
[c-c] lgc 0.54 check for duplicated commands, this may occurs with cw where plugins are automaticall (re)loaded
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6845
diff
changeset
|
50 |
if support_args(CommandLine, 'check_duplicated_command'): |
5be96d9cbedc
[c-c] lgc 0.54 check for duplicated commands, this may occurs with cw where plugins are automaticall (re)loaded
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6845
diff
changeset
|
51 |
# don't check duplicated commands, it occurs when reloading site_cubicweb |
5be96d9cbedc
[c-c] lgc 0.54 check for duplicated commands, this may occurs with cw where plugins are automaticall (re)loaded
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6845
diff
changeset
|
52 |
CWCTL = CommandLine('cubicweb-ctl', 'The CubicWeb swiss-knife.', |
5be96d9cbedc
[c-c] lgc 0.54 check for duplicated commands, this may occurs with cw where plugins are automaticall (re)loaded
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6845
diff
changeset
|
53 |
version=version, check_duplicated_command=False) |
5be96d9cbedc
[c-c] lgc 0.54 check for duplicated commands, this may occurs with cw where plugins are automaticall (re)loaded
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6845
diff
changeset
|
54 |
else: |
5be96d9cbedc
[c-c] lgc 0.54 check for duplicated commands, this may occurs with cw where plugins are automaticall (re)loaded
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6845
diff
changeset
|
55 |
CWCTL = CommandLine('cubicweb-ctl', 'The CubicWeb swiss-knife.', |
5be96d9cbedc
[c-c] lgc 0.54 check for duplicated commands, this may occurs with cw where plugins are automaticall (re)loaded
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6845
diff
changeset
|
56 |
version=version) |
1446 | 57 |
|
0 | 58 |
def wait_process_end(pid, maxtry=10, waittime=1): |
59 |
"""wait for a process to actually die""" |
|
60 |
import signal |
|
61 |
from time import sleep |
|
62 |
nbtry = 0 |
|
63 |
while nbtry < maxtry: |
|
64 |
try: |
|
65 |
kill(pid, signal.SIGUSR1) |
|
3117
32686ae66c75
mostly adapt the i18n subsystem to limitation wrt redirection handinling in windows, using the -o argument of the utilities
Aurélien Campéas
parents:
3115
diff
changeset
|
66 |
except (OSError, AttributeError): # XXX win32 |
0 | 67 |
break |
68 |
nbtry += 1 |
|
69 |
sleep(waittime) |
|
70 |
else: |
|
71 |
raise ExecutionError('can\'t kill process %s' % pid) |
|
72 |
||
73 |
def list_instances(regdir): |
|
6505
ac4cecb26813
[distribution] Handle missing instance directory when listing and running instance command.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6145
diff
changeset
|
74 |
if isdir(regdir): |
ac4cecb26813
[distribution] Handle missing instance directory when listing and running instance command.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6145
diff
changeset
|
75 |
return sorted(idir for idir in listdir(regdir) if isdir(join(regdir, idir))) |
ac4cecb26813
[distribution] Handle missing instance directory when listing and running instance command.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6145
diff
changeset
|
76 |
else: |
ac4cecb26813
[distribution] Handle missing instance directory when listing and running instance command.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6145
diff
changeset
|
77 |
return [] |
0 | 78 |
|
79 |
def detect_available_modes(templdir): |
|
80 |
modes = [] |
|
81 |
for fname in ('schema', 'schema.py'): |
|
82 |
if exists(join(templdir, fname)): |
|
83 |
modes.append('repository') |
|
84 |
break |
|
85 |
for fname in ('data', 'views', 'views.py'): |
|
86 |
if exists(join(templdir, fname)): |
|
87 |
modes.append('web ui') |
|
88 |
break |
|
89 |
return modes |
|
1446 | 90 |
|
91 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
92 |
class InstanceCommand(Command): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
93 |
"""base class for command taking 0 to n instance id as arguments |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
94 |
(0 meaning all registered instances) |
0 | 95 |
""" |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
96 |
arguments = '[<instance>...]' |
0 | 97 |
options = ( |
98 |
("force", |
|
99 |
{'short': 'f', 'action' : 'store_true', |
|
100 |
'default': False, |
|
101 |
'help': 'force command without asking confirmation', |
|
102 |
} |
|
103 |
), |
|
104 |
) |
|
105 |
actionverb = None |
|
1446 | 106 |
|
0 | 107 |
def ordered_instances(self): |
108 |
"""return instances in the order in which they should be started, |
|
109 |
considering $REGISTRY_DIR/startorder file if it exists (useful when |
|
3619
af81a4f7053e
enhance docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3562
diff
changeset
|
110 |
some instances depends on another as external source). |
af81a4f7053e
enhance docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3562
diff
changeset
|
111 |
|
af81a4f7053e
enhance docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3562
diff
changeset
|
112 |
Instance used by another one should appears first in the file (one |
af81a4f7053e
enhance docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3562
diff
changeset
|
113 |
instance per line) |
0 | 114 |
""" |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4798
diff
changeset
|
115 |
regdir = cwcfg.instances_dir() |
0 | 116 |
_allinstances = list_instances(regdir) |
117 |
if isfile(join(regdir, 'startorder')): |
|
118 |
allinstances = [] |
|
119 |
for line in file(join(regdir, 'startorder')): |
|
120 |
line = line.strip() |
|
121 |
if line and not line.startswith('#'): |
|
122 |
try: |
|
123 |
_allinstances.remove(line) |
|
124 |
allinstances.append(line) |
|
125 |
except ValueError: |
|
1132 | 126 |
print ('ERROR: startorder file contains unexistant ' |
127 |
'instance %s' % line) |
|
0 | 128 |
allinstances += _allinstances |
129 |
else: |
|
130 |
allinstances = _allinstances |
|
131 |
return allinstances |
|
1446 | 132 |
|
0 | 133 |
def run(self, args): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
134 |
"""run the <command>_method on each argument (a list of instance |
0 | 135 |
identifiers) |
136 |
""" |
|
137 |
if not args: |
|
138 |
args = self.ordered_instances() |
|
139 |
try: |
|
140 |
askconfirm = not self.config.force |
|
141 |
except AttributeError: |
|
142 |
# no force option |
|
143 |
askconfirm = False |
|
144 |
else: |
|
145 |
askconfirm = False |
|
146 |
self.run_args(args, askconfirm) |
|
1446 | 147 |
|
0 | 148 |
def run_args(self, args, askconfirm): |
5380
a4e7e87d315f
[c-c status] return status code 1 when some instances isn't running. Closes #510817
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5323
diff
changeset
|
149 |
status = 0 |
0 | 150 |
for appid in args: |
151 |
if askconfirm: |
|
152 |
print '*'*72 |
|
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
153 |
if not ASK.confirm('%s instance %r ?' % (self.name, appid)): |
0 | 154 |
continue |
7593
0c1024b3e7fc
[c-c instance commands] keyboard interrupt should stop the command, not jump to the next instance. Closes #1794850
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7538
diff
changeset
|
155 |
try: |
0c1024b3e7fc
[c-c instance commands] keyboard interrupt should stop the command, not jump to the next instance. Closes #1794850
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7538
diff
changeset
|
156 |
status = max(status, self.run_arg(appid)) |
0c1024b3e7fc
[c-c instance commands] keyboard interrupt should stop the command, not jump to the next instance. Closes #1794850
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7538
diff
changeset
|
157 |
except (KeyboardInterrupt, SystemExit): |
0c1024b3e7fc
[c-c instance commands] keyboard interrupt should stop the command, not jump to the next instance. Closes #1794850
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7538
diff
changeset
|
158 |
print >> sys.stderr, '%s aborted' % self.name |
0c1024b3e7fc
[c-c instance commands] keyboard interrupt should stop the command, not jump to the next instance. Closes #1794850
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7538
diff
changeset
|
159 |
return 2 # specific error code |
5380
a4e7e87d315f
[c-c status] return status code 1 when some instances isn't running. Closes #510817
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5323
diff
changeset
|
160 |
sys.exit(status) |
1446 | 161 |
|
0 | 162 |
def run_arg(self, appid): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
163 |
cmdmeth = getattr(self, '%s_instance' % self.name) |
0 | 164 |
try: |
5380
a4e7e87d315f
[c-c status] return status code 1 when some instances isn't running. Closes #510817
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5323
diff
changeset
|
165 |
status = cmdmeth(appid) |
0 | 166 |
except (ExecutionError, ConfigurationError), ex: |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
167 |
print >> sys.stderr, 'instance %s not %s: %s' % ( |
0 | 168 |
appid, self.actionverb, ex) |
5380
a4e7e87d315f
[c-c status] return status code 1 when some instances isn't running. Closes #510817
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5323
diff
changeset
|
169 |
status = 4 |
0 | 170 |
except Exception, ex: |
171 |
import traceback |
|
172 |
traceback.print_exc() |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
173 |
print >> sys.stderr, 'instance %s not %s: %s' % ( |
0 | 174 |
appid, self.actionverb, ex) |
5380
a4e7e87d315f
[c-c status] return status code 1 when some instances isn't running. Closes #510817
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5323
diff
changeset
|
175 |
status = 8 |
a4e7e87d315f
[c-c status] return status code 1 when some instances isn't running. Closes #510817
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5323
diff
changeset
|
176 |
return status |
0 | 177 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
178 |
class InstanceCommandFork(InstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
179 |
"""Same as `InstanceCommand`, but command is forked in a new environment |
0 | 180 |
for each argument |
181 |
""" |
|
182 |
||
183 |
def run_args(self, args, askconfirm): |
|
184 |
if len(args) > 1: |
|
185 |
forkcmd = ' '.join(w for w in sys.argv if not w in args) |
|
186 |
else: |
|
187 |
forkcmd = None |
|
188 |
for appid in args: |
|
189 |
if askconfirm: |
|
190 |
print '*'*72 |
|
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
191 |
if not ASK.confirm('%s instance %r ?' % (self.name, appid)): |
0 | 192 |
continue |
193 |
if forkcmd: |
|
194 |
status = system('%s %s' % (forkcmd, appid)) |
|
195 |
if status: |
|
2156
fadb86b040a9
continue to run command on other instances, do not exit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2104
diff
changeset
|
196 |
print '%s exited with status %s' % (forkcmd, status) |
0 | 197 |
else: |
198 |
self.run_arg(appid) |
|
1446 | 199 |
|
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
200 |
|
0 | 201 |
# base commands ############################################################### |
202 |
||
203 |
class ListCommand(Command): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
204 |
"""List configurations, cubes and instances. |
0 | 205 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
206 |
list available configurations, installed cubes, and registered instances |
0 | 207 |
""" |
208 |
name = 'list' |
|
209 |
options = ( |
|
210 |
('verbose', |
|
1446 | 211 |
{'short': 'v', 'action' : 'store_true', |
212 |
'help': "display more information."}), |
|
0 | 213 |
) |
1446 | 214 |
|
0 | 215 |
def run(self, args): |
216 |
"""run the command with its specific arguments""" |
|
217 |
if args: |
|
5608
f9ab62103ad4
proof read documentation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5498
diff
changeset
|
218 |
raise BadCommandUsage('Too many arguments') |
5027
d688daf0a62c
[config] move ConfigurationProblem to migration + refactor it to benefit from config methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5026
diff
changeset
|
219 |
from cubicweb.migration import ConfigurationProblem |
3486
ea6bf6f9ba0c
[cwctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3198
diff
changeset
|
220 |
print 'CubicWeb %s (%s mode)' % (cwcfg.cubicweb_version(), cwcfg.mode) |
0 | 221 |
print |
222 |
print 'Available configurations:' |
|
223 |
for config in CONFIGURATIONS: |
|
224 |
print '*', config.name |
|
225 |
for line in config.__doc__.splitlines(): |
|
226 |
line = line.strip() |
|
227 |
if not line: |
|
228 |
continue |
|
229 |
print ' ', line |
|
1446 | 230 |
print |
5027
d688daf0a62c
[config] move ConfigurationProblem to migration + refactor it to benefit from config methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5026
diff
changeset
|
231 |
cfgpb = ConfigurationProblem(cwcfg) |
0 | 232 |
try: |
1342
4273e44852cb
no more cubes_dir class method
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
233 |
cubesdir = pathsep.join(cwcfg.cubes_search_path()) |
1132 | 234 |
namesize = max(len(x) for x in cwcfg.available_cubes()) |
0 | 235 |
except ConfigurationError, ex: |
236 |
print 'No cubes available:', ex |
|
237 |
except ValueError: |
|
238 |
print 'No cubes available in %s' % cubesdir |
|
239 |
else: |
|
240 |
print 'Available cubes (%s):' % cubesdir |
|
1132 | 241 |
for cube in cwcfg.available_cubes(): |
0 | 242 |
try: |
1132 | 243 |
tinfo = cwcfg.cube_pkginfo(cube) |
0 | 244 |
tversion = tinfo.version |
5027
d688daf0a62c
[config] move ConfigurationProblem to migration + refactor it to benefit from config methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5026
diff
changeset
|
245 |
cfgpb.add_cube(cube, tversion) |
6845
027c93dfba0a
[c-c list] don't crash if there are no 'version' attribute in pkginfo
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6778
diff
changeset
|
246 |
except (ConfigurationError, AttributeError), ex: |
0 | 247 |
tinfo = None |
6675
12ee2fe13fa7
[c-c list] tell more about the pb when some cube information is missing
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6657
diff
changeset
|
248 |
tversion = '[missing cube information: %s]' % ex |
0 | 249 |
print '* %s %s' % (cube.ljust(namesize), tversion) |
250 |
if self.config.verbose: |
|
5025
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
251 |
if tinfo: |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
252 |
descr = getattr(tinfo, 'description', '') |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
253 |
if not descr: |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
254 |
descr = getattr(tinfo, 'short_desc', '') |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
255 |
if descr: |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
256 |
warn('[3.8] short_desc is deprecated, update %s' |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
257 |
' pkginfo' % cube, DeprecationWarning) |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
258 |
else: |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
259 |
descr = tinfo.__doc__ |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
260 |
if descr: |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
261 |
print ' '+ ' \n'.join(descr.splitlines()) |
2024
82128fe6798c
redo juj's fix in stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1898
diff
changeset
|
262 |
modes = detect_available_modes(cwcfg.cube_dir(cube)) |
0 | 263 |
print ' available modes: %s' % ', '.join(modes) |
264 |
print |
|
265 |
try: |
|
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4798
diff
changeset
|
266 |
regdir = cwcfg.instances_dir() |
0 | 267 |
except ConfigurationError, ex: |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
268 |
print 'No instance available:', ex |
0 | 269 |
print |
270 |
return |
|
271 |
instances = list_instances(regdir) |
|
272 |
if instances: |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
273 |
print 'Available instances (%s):' % regdir |
0 | 274 |
for appid in instances: |
1132 | 275 |
modes = cwcfg.possible_configurations(appid) |
0 | 276 |
if not modes: |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
277 |
print '* %s (BROKEN instance, no configuration found)' % appid |
0 | 278 |
continue |
279 |
print '* %s (%s)' % (appid, ', '.join(modes)) |
|
280 |
try: |
|
1132 | 281 |
config = cwcfg.config_for(appid, modes[0]) |
1446 | 282 |
except Exception, exc: |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
283 |
print ' (BROKEN instance, %s)' % exc |
0 | 284 |
continue |
285 |
else: |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
286 |
print 'No instance available in %s' % regdir |
0 | 287 |
print |
4656
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
288 |
# configuration management problem solving |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
289 |
cfgpb.solve() |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
290 |
if cfgpb.warnings: |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
291 |
print 'Warnings:\n', '\n'.join('* '+txt for txt in cfgpb.warnings) |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
292 |
if cfgpb.errors: |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
293 |
print 'Errors:' |
6657
402bff898024
[cwctl] command list now checks version of cw, not only versions of cubes
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6562
diff
changeset
|
294 |
for op, cube, version, src in cfgpb.errors: |
4656
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
295 |
if op == 'add': |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
296 |
print '* cube', cube, |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
297 |
if version: |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
298 |
print ' version', version, |
6657
402bff898024
[cwctl] command list now checks version of cw, not only versions of cubes
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6562
diff
changeset
|
299 |
print 'is not installed, but required by %s' % src |
4656
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
300 |
else: |
6657
402bff898024
[cwctl] command list now checks version of cw, not only versions of cubes
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6562
diff
changeset
|
301 |
print '* cube %s version %s is installed, but version %s is required by %s' % ( |
402bff898024
[cwctl] command list now checks version of cw, not only versions of cubes
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6562
diff
changeset
|
302 |
cube, cfgpb.cubes[cube], version, src) |
0 | 303 |
|
7140
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
304 |
def check_options_consistency(config): |
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
305 |
if config.automatic and config.config_level > 0: |
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
306 |
raise BadCommandUsage('--automatic and --config-level should not be ' |
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
307 |
'used together') |
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
308 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
309 |
class CreateInstanceCommand(Command): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
310 |
"""Create an instance from a cube. This is an unified |
0 | 311 |
command which can handle web / server / all-in-one installation |
312 |
according to available parts of the software library and of the |
|
313 |
desired cube. |
|
314 |
||
315 |
<cube> |
|
316 |
the name of cube to use (list available cube names using |
|
317 |
the "list" command). You can use several cubes by separating |
|
7140
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
318 |
them using comma (e.g. 'jpl,email') |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
319 |
<instance> |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
320 |
an identifier for the instance to create |
0 | 321 |
""" |
322 |
name = 'create' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
323 |
arguments = '<cube> <instance>' |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
324 |
min_args = max_args = 2 |
0 | 325 |
options = ( |
7140
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
326 |
('automatic', |
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
327 |
{'short': 'a', 'action' : 'store_true', |
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
328 |
'default': False, |
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
329 |
'help': 'automatic mode: never ask and use default answer to every ' |
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
330 |
'question. this may require that your login match a database super ' |
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
331 |
'user (allowed to create database & all).', |
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
332 |
}), |
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
333 |
('config-level', |
0 | 334 |
{'short': 'l', 'type' : 'int', 'metavar': '<level>', |
335 |
'default': 0, |
|
7140
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
336 |
'help': 'configuration level (0..2): 0 will ask for essential ' |
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
337 |
'configuration parameters only while 2 will ask for all parameters', |
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
338 |
}), |
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
339 |
('config', |
0 | 340 |
{'short': 'c', 'type' : 'choice', 'metavar': '<install type>', |
341 |
'choices': ('all-in-one', 'repository', 'twisted'), |
|
342 |
'default': 'all-in-one', |
|
7140
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
343 |
'help': 'installation type, telling which part of an instance ' |
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
344 |
'should be installed. You can list available configurations using the' |
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
345 |
' "list" command. Default to "all-in-one", e.g. an installation ' |
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
346 |
'embedding both the RQL repository and the web server.', |
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
347 |
}), |
0 | 348 |
) |
1446 | 349 |
|
0 | 350 |
def run(self, args): |
351 |
"""run the command with its specific arguments""" |
|
2633
bc9386c3b2c9
get_csv is being renamed to splitstrip
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2615
diff
changeset
|
352 |
from logilab.common.textutils import splitstrip |
7140
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
353 |
check_options_consistency(self.config) |
0 | 354 |
configname = self.config.config |
6144
40af8e328e64
[c-c create] argument inversed accidentally
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
355 |
cubes, appid = args |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
356 |
cubes = splitstrip(cubes) |
0 | 357 |
# get the configuration and helper |
7129
455b503fb7ff
[config] generalise config.creating, allowing to drop set_language class attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7028
diff
changeset
|
358 |
config = cwcfg.config_for(appid, configname, creating=True) |
2104
b4ffcea3275b
change cubes into expanded cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2032
diff
changeset
|
359 |
cubes = config.expand_cubes(cubes) |
b4ffcea3275b
change cubes into expanded cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2032
diff
changeset
|
360 |
config.init_cubes(cubes) |
0 | 361 |
helper = self.config_helper(config) |
362 |
# check the cube exists |
|
363 |
try: |
|
1132 | 364 |
templdirs = [cwcfg.cube_dir(cube) |
0 | 365 |
for cube in cubes] |
366 |
except ConfigurationError, ex: |
|
367 |
print ex |
|
368 |
print '\navailable cubes:', |
|
1132 | 369 |
print ', '.join(cwcfg.available_cubes()) |
0 | 370 |
return |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
371 |
# create the registry directory for this instance |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
372 |
print '\n'+underline_title('Creating the instance %s' % appid) |
0 | 373 |
create_dir(config.apphome) |
374 |
# cubicweb-ctl configuration |
|
7140
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
375 |
if not self.config.automatic: |
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
376 |
print '\n'+underline_title('Configuring the instance (%s.conf)' |
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
377 |
% configname) |
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
378 |
config.input_config('main', self.config.config_level) |
0 | 379 |
# configuration'specific stuff |
380 |
print |
|
7140
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
381 |
helper.bootstrap(cubes, self.config.automatic, self.config.config_level) |
4610
7bf205b9a845
when creating an instance, ask for cubes specific options properly (fix #607349)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4609
diff
changeset
|
382 |
# input for cubes specific options |
7131
5893b899c21f
[c-c create]Â we should also skip option with no type, else we may generate title for section without any option to fill
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7129
diff
changeset
|
383 |
sections = set(sect.lower() for sect, opt, odict in config.all_options() |
5893b899c21f
[c-c create]Â we should also skip option with no type, else we may generate title for section without any option to fill
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7129
diff
changeset
|
384 |
if 'type' in odict |
5893b899c21f
[c-c create]Â we should also skip option with no type, else we may generate title for section without any option to fill
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7129
diff
changeset
|
385 |
and odict.get('level') <= self.config.config_level) |
5893b899c21f
[c-c create]Â we should also skip option with no type, else we may generate title for section without any option to fill
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7129
diff
changeset
|
386 |
for section in sections: |
7140
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
387 |
if section not in ('main', 'email', 'pyro', 'web'): |
4610
7bf205b9a845
when creating an instance, ask for cubes specific options properly (fix #607349)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4609
diff
changeset
|
388 |
print '\n' + underline_title('%s options' % section) |
7bf205b9a845
when creating an instance, ask for cubes specific options properly (fix #607349)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4609
diff
changeset
|
389 |
config.input_config(section, self.config.config_level) |
0 | 390 |
# write down configuration |
391 |
config.save() |
|
4064
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
392 |
self._handle_win32(config, appid) |
7155
4bab50b02927
[cwctl] refactor ui messages aiming for consistency and simplicity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7140
diff
changeset
|
393 |
print '-> generated config %s' % config.main_config_file() |
0 | 394 |
# handle i18n files structure |
395 |
# in the first cube given |
|
4021
280c910c8710
move i18n / migration modules from cw.common to cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3720
diff
changeset
|
396 |
from cubicweb import i18n |
0 | 397 |
langs = [lang for lang, _ in i18n.available_catalogs(join(templdirs[0], 'i18n'))] |
398 |
errors = config.i18ncompile(langs) |
|
399 |
if errors: |
|
400 |
print '\n'.join(errors) |
|
7140
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
401 |
if self.config.automatic \ |
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
402 |
or not ASK.confirm('error while compiling message catalogs, ' |
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
403 |
'continue anyway ?'): |
0 | 404 |
print 'creation not completed' |
405 |
return |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
406 |
# create the additional data directory for this instance |
0 | 407 |
if config.appdatahome != config.apphome: # true in dev mode |
408 |
create_dir(config.appdatahome) |
|
2489
37a747ad6fd4
#344772: instance backups should be done in instance_data_dir
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2476
diff
changeset
|
409 |
create_dir(join(config.appdatahome, 'backup')) |
0 | 410 |
if config['uid']: |
411 |
from logilab.common.shellutils import chown |
|
412 |
# this directory should be owned by the uid of the server process |
|
413 |
print 'set %s as owner of the data directory' % config['uid'] |
|
414 |
chown(config.appdatahome, config['uid']) |
|
7155
4bab50b02927
[cwctl] refactor ui messages aiming for consistency and simplicity
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7140
diff
changeset
|
415 |
print '\n-> creation done for %s\n' % repr(config.apphome)[1:-1] |
7140
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
416 |
helper.postcreate(self.config.automatic) |
0 | 417 |
|
4064
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
418 |
def _handle_win32(self, config, appid): |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
419 |
if sys.platform != 'win32': |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
420 |
return |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
421 |
service_template = """ |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
422 |
import sys |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
423 |
import win32serviceutil |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
424 |
sys.path.insert(0, r"%(CWPATH)s") |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
425 |
|
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
426 |
from cubicweb.etwist.service import CWService |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
427 |
|
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
428 |
classdict = {'_svc_name_': 'cubicweb-%(APPID)s', |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
429 |
'_svc_display_name_': 'CubicWeb ' + '%(CNAME)s', |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
430 |
'instance': '%(APPID)s'} |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
431 |
%(CNAME)sService = type('%(CNAME)sService', (CWService,), classdict) |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
432 |
|
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
433 |
if __name__ == '__main__': |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
434 |
win32serviceutil.HandleCommandLine(%(CNAME)sService) |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
435 |
""" |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
436 |
open(join(config.apphome, 'win32svc.py'), 'wb').write( |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
437 |
service_template % {'APPID': appid, |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
438 |
'CNAME': appid.capitalize(), |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
439 |
'CWPATH': abspath(join(dirname(__file__), '..'))}) |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
440 |
|
1446 | 441 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
442 |
class DeleteInstanceCommand(Command): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
443 |
"""Delete an instance. Will remove instance's files and |
0 | 444 |
unregister it. |
445 |
""" |
|
446 |
name = 'delete' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
447 |
arguments = '<instance>' |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
448 |
min_args = max_args = 1 |
0 | 449 |
options = () |
450 |
||
451 |
def run(self, args): |
|
452 |
"""run the command with its specific arguments""" |
|
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
453 |
appid = args[0] |
1132 | 454 |
configs = [cwcfg.config_for(appid, configname) |
455 |
for configname in cwcfg.possible_configurations(appid)] |
|
0 | 456 |
if not configs: |
457 |
raise ExecutionError('unable to guess configuration for %s' % appid) |
|
458 |
for config in configs: |
|
459 |
helper = self.config_helper(config, required=False) |
|
460 |
if helper: |
|
461 |
helper.cleanup() |
|
462 |
# remove home |
|
463 |
rm(config.apphome) |
|
464 |
# remove instance data directory |
|
465 |
try: |
|
466 |
rm(config.appdatahome) |
|
467 |
except OSError, ex: |
|
468 |
import errno |
|
469 |
if ex.errno != errno.ENOENT: |
|
470 |
raise |
|
471 |
confignames = ', '.join([config.name for config in configs]) |
|
2532
f7ca29d75183
[cleanup] improve dialog message consistency
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2512
diff
changeset
|
472 |
print '-> instance %s (%s) deleted.' % (appid, confignames) |
0 | 473 |
|
474 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
475 |
# instance commands ######################################################## |
0 | 476 |
|
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
477 |
class StartInstanceCommand(InstanceCommandFork): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
478 |
"""Start the given instances. If no instance is given, start them all. |
1446 | 479 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
480 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
481 |
identifiers of the instances to start. If no instance is |
0 | 482 |
given, start them all. |
483 |
""" |
|
484 |
name = 'start' |
|
485 |
actionverb = 'started' |
|
486 |
options = ( |
|
487 |
("debug", |
|
488 |
{'short': 'D', 'action' : 'store_true', |
|
489 |
'help': 'start server in debug mode.'}), |
|
490 |
("force", |
|
491 |
{'short': 'f', 'action' : 'store_true', |
|
492 |
'default': False, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
493 |
'help': 'start the instance even if it seems to be already \ |
0 | 494 |
running.'}), |
495 |
('profile', |
|
496 |
{'short': 'P', 'type' : 'string', 'metavar': '<stat file>', |
|
497 |
'default': None, |
|
498 |
'help': 'profile code and use the specified file to store stats', |
|
499 |
}), |
|
2654
6512522860aa
[twisted] don't use twistd anymore, all-in-one.py file is needed anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2633
diff
changeset
|
500 |
('loglevel', |
6512522860aa
[twisted] don't use twistd anymore, all-in-one.py file is needed anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2633
diff
changeset
|
501 |
{'short': 'l', 'type' : 'choice', 'metavar': '<log level>', |
6512522860aa
[twisted] don't use twistd anymore, all-in-one.py file is needed anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2633
diff
changeset
|
502 |
'default': None, 'choices': ('debug', 'info', 'warning', 'error'), |
6512522860aa
[twisted] don't use twistd anymore, all-in-one.py file is needed anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2633
diff
changeset
|
503 |
'help': 'debug if -D is set, error otherwise', |
6512522860aa
[twisted] don't use twistd anymore, all-in-one.py file is needed anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2633
diff
changeset
|
504 |
}), |
0 | 505 |
) |
506 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
507 |
def start_instance(self, appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
508 |
"""start the instance's server""" |
5442
3ed8afbbdf70
[webconfig] refactor/cleanup debug mode management on startup: simply use config.debugmode instead of debug argument everywhere...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5436
diff
changeset
|
509 |
config = cwcfg.config_for(appid, debugmode=self['debug']) |
5814
51cc4b61f9ae
[repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5811
diff
changeset
|
510 |
init_cmdline_log_threshold(config, self['loglevel']) |
3182 | 511 |
if self['profile']: |
0 | 512 |
config.global_set_option('profile', self.config.profile) |
513 |
helper = self.config_helper(config, cmdname='start') |
|
514 |
pidf = config['pid-file'] |
|
5814
51cc4b61f9ae
[repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5811
diff
changeset
|
515 |
if exists(pidf) and not self['force']: |
0 | 516 |
msg = "%s seems to be running. Remove %s by hand if necessary or use \ |
517 |
the --force option." |
|
518 |
raise ExecutionError(msg % (appid, pidf)) |
|
6778
7dd4835d5198
properly tell we've started an instance (close #1391262)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6675
diff
changeset
|
519 |
if helper.start_server(config) == 1: |
7dd4835d5198
properly tell we've started an instance (close #1391262)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6675
diff
changeset
|
520 |
print 'instance %s started' % appid |
0 | 521 |
|
522 |
||
5814
51cc4b61f9ae
[repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5811
diff
changeset
|
523 |
def init_cmdline_log_threshold(config, loglevel): |
51cc4b61f9ae
[repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5811
diff
changeset
|
524 |
if loglevel is not None: |
51cc4b61f9ae
[repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5811
diff
changeset
|
525 |
config.global_set_option('log-threshold', loglevel.upper()) |
51cc4b61f9ae
[repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5811
diff
changeset
|
526 |
config.init_log(config['log-threshold'], force=True) |
51cc4b61f9ae
[repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5811
diff
changeset
|
527 |
|
51cc4b61f9ae
[repo] fix 'c-c start --loglevel LEVEL' for repository only configuration. Closes #1058269.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5811
diff
changeset
|
528 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
529 |
class StopInstanceCommand(InstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
530 |
"""Stop the given instances. |
1446 | 531 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
532 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
533 |
identifiers of the instances to stop. If no instance is |
0 | 534 |
given, stop them all. |
535 |
""" |
|
536 |
name = 'stop' |
|
537 |
actionverb = 'stopped' |
|
1446 | 538 |
|
0 | 539 |
def ordered_instances(self): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
540 |
instances = super(StopInstanceCommand, self).ordered_instances() |
0 | 541 |
instances.reverse() |
542 |
return instances |
|
1446 | 543 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
544 |
def stop_instance(self, appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
545 |
"""stop the instance's server""" |
1132 | 546 |
config = cwcfg.config_for(appid) |
0 | 547 |
helper = self.config_helper(config, cmdname='stop') |
548 |
helper.poststop() # do this anyway |
|
549 |
pidf = config['pid-file'] |
|
550 |
if not exists(pidf): |
|
551 |
print >> sys.stderr, "%s doesn't exist." % pidf |
|
552 |
return |
|
553 |
import signal |
|
554 |
pid = int(open(pidf).read().strip()) |
|
555 |
try: |
|
556 |
kill(pid, signal.SIGTERM) |
|
557 |
except: |
|
558 |
print >> sys.stderr, "process %s seems already dead." % pid |
|
559 |
else: |
|
560 |
try: |
|
561 |
wait_process_end(pid) |
|
562 |
except ExecutionError, ex: |
|
563 |
print >> sys.stderr, ex |
|
564 |
print >> sys.stderr, 'trying SIGKILL' |
|
565 |
try: |
|
566 |
kill(pid, signal.SIGKILL) |
|
567 |
except: |
|
568 |
# probably dead now |
|
569 |
pass |
|
570 |
wait_process_end(pid) |
|
571 |
try: |
|
572 |
remove(pidf) |
|
573 |
except OSError: |
|
574 |
# already removed by twistd |
|
575 |
pass |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
576 |
print 'instance %s stopped' % appid |
1446 | 577 |
|
0 | 578 |
|
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
579 |
class RestartInstanceCommand(StartInstanceCommand): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
580 |
"""Restart the given instances. |
1446 | 581 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
582 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
583 |
identifiers of the instances to restart. If no instance is |
0 | 584 |
given, restart them all. |
585 |
""" |
|
586 |
name = 'restart' |
|
587 |
actionverb = 'restarted' |
|
588 |
||
589 |
def run_args(self, args, askconfirm): |
|
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4798
diff
changeset
|
590 |
regdir = cwcfg.instances_dir() |
0 | 591 |
if not isfile(join(regdir, 'startorder')) or len(args) <= 1: |
592 |
# no specific startorder |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
593 |
super(RestartInstanceCommand, self).run_args(args, askconfirm) |
0 | 594 |
return |
595 |
print ('some specific start order is specified, will first stop all ' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
596 |
'instances then restart them.') |
0 | 597 |
# get instances in startorder |
598 |
for appid in args: |
|
599 |
if askconfirm: |
|
600 |
print '*'*72 |
|
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
601 |
if not ASK.confirm('%s instance %r ?' % (self.name, appid)): |
0 | 602 |
continue |
6145
528be1e059aa
more cwctl api update and fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6144
diff
changeset
|
603 |
StopInstanceCommand(self.logger).stop_instance(appid) |
0 | 604 |
forkcmd = [w for w in sys.argv if not w in args] |
605 |
forkcmd[1] = 'start' |
|
606 |
forkcmd = ' '.join(forkcmd) |
|
607 |
for appid in reversed(args): |
|
608 |
status = system('%s %s' % (forkcmd, appid)) |
|
609 |
if status: |
|
610 |
sys.exit(status) |
|
1446 | 611 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
612 |
def restart_instance(self, appid): |
6145
528be1e059aa
more cwctl api update and fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6144
diff
changeset
|
613 |
StopInstanceCommand(self.logger).stop_instance(appid) |
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
614 |
self.start_instance(appid) |
0 | 615 |
|
1446 | 616 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
617 |
class ReloadConfigurationCommand(RestartInstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
618 |
"""Reload the given instances. This command is equivalent to a |
0 | 619 |
restart for now. |
1446 | 620 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
621 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
622 |
identifiers of the instances to reload. If no instance is |
0 | 623 |
given, reload them all. |
624 |
""" |
|
625 |
name = 'reload' |
|
1446 | 626 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
627 |
def reload_instance(self, appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
628 |
self.restart_instance(appid) |
1446 | 629 |
|
0 | 630 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
631 |
class StatusCommand(InstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
632 |
"""Display status information about the given instances. |
1446 | 633 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
634 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
635 |
identifiers of the instances to status. If no instance is |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
636 |
given, get status information about all registered instances. |
0 | 637 |
""" |
638 |
name = 'status' |
|
639 |
options = () |
|
640 |
||
1132 | 641 |
@staticmethod |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
642 |
def status_instance(appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
643 |
"""print running status information for an instance""" |
5380
a4e7e87d315f
[c-c status] return status code 1 when some instances isn't running. Closes #510817
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5323
diff
changeset
|
644 |
status = 0 |
1132 | 645 |
for mode in cwcfg.possible_configurations(appid): |
646 |
config = cwcfg.config_for(appid, mode) |
|
0 | 647 |
print '[%s-%s]' % (appid, mode), |
648 |
try: |
|
649 |
pidf = config['pid-file'] |
|
650 |
except KeyError: |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
651 |
print 'buggy instance, pid file not specified' |
0 | 652 |
continue |
653 |
if not exists(pidf): |
|
654 |
print "doesn't seem to be running" |
|
5380
a4e7e87d315f
[c-c status] return status code 1 when some instances isn't running. Closes #510817
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5323
diff
changeset
|
655 |
status = 1 |
0 | 656 |
continue |
657 |
pid = int(open(pidf).read().strip()) |
|
658 |
# trick to guess whether or not the process is running |
|
659 |
try: |
|
660 |
getpgid(pid) |
|
661 |
except OSError: |
|
662 |
print "should be running with pid %s but the process can not be found" % pid |
|
5380
a4e7e87d315f
[c-c status] return status code 1 when some instances isn't running. Closes #510817
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5323
diff
changeset
|
663 |
status = 1 |
0 | 664 |
continue |
665 |
print "running with pid %s" % (pid) |
|
5380
a4e7e87d315f
[c-c status] return status code 1 when some instances isn't running. Closes #510817
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5323
diff
changeset
|
666 |
return status |
0 | 667 |
|
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
668 |
class UpgradeInstanceCommand(InstanceCommandFork): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
669 |
"""Upgrade an instance after cubicweb and/or component(s) upgrade. |
0 | 670 |
|
671 |
For repository update, you will be prompted for a login / password to use |
|
672 |
to connect to the system database. For some upgrades, the given user |
|
673 |
should have create or alter table permissions. |
|
674 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
675 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
676 |
identifiers of the instances to upgrade. If no instance is |
0 | 677 |
given, upgrade them all. |
678 |
""" |
|
679 |
name = 'upgrade' |
|
680 |
actionverb = 'upgraded' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
681 |
options = InstanceCommand.options + ( |
7028
e8855733b125
[c-c upgrade] rename force-componant-version option to force-cube-version and cleanup code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6914
diff
changeset
|
682 |
('force-cube-version', |
e8855733b125
[c-c upgrade] rename force-componant-version option to force-cube-version and cleanup code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6914
diff
changeset
|
683 |
{'short': 't', 'type' : 'named', 'metavar': 'cube1:X.Y.Z,cube2:X.Y.Z', |
0 | 684 |
'default': None, |
7028
e8855733b125
[c-c upgrade] rename force-componant-version option to force-cube-version and cleanup code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6914
diff
changeset
|
685 |
'help': 'force migration from the indicated version for the specified cube(s).'}), |
e8855733b125
[c-c upgrade] rename force-componant-version option to force-cube-version and cleanup code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6914
diff
changeset
|
686 |
|
0 | 687 |
('force-cubicweb-version', |
688 |
{'short': 'e', 'type' : 'string', 'metavar': 'X.Y.Z', |
|
689 |
'default': None, |
|
690 |
'help': 'force migration from the indicated cubicweb version.'}), |
|
1446 | 691 |
|
0 | 692 |
('fs-only', |
693 |
{'short': 's', 'action' : 'store_true', |
|
694 |
'default': False, |
|
695 |
'help': 'only upgrade files on the file system, not the database.'}), |
|
696 |
||
697 |
('nostartstop', |
|
698 |
{'short': 'n', 'action' : 'store_true', |
|
699 |
'default': False, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
700 |
'help': 'don\'t try to stop instance before migration and to restart it after.'}), |
1446 | 701 |
|
0 | 702 |
('verbosity', |
703 |
{'short': 'v', 'type' : 'int', 'metavar': '<0..2>', |
|
704 |
'default': 1, |
|
705 |
'help': "0: no confirmation, 1: only main commands confirmed, 2 ask \ |
|
706 |
for everything."}), |
|
1446 | 707 |
|
0 | 708 |
('backup-db', |
709 |
{'short': 'b', 'type' : 'yn', 'metavar': '<y or n>', |
|
710 |
'default': None, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
711 |
'help': "Backup the instance database before upgrade.\n"\ |
0 | 712 |
"If the option is ommitted, confirmation will be ask.", |
713 |
}), |
|
714 |
||
715 |
('ext-sources', |
|
716 |
{'short': 'E', 'type' : 'csv', 'metavar': '<sources>', |
|
717 |
'default': None, |
|
718 |
'help': "For multisources instances, specify to which sources the \ |
|
719 |
repository should connect to for upgrading. When unspecified or 'migration' is \ |
|
720 |
given, appropriate sources for migration will be automatically selected \ |
|
721 |
(recommended). If 'all' is given, will connect to all defined sources.", |
|
722 |
}), |
|
723 |
) |
|
724 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
725 |
def upgrade_instance(self, appid): |
2512
106b2a05dc88
[cleanup] started to improve cubicweb-ctl dialog messages consistency
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2489
diff
changeset
|
726 |
print '\n' + underline_title('Upgrading the instance %s' % appid) |
0 | 727 |
from logilab.common.changelog import Version |
1132 | 728 |
config = cwcfg.config_for(appid) |
2473
490f88fb99b6
new distinguish repairing/creating from regular start.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2395
diff
changeset
|
729 |
config.repairing = True # notice we're not starting the server |
0 | 730 |
config.verbosity = self.config.verbosity |
7577
9892937d9041
[all] remove pattern "try: function() except AttributeError: pass" (closes #1787966)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7538
diff
changeset
|
731 |
set_sources_mode = getattr(config, 'set_sources_mode', None) |
9892937d9041
[all] remove pattern "try: function() except AttributeError: pass" (closes #1787966)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7538
diff
changeset
|
732 |
if set_sources_mode is not None: |
9892937d9041
[all] remove pattern "try: function() except AttributeError: pass" (closes #1787966)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7538
diff
changeset
|
733 |
set_sources_mode(self.config.ext_sources or ('migration',)) |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
734 |
# get instance and installed versions for the server and the componants |
0 | 735 |
mih = config.migration_handler() |
736 |
repo = mih.repo_connect() |
|
737 |
vcconf = repo.get_versions() |
|
7028
e8855733b125
[c-c upgrade] rename force-componant-version option to force-cube-version and cleanup code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6914
diff
changeset
|
738 |
if self.config.force_cube_version: |
e8855733b125
[c-c upgrade] rename force-componant-version option to force-cube-version and cleanup code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6914
diff
changeset
|
739 |
for cube, version in self.config.force_cube_version.iteritems(): |
e8855733b125
[c-c upgrade] rename force-componant-version option to force-cube-version and cleanup code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6914
diff
changeset
|
740 |
vcconf[cube] = Version(version) |
0 | 741 |
toupgrade = [] |
742 |
for cube in config.cubes(): |
|
743 |
installedversion = config.cube_version(cube) |
|
744 |
try: |
|
745 |
applversion = vcconf[cube] |
|
746 |
except KeyError: |
|
747 |
config.error('no version information for %s' % cube) |
|
748 |
continue |
|
749 |
if installedversion > applversion: |
|
750 |
toupgrade.append( (cube, applversion, installedversion) ) |
|
1446 | 751 |
cubicwebversion = config.cubicweb_version() |
0 | 752 |
if self.config.force_cubicweb_version: |
753 |
applcubicwebversion = Version(self.config.force_cubicweb_version) |
|
754 |
vcconf['cubicweb'] = applcubicwebversion |
|
755 |
else: |
|
756 |
applcubicwebversion = vcconf.get('cubicweb') |
|
757 |
if cubicwebversion > applcubicwebversion: |
|
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2156
diff
changeset
|
758 |
toupgrade.append(('cubicweb', applcubicwebversion, cubicwebversion)) |
1404
971b19de6b85
stop application only once we're sure we've something to do, fixing #342689
sylvain.thenault@logilab.fr
parents:
1219
diff
changeset
|
759 |
# only stop once we're sure we have something to do |
3638
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3619
diff
changeset
|
760 |
if not (CWDEV or self.config.nostartstop): |
6145
528be1e059aa
more cwctl api update and fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6144
diff
changeset
|
761 |
StopInstanceCommand(self.logger).stop_instance(appid) |
0 | 762 |
# run cubicweb/componants migration scripts |
7538
849c04098f3f
[migration] when there are no data migration needed, we still want to rewrite the configuration and to restart the server. Closes #1760927
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7372
diff
changeset
|
763 |
if self.config.fs_only or toupgrade: |
849c04098f3f
[migration] when there are no data migration needed, we still want to rewrite the configuration and to restart the server. Closes #1760927
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7372
diff
changeset
|
764 |
for cube, fromversion, toversion in toupgrade: |
849c04098f3f
[migration] when there are no data migration needed, we still want to rewrite the configuration and to restart the server. Closes #1760927
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7372
diff
changeset
|
765 |
print '-> migration needed from %s to %s for %s' % (fromversion, toversion, cube) |
849c04098f3f
[migration] when there are no data migration needed, we still want to rewrite the configuration and to restart the server. Closes #1760927
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7372
diff
changeset
|
766 |
mih.migrate(vcconf, reversed(toupgrade), self.config) |
849c04098f3f
[migration] when there are no data migration needed, we still want to rewrite the configuration and to restart the server. Closes #1760927
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7372
diff
changeset
|
767 |
else: |
849c04098f3f
[migration] when there are no data migration needed, we still want to rewrite the configuration and to restart the server. Closes #1760927
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7372
diff
changeset
|
768 |
print '-> no data migration needed for instance %s.' % appid |
0 | 769 |
# rewrite main configuration file |
770 |
mih.rewrite_configuration() |
|
5796
351e84e18a61
closes #1059729: cw-ctl upgrade : i18n upgrade not performed if DB does not need upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5608
diff
changeset
|
771 |
mih.shutdown() |
351e84e18a61
closes #1059729: cw-ctl upgrade : i18n upgrade not performed if DB does not need upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5608
diff
changeset
|
772 |
# handle i18n upgrade |
351e84e18a61
closes #1059729: cw-ctl upgrade : i18n upgrade not performed if DB does not need upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5608
diff
changeset
|
773 |
if not self.i18nupgrade(config): |
351e84e18a61
closes #1059729: cw-ctl upgrade : i18n upgrade not performed if DB does not need upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5608
diff
changeset
|
774 |
return |
351e84e18a61
closes #1059729: cw-ctl upgrade : i18n upgrade not performed if DB does not need upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5608
diff
changeset
|
775 |
print |
351e84e18a61
closes #1059729: cw-ctl upgrade : i18n upgrade not performed if DB does not need upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5608
diff
changeset
|
776 |
print '-> instance migrated.' |
351e84e18a61
closes #1059729: cw-ctl upgrade : i18n upgrade not performed if DB does not need upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5608
diff
changeset
|
777 |
if not (CWDEV or self.config.nostartstop): |
351e84e18a61
closes #1059729: cw-ctl upgrade : i18n upgrade not performed if DB does not need upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5608
diff
changeset
|
778 |
# restart instance through fork to get a proper environment, avoid |
351e84e18a61
closes #1059729: cw-ctl upgrade : i18n upgrade not performed if DB does not need upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5608
diff
changeset
|
779 |
# uicfg pb (and probably gettext catalogs, to check...) |
351e84e18a61
closes #1059729: cw-ctl upgrade : i18n upgrade not performed if DB does not need upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5608
diff
changeset
|
780 |
forkcmd = '%s start %s' % (sys.argv[0], appid) |
351e84e18a61
closes #1059729: cw-ctl upgrade : i18n upgrade not performed if DB does not need upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5608
diff
changeset
|
781 |
status = system(forkcmd) |
351e84e18a61
closes #1059729: cw-ctl upgrade : i18n upgrade not performed if DB does not need upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5608
diff
changeset
|
782 |
if status: |
351e84e18a61
closes #1059729: cw-ctl upgrade : i18n upgrade not performed if DB does not need upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5608
diff
changeset
|
783 |
print '%s exited with status %s' % (forkcmd, status) |
351e84e18a61
closes #1059729: cw-ctl upgrade : i18n upgrade not performed if DB does not need upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5608
diff
changeset
|
784 |
print |
351e84e18a61
closes #1059729: cw-ctl upgrade : i18n upgrade not performed if DB does not need upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5608
diff
changeset
|
785 |
|
351e84e18a61
closes #1059729: cw-ctl upgrade : i18n upgrade not performed if DB does not need upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5608
diff
changeset
|
786 |
def i18nupgrade(self, config): |
0 | 787 |
# handle i18n upgrade: |
788 |
# * install new languages |
|
789 |
# * recompile catalogs |
|
5092
e126becc1263
[upgrade] after upgrade, fork command to start instance avoid grave uicfg pb (explicit rules all removed...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5043
diff
changeset
|
790 |
# XXX search available language in the first cube given |
4021
280c910c8710
move i18n / migration modules from cw.common to cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3720
diff
changeset
|
791 |
from cubicweb import i18n |
1132 | 792 |
templdir = cwcfg.cube_dir(config.cubes()[0]) |
0 | 793 |
langs = [lang for lang, _ in i18n.available_catalogs(join(templdir, 'i18n'))] |
794 |
errors = config.i18ncompile(langs) |
|
795 |
if errors: |
|
796 |
print '\n'.join(errors) |
|
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
797 |
if not ASK.confirm('Error while compiling message catalogs, ' |
5796
351e84e18a61
closes #1059729: cw-ctl upgrade : i18n upgrade not performed if DB does not need upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5608
diff
changeset
|
798 |
'continue anyway?'): |
2512
106b2a05dc88
[cleanup] started to improve cubicweb-ctl dialog messages consistency
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2489
diff
changeset
|
799 |
print '-> migration not completed.' |
5796
351e84e18a61
closes #1059729: cw-ctl upgrade : i18n upgrade not performed if DB does not need upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5608
diff
changeset
|
800 |
return False |
351e84e18a61
closes #1059729: cw-ctl upgrade : i18n upgrade not performed if DB does not need upgrade
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5608
diff
changeset
|
801 |
return True |
0 | 802 |
|
7591
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
803 |
|
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
804 |
class ListVersionsInstanceCommand(InstanceCommand): |
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
805 |
"""List versions used by an instance. |
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
806 |
|
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
807 |
<instance>... |
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
808 |
identifiers of the instances to list versions for. |
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
809 |
""" |
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
810 |
name = 'versions' |
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
811 |
|
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
812 |
def versions_instance(self, appid): |
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
813 |
from logilab.common.changelog import Version |
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
814 |
config = cwcfg.config_for(appid) |
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
815 |
# should not raise error if db versions don't match fs versions |
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
816 |
config.repairing = True |
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
817 |
if hasattr(config, 'set_sources_mode'): |
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
818 |
config.set_sources_mode(('migration',)) |
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
819 |
repo = config.migration_handler().repo_connect() |
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
820 |
vcconf = repo.get_versions() |
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
821 |
for key in sorted(vcconf): |
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
822 |
print key+': %s.%s.%s' % vcconf[key] |
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
823 |
|
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
824 |
|
0 | 825 |
class ShellCommand(Command): |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
826 |
"""Run an interactive migration shell on an instance. This is a python shell |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
827 |
with enhanced migration commands predefined in the namespace. An additional |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
828 |
argument may be given corresponding to a file containing commands to execute |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
829 |
in batch mode. |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
830 |
|
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
831 |
By default it will connect to a local instance using an in memory |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
832 |
connection, unless -P option is specified, in which case you will be |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
833 |
connected through pyro. In the later case, you won't have access to |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
834 |
repository internals (session, etc...) so most migration commands won't be |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
835 |
available. |
0 | 836 |
|
5430
ed8f71e244f8
[shell] #715938: support of script parameters (using standard '--' as arguments separator)
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5426
diff
changeset
|
837 |
Arguments after bare "--" string will not be processed by the shell command |
ed8f71e244f8
[shell] #715938: support of script parameters (using standard '--' as arguments separator)
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5426
diff
changeset
|
838 |
You can use it to pass extra arguments to your script and expect for |
5436
2455ca3a2a3a
[c-c shell] make script arguments available as __args__ in the script namespace. Use scriptargs instead of args as process_script argument name.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5430
diff
changeset
|
839 |
them in '__args__' afterwards. |
5430
ed8f71e244f8
[shell] #715938: support of script parameters (using standard '--' as arguments separator)
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5426
diff
changeset
|
840 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
841 |
<instance> |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
842 |
the identifier of the instance to connect. |
0 | 843 |
""" |
844 |
name = 'shell' |
|
5430
ed8f71e244f8
[shell] #715938: support of script parameters (using standard '--' as arguments separator)
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5426
diff
changeset
|
845 |
arguments = '<instance> [batch command file(s)] [-- <script arguments>]' |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
846 |
min_args = 1 |
0 | 847 |
options = ( |
848 |
('system-only', |
|
849 |
{'short': 'S', 'action' : 'store_true', |
|
850 |
'help': 'only connect to the system source when the instance is ' |
|
851 |
'using multiple sources. You can\'t use this option and the ' |
|
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
852 |
'--ext-sources option at the same time.', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
853 |
'group': 'local' |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
854 |
}), |
1446 | 855 |
|
0 | 856 |
('ext-sources', |
857 |
{'short': 'E', 'type' : 'csv', 'metavar': '<sources>', |
|
858 |
'help': "For multisources instances, specify to which sources the \ |
|
859 |
repository should connect to for upgrading. When unspecified or 'all' given, \ |
|
860 |
will connect to all defined sources. If 'migration' is given, appropriate \ |
|
861 |
sources for migration will be automatically selected.", |
|
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
862 |
'group': 'local' |
0 | 863 |
}), |
1446 | 864 |
|
2905
b23bbb31368c
backport change from default to get -f option on cw shell, may be necessary for the forthcoming migration...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2743
diff
changeset
|
865 |
('force', |
b23bbb31368c
backport change from default to get -f option on cw shell, may be necessary for the forthcoming migration...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2743
diff
changeset
|
866 |
{'short': 'f', 'action' : 'store_true', |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
867 |
'help': 'don\'t check instance is up to date.', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
868 |
'group': 'local' |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
869 |
}), |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
870 |
|
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
871 |
('pyro', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
872 |
{'short': 'P', 'action' : 'store_true', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
873 |
'help': 'connect to a running instance through Pyro.', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
874 |
'group': 'remote', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
875 |
}), |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
876 |
('pyro-ns-host', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
877 |
{'short': 'H', 'type' : 'string', 'metavar': '<host[:port]>', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
878 |
'help': 'Pyro name server host. If not set, will be detected by ' |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
879 |
'using a broadcast query.', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
880 |
'group': 'remote' |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
881 |
}), |
0 | 882 |
) |
2905
b23bbb31368c
backport change from default to get -f option on cw shell, may be necessary for the forthcoming migration...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2743
diff
changeset
|
883 |
|
0 | 884 |
def run(self, args): |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
885 |
appid = args.pop(0) |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
886 |
if self.config.pyro: |
3707
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
887 |
from cubicweb import AuthenticationError |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
888 |
from cubicweb.dbapi import connect |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
889 |
from cubicweb.server.utils import manager_userpasswd |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
890 |
from cubicweb.server.migractions import ServerMigrationHelper |
3707
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
891 |
while True: |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
892 |
try: |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
893 |
login, pwd = manager_userpasswd(msg=None) |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
894 |
cnx = connect(appid, login=login, password=pwd, |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
895 |
host=self.config.pyro_ns_host, mulcnx=False) |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
896 |
except AuthenticationError, ex: |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
897 |
print ex |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
898 |
except (KeyboardInterrupt, EOFError): |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
899 |
print |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
900 |
sys.exit(0) |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
901 |
else: |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
902 |
break |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
903 |
cnx.load_appobjects() |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
904 |
repo = cnx._repo |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
905 |
mih = ServerMigrationHelper(None, repo=repo, cnx=cnx, |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
906 |
# hack so it don't try to load fs schema |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
907 |
schema=1) |
0 | 908 |
else: |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
909 |
config = cwcfg.config_for(appid) |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
910 |
if self.config.ext_sources: |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
911 |
assert not self.config.system_only |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
912 |
sources = self.config.ext_sources |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
913 |
elif self.config.system_only: |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
914 |
sources = ('system',) |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
915 |
else: |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
916 |
sources = ('all',) |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
917 |
config.set_sources_mode(sources) |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
918 |
config.repairing = self.config.force |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
919 |
mih = config.migration_handler() |
3709
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
920 |
try: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
921 |
if args: |
5430
ed8f71e244f8
[shell] #715938: support of script parameters (using standard '--' as arguments separator)
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5426
diff
changeset
|
922 |
# use cmdline parser to access left/right attributes only |
ed8f71e244f8
[shell] #715938: support of script parameters (using standard '--' as arguments separator)
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5426
diff
changeset
|
923 |
# remember that usage requires instance appid as first argument |
ed8f71e244f8
[shell] #715938: support of script parameters (using standard '--' as arguments separator)
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5426
diff
changeset
|
924 |
scripts, args = self.cmdline_parser.largs[1:], self.cmdline_parser.rargs |
ed8f71e244f8
[shell] #715938: support of script parameters (using standard '--' as arguments separator)
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5426
diff
changeset
|
925 |
for script in scripts: |
5436
2455ca3a2a3a
[c-c shell] make script arguments available as __args__ in the script namespace. Use scriptargs instead of args as process_script argument name.
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5430
diff
changeset
|
926 |
mih.cmd_process_script(script, scriptargs=args) |
7372
65bd75f16d65
[c-c shell] we should commit the migration handler, cnx is not None unless connected through pyro
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7369
diff
changeset
|
927 |
mih.commit() |
3709
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
928 |
else: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
929 |
mih.interactive_shell() |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
930 |
finally: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
931 |
if not self.config.pyro: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
932 |
mih.shutdown() |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
933 |
else: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
934 |
cnx.close() |
0 | 935 |
|
936 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
937 |
class RecompileInstanceCatalogsCommand(InstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
938 |
"""Recompile i18n catalogs for instances. |
1446 | 939 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
940 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
941 |
identifiers of the instances to consider. If no instance is |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
942 |
given, recompile for all registered instances. |
0 | 943 |
""" |
1898
39b37f90a8a4
[cw-ctl] rename i18n commands (see #342889)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1477
diff
changeset
|
944 |
name = 'i18ninstance' |
1132 | 945 |
|
946 |
@staticmethod |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
947 |
def i18ninstance_instance(appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
948 |
"""recompile instance's messages catalogs""" |
1132 | 949 |
config = cwcfg.config_for(appid) |
5043
fe52dd3936cf
[repo config] cleanup read_instance_schema / bootstrap_schema / creating mess
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5042
diff
changeset
|
950 |
config.quick_start = True # notify this is not a regular start |
5042
cc062bb09abb
fix #726167: i18ninstance use data in bootstrab_cubes instead of the database one
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4798
diff
changeset
|
951 |
repo = config.repository() |
cc062bb09abb
fix #726167: i18ninstance use data in bootstrab_cubes instead of the database one
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4798
diff
changeset
|
952 |
if config._cubes is None: |
0 | 953 |
# web only config |
5042
cc062bb09abb
fix #726167: i18ninstance use data in bootstrab_cubes instead of the database one
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4798
diff
changeset
|
954 |
config.init_cubes(repo.get_cubes()) |
0 | 955 |
errors = config.i18ncompile() |
956 |
if errors: |
|
957 |
print '\n'.join(errors) |
|
958 |
||
959 |
||
960 |
class ListInstancesCommand(Command): |
|
961 |
"""list available instances, useful for bash completion.""" |
|
962 |
name = 'listinstances' |
|
963 |
hidden = True |
|
1446 | 964 |
|
0 | 965 |
def run(self, args): |
966 |
"""run the command with its specific arguments""" |
|
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4798
diff
changeset
|
967 |
regdir = cwcfg.instances_dir() |
0 | 968 |
for appid in sorted(listdir(regdir)): |
969 |
print appid |
|
970 |
||
971 |
||
972 |
class ListCubesCommand(Command): |
|
973 |
"""list available componants, useful for bash completion.""" |
|
974 |
name = 'listcubes' |
|
975 |
hidden = True |
|
1446 | 976 |
|
0 | 977 |
def run(self, args): |
978 |
"""run the command with its specific arguments""" |
|
1132 | 979 |
for cube in cwcfg.available_cubes(): |
0 | 980 |
print cube |
981 |
||
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
982 |
for cmdcls in (ListCommand, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
983 |
CreateInstanceCommand, DeleteInstanceCommand, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
984 |
StartInstanceCommand, StopInstanceCommand, RestartInstanceCommand, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
985 |
ReloadConfigurationCommand, StatusCommand, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
986 |
UpgradeInstanceCommand, |
7591
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
987 |
ListVersionsInstanceCommand, |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
988 |
ShellCommand, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
989 |
RecompileInstanceCatalogsCommand, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
990 |
ListInstancesCommand, ListCubesCommand, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
991 |
): |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
992 |
CWCTL.register(cmdcls) |
0 | 993 |
|
1446 | 994 |
|
0 | 995 |
def run(args): |
996 |
"""command line tool""" |
|
6562
34be5986bca0
make stdout and stderr non buffered for cwctl commands (#1330647)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6505
diff
changeset
|
997 |
import os |
34be5986bca0
make stdout and stderr non buffered for cwctl commands (#1330647)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6505
diff
changeset
|
998 |
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) |
34be5986bca0
make stdout and stderr non buffered for cwctl commands (#1330647)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6505
diff
changeset
|
999 |
sys.stderr = os.fdopen(sys.stderr.fileno(), 'w', 0) |
1132 | 1000 |
cwcfg.load_cwctl_plugins() |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
1001 |
try: |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
1002 |
CWCTL.run(args) |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
1003 |
except ConfigurationError, err: |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
1004 |
print 'ERROR: ', err |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
1005 |
sys.exit(1) |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
1006 |
except ExecutionError, err: |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
1007 |
print err |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
1008 |
sys.exit(2) |
0 | 1009 |
|
1010 |
if __name__ == '__main__': |
|
1011 |
run(sys.argv[1:]) |