author | Alexandre Fayolle <alexandre.fayolle@logilab.fr> |
Sat, 19 Jun 2010 16:08:08 +0200 | |
branch | stable |
changeset 5798 | 74d9a062965c |
parent 5796 | 351e84e18a61 |
child 5811 | e77cea9721e7 |
permissions | -rw-r--r-- |
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
|
1 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
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. |
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
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 |
""" |
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
23 |
__docformat__ = "restructuredtext en" |
0 | 24 |
|
4718
3dc3ad02d091
avoid module import in c-c plugins module, and remind it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4684
diff
changeset
|
25 |
# *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
|
26 |
# 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
|
27 |
# completion). So import locally in command helpers. |
0 | 28 |
import sys |
5025
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
29 |
from warnings import warn |
3115
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
2905
diff
changeset
|
30 |
from os import remove, listdir, system, pathsep |
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
2905
diff
changeset
|
31 |
try: |
3562 | 32 |
from os import kill, getpgid |
3115
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
2905
diff
changeset
|
33 |
except ImportError: |
4721
8f63691ccb7f
pylint style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4720
diff
changeset
|
34 |
def kill(*args): |
8f63691ccb7f
pylint style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4720
diff
changeset
|
35 |
"""win32 kill implementation""" |
8f63691ccb7f
pylint style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4720
diff
changeset
|
36 |
def getpgid(): |
8f63691ccb7f
pylint style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4720
diff
changeset
|
37 |
"""win32 getpgid implementation""" |
3115
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
2905
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 |
|
1132 | 41 |
from logilab.common.clcommands import register_commands, pop_arg |
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 |
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
|
45 |
from cubicweb.cwconfig import CubicWebConfiguration as cwcfg, CWDEV, CONFIGURATIONS |
2790
968108e16066
move underline_title to toolsutils
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2743
diff
changeset
|
46 |
from cubicweb.toolsutils import Command, main_run, rm, create_dir, underline_title |
1446 | 47 |
|
0 | 48 |
def wait_process_end(pid, maxtry=10, waittime=1): |
49 |
"""wait for a process to actually die""" |
|
50 |
import signal |
|
51 |
from time import sleep |
|
52 |
nbtry = 0 |
|
53 |
while nbtry < maxtry: |
|
54 |
try: |
|
55 |
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
|
56 |
except (OSError, AttributeError): # XXX win32 |
0 | 57 |
break |
58 |
nbtry += 1 |
|
59 |
sleep(waittime) |
|
60 |
else: |
|
61 |
raise ExecutionError('can\'t kill process %s' % pid) |
|
62 |
||
63 |
def list_instances(regdir): |
|
64 |
return sorted(idir for idir in listdir(regdir) if isdir(join(regdir, idir))) |
|
65 |
||
66 |
def detect_available_modes(templdir): |
|
67 |
modes = [] |
|
68 |
for fname in ('schema', 'schema.py'): |
|
69 |
if exists(join(templdir, fname)): |
|
70 |
modes.append('repository') |
|
71 |
break |
|
72 |
for fname in ('data', 'views', 'views.py'): |
|
73 |
if exists(join(templdir, fname)): |
|
74 |
modes.append('web ui') |
|
75 |
break |
|
76 |
return modes |
|
1446 | 77 |
|
78 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
79 |
class InstanceCommand(Command): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
80 |
"""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
|
81 |
(0 meaning all registered instances) |
0 | 82 |
""" |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
83 |
arguments = '[<instance>...]' |
0 | 84 |
options = ( |
85 |
("force", |
|
86 |
{'short': 'f', 'action' : 'store_true', |
|
87 |
'default': False, |
|
88 |
'help': 'force command without asking confirmation', |
|
89 |
} |
|
90 |
), |
|
91 |
) |
|
92 |
actionverb = None |
|
1446 | 93 |
|
0 | 94 |
def ordered_instances(self): |
95 |
"""return instances in the order in which they should be started, |
|
96 |
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
|
97 |
some instances depends on another as external source). |
af81a4f7053e
enhance docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3562
diff
changeset
|
98 |
|
af81a4f7053e
enhance docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3562
diff
changeset
|
99 |
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
|
100 |
instance per line) |
0 | 101 |
""" |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4798
diff
changeset
|
102 |
regdir = cwcfg.instances_dir() |
0 | 103 |
_allinstances = list_instances(regdir) |
104 |
if isfile(join(regdir, 'startorder')): |
|
105 |
allinstances = [] |
|
106 |
for line in file(join(regdir, 'startorder')): |
|
107 |
line = line.strip() |
|
108 |
if line and not line.startswith('#'): |
|
109 |
try: |
|
110 |
_allinstances.remove(line) |
|
111 |
allinstances.append(line) |
|
112 |
except ValueError: |
|
1132 | 113 |
print ('ERROR: startorder file contains unexistant ' |
114 |
'instance %s' % line) |
|
0 | 115 |
allinstances += _allinstances |
116 |
else: |
|
117 |
allinstances = _allinstances |
|
118 |
return allinstances |
|
1446 | 119 |
|
0 | 120 |
def run(self, args): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
121 |
"""run the <command>_method on each argument (a list of instance |
0 | 122 |
identifiers) |
123 |
""" |
|
124 |
if not args: |
|
125 |
args = self.ordered_instances() |
|
126 |
try: |
|
127 |
askconfirm = not self.config.force |
|
128 |
except AttributeError: |
|
129 |
# no force option |
|
130 |
askconfirm = False |
|
131 |
else: |
|
132 |
askconfirm = False |
|
133 |
self.run_args(args, askconfirm) |
|
1446 | 134 |
|
0 | 135 |
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
|
136 |
status = 0 |
0 | 137 |
for appid in args: |
138 |
if askconfirm: |
|
139 |
print '*'*72 |
|
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
140 |
if not ASK.confirm('%s instance %r ?' % (self.name, appid)): |
0 | 141 |
continue |
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
|
142 |
status = max(status, self.run_arg(appid)) |
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
|
143 |
sys.exit(status) |
1446 | 144 |
|
0 | 145 |
def run_arg(self, appid): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
146 |
cmdmeth = getattr(self, '%s_instance' % self.name) |
0 | 147 |
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
|
148 |
status = cmdmeth(appid) |
0 | 149 |
except (KeyboardInterrupt, SystemExit): |
150 |
print >> sys.stderr, '%s aborted' % self.name |
|
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
|
151 |
return 2 # specific error code |
0 | 152 |
except (ExecutionError, ConfigurationError), ex: |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
153 |
print >> sys.stderr, 'instance %s not %s: %s' % ( |
0 | 154 |
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
|
155 |
status = 4 |
0 | 156 |
except Exception, ex: |
157 |
import traceback |
|
158 |
traceback.print_exc() |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
159 |
print >> sys.stderr, 'instance %s not %s: %s' % ( |
0 | 160 |
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
|
161 |
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
|
162 |
return status |
0 | 163 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
164 |
class InstanceCommandFork(InstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
165 |
"""Same as `InstanceCommand`, but command is forked in a new environment |
0 | 166 |
for each argument |
167 |
""" |
|
168 |
||
169 |
def run_args(self, args, askconfirm): |
|
170 |
if len(args) > 1: |
|
171 |
forkcmd = ' '.join(w for w in sys.argv if not w in args) |
|
172 |
else: |
|
173 |
forkcmd = None |
|
174 |
for appid in args: |
|
175 |
if askconfirm: |
|
176 |
print '*'*72 |
|
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
177 |
if not ASK.confirm('%s instance %r ?' % (self.name, appid)): |
0 | 178 |
continue |
179 |
if forkcmd: |
|
180 |
status = system('%s %s' % (forkcmd, appid)) |
|
181 |
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
|
182 |
print '%s exited with status %s' % (forkcmd, status) |
0 | 183 |
else: |
184 |
self.run_arg(appid) |
|
1446 | 185 |
|
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
186 |
|
0 | 187 |
# base commands ############################################################### |
188 |
||
189 |
class ListCommand(Command): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
190 |
"""List configurations, cubes and instances. |
0 | 191 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
192 |
list available configurations, installed cubes, and registered instances |
0 | 193 |
""" |
194 |
name = 'list' |
|
195 |
options = ( |
|
196 |
('verbose', |
|
1446 | 197 |
{'short': 'v', 'action' : 'store_true', |
198 |
'help': "display more information."}), |
|
0 | 199 |
) |
1446 | 200 |
|
0 | 201 |
def run(self, args): |
202 |
"""run the command with its specific arguments""" |
|
203 |
if args: |
|
5608
f9ab62103ad4
proof read documentation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5498
diff
changeset
|
204 |
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
|
205 |
from cubicweb.migration import ConfigurationProblem |
3486
ea6bf6f9ba0c
[cwctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3198
diff
changeset
|
206 |
print 'CubicWeb %s (%s mode)' % (cwcfg.cubicweb_version(), cwcfg.mode) |
0 | 207 |
print |
208 |
print 'Available configurations:' |
|
209 |
for config in CONFIGURATIONS: |
|
210 |
print '*', config.name |
|
211 |
for line in config.__doc__.splitlines(): |
|
212 |
line = line.strip() |
|
213 |
if not line: |
|
214 |
continue |
|
215 |
print ' ', line |
|
1446 | 216 |
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
|
217 |
cfgpb = ConfigurationProblem(cwcfg) |
0 | 218 |
try: |
1342
4273e44852cb
no more cubes_dir class method
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
219 |
cubesdir = pathsep.join(cwcfg.cubes_search_path()) |
1132 | 220 |
namesize = max(len(x) for x in cwcfg.available_cubes()) |
0 | 221 |
except ConfigurationError, ex: |
222 |
print 'No cubes available:', ex |
|
223 |
except ValueError: |
|
224 |
print 'No cubes available in %s' % cubesdir |
|
225 |
else: |
|
226 |
print 'Available cubes (%s):' % cubesdir |
|
1132 | 227 |
for cube in cwcfg.available_cubes(): |
0 | 228 |
try: |
1132 | 229 |
tinfo = cwcfg.cube_pkginfo(cube) |
0 | 230 |
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
|
231 |
cfgpb.add_cube(cube, tversion) |
0 | 232 |
except ConfigurationError: |
233 |
tinfo = None |
|
234 |
tversion = '[missing cube information]' |
|
235 |
print '* %s %s' % (cube.ljust(namesize), tversion) |
|
236 |
if self.config.verbose: |
|
5025
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
237 |
if tinfo: |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
238 |
descr = getattr(tinfo, 'description', '') |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
239 |
if not descr: |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
240 |
descr = getattr(tinfo, 'short_desc', '') |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
241 |
if descr: |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
242 |
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
|
243 |
' pkginfo' % cube, DeprecationWarning) |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
244 |
else: |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
245 |
descr = tinfo.__doc__ |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
246 |
if descr: |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
247 |
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
|
248 |
modes = detect_available_modes(cwcfg.cube_dir(cube)) |
0 | 249 |
print ' available modes: %s' % ', '.join(modes) |
250 |
print |
|
251 |
try: |
|
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4798
diff
changeset
|
252 |
regdir = cwcfg.instances_dir() |
0 | 253 |
except ConfigurationError, ex: |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
254 |
print 'No instance available:', ex |
0 | 255 |
print |
256 |
return |
|
257 |
instances = list_instances(regdir) |
|
258 |
if instances: |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
259 |
print 'Available instances (%s):' % regdir |
0 | 260 |
for appid in instances: |
1132 | 261 |
modes = cwcfg.possible_configurations(appid) |
0 | 262 |
if not modes: |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
263 |
print '* %s (BROKEN instance, no configuration found)' % appid |
0 | 264 |
continue |
265 |
print '* %s (%s)' % (appid, ', '.join(modes)) |
|
266 |
try: |
|
1132 | 267 |
config = cwcfg.config_for(appid, modes[0]) |
1446 | 268 |
except Exception, exc: |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
269 |
print ' (BROKEN instance, %s)' % exc |
0 | 270 |
continue |
271 |
else: |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
272 |
print 'No instance available in %s' % regdir |
0 | 273 |
print |
4656
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
274 |
# 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
|
275 |
cfgpb.solve() |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
276 |
if cfgpb.warnings: |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
277 |
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
|
278 |
if cfgpb.errors: |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
279 |
print 'Errors:' |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
280 |
for op, cube, version in cfgpb.errors: |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
281 |
if op == 'add': |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
282 |
print '* cube', cube, |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
283 |
if version: |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
284 |
print ' version', version, |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
285 |
print 'is not installed, but required by %s' % ' '.join(cfgpb.reverse_constraints[cube]) |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
286 |
else: |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
287 |
print '* cube %s version %s is installed, but version %s is required by (%s)' % ( |
5498
eab5540d96eb
[c-c list] configuration pb cubes directly hold version number now, avoid crash when reporting errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
288 |
cube, cfgpb.cubes[cube], version, ', '.join(cfgpb.reverse_constraints[cube])) |
0 | 289 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
290 |
class CreateInstanceCommand(Command): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
291 |
"""Create an instance from a cube. This is an unified |
0 | 292 |
command which can handle web / server / all-in-one installation |
293 |
according to available parts of the software library and of the |
|
294 |
desired cube. |
|
295 |
||
296 |
<cube> |
|
297 |
the name of cube to use (list available cube names using |
|
298 |
the "list" command). You can use several cubes by separating |
|
299 |
them using comma (e.g. 'jpl,eemail') |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
300 |
<instance> |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
301 |
an identifier for the instance to create |
0 | 302 |
""" |
303 |
name = 'create' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
304 |
arguments = '<cube> <instance>' |
0 | 305 |
options = ( |
306 |
("config-level", |
|
307 |
{'short': 'l', 'type' : 'int', 'metavar': '<level>', |
|
308 |
'default': 0, |
|
309 |
'help': 'configuration level (0..2): 0 will ask for essential \ |
|
310 |
configuration parameters only while 2 will ask for all parameters', |
|
311 |
} |
|
312 |
), |
|
313 |
("config", |
|
314 |
{'short': 'c', 'type' : 'choice', 'metavar': '<install type>', |
|
315 |
'choices': ('all-in-one', 'repository', 'twisted'), |
|
316 |
'default': 'all-in-one', |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
317 |
'help': 'installation type, telling which part of an instance \ |
0 | 318 |
should be installed. You can list available configurations using the "list" \ |
319 |
command. Default to "all-in-one", e.g. an installation embedding both the RQL \ |
|
320 |
repository and the web server.', |
|
321 |
} |
|
322 |
), |
|
323 |
) |
|
1446 | 324 |
|
0 | 325 |
def run(self, args): |
326 |
"""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
|
327 |
from logilab.common.textutils import splitstrip |
0 | 328 |
configname = self.config.config |
2633
bc9386c3b2c9
get_csv is being renamed to splitstrip
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2615
diff
changeset
|
329 |
cubes = splitstrip(pop_arg(args, 1)) |
0 | 330 |
appid = pop_arg(args) |
331 |
# get the configuration and helper |
|
1132 | 332 |
config = cwcfg.config_for(appid, configname) |
0 | 333 |
config.set_language = False |
2104
b4ffcea3275b
change cubes into expanded cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2032
diff
changeset
|
334 |
cubes = config.expand_cubes(cubes) |
b4ffcea3275b
change cubes into expanded cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2032
diff
changeset
|
335 |
config.init_cubes(cubes) |
0 | 336 |
helper = self.config_helper(config) |
337 |
# check the cube exists |
|
338 |
try: |
|
1132 | 339 |
templdirs = [cwcfg.cube_dir(cube) |
0 | 340 |
for cube in cubes] |
341 |
except ConfigurationError, ex: |
|
342 |
print ex |
|
343 |
print '\navailable cubes:', |
|
1132 | 344 |
print ', '.join(cwcfg.available_cubes()) |
0 | 345 |
return |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
346 |
# 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
|
347 |
print '\n'+underline_title('Creating the instance %s' % appid) |
0 | 348 |
create_dir(config.apphome) |
349 |
# cubicweb-ctl configuration |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
350 |
print '\n'+underline_title('Configuring the instance (%s.conf)' % configname) |
0 | 351 |
config.input_config('main', self.config.config_level) |
352 |
# configuration'specific stuff |
|
353 |
print |
|
354 |
helper.bootstrap(cubes, 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
|
355 |
# input for cubes specific options |
7bf205b9a845
when creating an instance, ask for cubes specific options properly (fix #607349)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4609
diff
changeset
|
356 |
for section in set(sect.lower() for sect, opt, optdict in config.all_options() |
5323
329b4f6d18b4
[config] with lgc >= 0.50, option's dict inputlevel becomes level
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5302
diff
changeset
|
357 |
if optdict.get('level') <= 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
|
358 |
if section not in ('main', 'email', 'pyro'): |
7bf205b9a845
when creating an instance, ask for cubes specific options properly (fix #607349)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4609
diff
changeset
|
359 |
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
|
360 |
config.input_config(section, self.config.config_level) |
0 | 361 |
# write down configuration |
362 |
config.save() |
|
4064
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
363 |
self._handle_win32(config, appid) |
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2318
diff
changeset
|
364 |
print '-> generated %s' % config.main_config_file() |
0 | 365 |
# handle i18n files structure |
366 |
# in the first cube given |
|
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2318
diff
changeset
|
367 |
print '-> preparing i18n catalogs' |
4021
280c910c8710
move i18n / migration modules from cw.common to cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3720
diff
changeset
|
368 |
from cubicweb import i18n |
0 | 369 |
langs = [lang for lang, _ in i18n.available_catalogs(join(templdirs[0], 'i18n'))] |
370 |
errors = config.i18ncompile(langs) |
|
371 |
if errors: |
|
372 |
print '\n'.join(errors) |
|
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
373 |
if not ASK.confirm('error while compiling message catalogs, ' |
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
374 |
'continue anyway ?'): |
0 | 375 |
print 'creation not completed' |
376 |
return |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
377 |
# create the additional data directory for this instance |
0 | 378 |
if config.appdatahome != config.apphome: # true in dev mode |
379 |
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
|
380 |
create_dir(join(config.appdatahome, 'backup')) |
0 | 381 |
if config['uid']: |
382 |
from logilab.common.shellutils import chown |
|
383 |
# this directory should be owned by the uid of the server process |
|
384 |
print 'set %s as owner of the data directory' % config['uid'] |
|
385 |
chown(config.appdatahome, config['uid']) |
|
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2318
diff
changeset
|
386 |
print '\n-> creation done for %r.\n' % config.apphome |
0 | 387 |
helper.postcreate() |
388 |
||
4064
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
389 |
def _handle_win32(self, config, appid): |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
390 |
if sys.platform != 'win32': |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
391 |
return |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
392 |
service_template = """ |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
393 |
import sys |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
394 |
import win32serviceutil |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
395 |
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
|
396 |
|
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
397 |
from cubicweb.etwist.service import CWService |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
398 |
|
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
399 |
classdict = {'_svc_name_': 'cubicweb-%(APPID)s', |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
400 |
'_svc_display_name_': 'CubicWeb ' + '%(CNAME)s', |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
401 |
'instance': '%(APPID)s'} |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
402 |
%(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
|
403 |
|
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
404 |
if __name__ == '__main__': |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
405 |
win32serviceutil.HandleCommandLine(%(CNAME)sService) |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
406 |
""" |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
407 |
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
|
408 |
service_template % {'APPID': appid, |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
409 |
'CNAME': appid.capitalize(), |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
410 |
'CWPATH': abspath(join(dirname(__file__), '..'))}) |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
411 |
|
1446 | 412 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
413 |
class DeleteInstanceCommand(Command): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
414 |
"""Delete an instance. Will remove instance's files and |
0 | 415 |
unregister it. |
416 |
""" |
|
417 |
name = 'delete' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
418 |
arguments = '<instance>' |
1446 | 419 |
|
0 | 420 |
options = () |
421 |
||
422 |
def run(self, args): |
|
423 |
"""run the command with its specific arguments""" |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
424 |
appid = pop_arg(args, msg="No instance specified !") |
1132 | 425 |
configs = [cwcfg.config_for(appid, configname) |
426 |
for configname in cwcfg.possible_configurations(appid)] |
|
0 | 427 |
if not configs: |
428 |
raise ExecutionError('unable to guess configuration for %s' % appid) |
|
429 |
for config in configs: |
|
430 |
helper = self.config_helper(config, required=False) |
|
431 |
if helper: |
|
432 |
helper.cleanup() |
|
433 |
# remove home |
|
434 |
rm(config.apphome) |
|
435 |
# remove instance data directory |
|
436 |
try: |
|
437 |
rm(config.appdatahome) |
|
438 |
except OSError, ex: |
|
439 |
import errno |
|
440 |
if ex.errno != errno.ENOENT: |
|
441 |
raise |
|
442 |
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
|
443 |
print '-> instance %s (%s) deleted.' % (appid, confignames) |
0 | 444 |
|
445 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
446 |
# instance commands ######################################################## |
0 | 447 |
|
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
448 |
class StartInstanceCommand(InstanceCommandFork): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
449 |
"""Start the given instances. If no instance is given, start them all. |
1446 | 450 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
451 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
452 |
identifiers of the instances to start. If no instance is |
0 | 453 |
given, start them all. |
454 |
""" |
|
455 |
name = 'start' |
|
456 |
actionverb = 'started' |
|
457 |
options = ( |
|
458 |
("debug", |
|
459 |
{'short': 'D', 'action' : 'store_true', |
|
460 |
'help': 'start server in debug mode.'}), |
|
461 |
("force", |
|
462 |
{'short': 'f', 'action' : 'store_true', |
|
463 |
'default': False, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
464 |
'help': 'start the instance even if it seems to be already \ |
0 | 465 |
running.'}), |
466 |
('profile', |
|
467 |
{'short': 'P', 'type' : 'string', 'metavar': '<stat file>', |
|
468 |
'default': None, |
|
469 |
'help': 'profile code and use the specified file to store stats', |
|
470 |
}), |
|
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
|
471 |
('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
|
472 |
{'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
|
473 |
'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
|
474 |
'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
|
475 |
}), |
0 | 476 |
) |
477 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
478 |
def start_instance(self, appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
479 |
"""start the instance's server""" |
3182 | 480 |
debug = self['debug'] |
481 |
force = self['force'] |
|
482 |
loglevel = self['loglevel'] |
|
1132 | 483 |
config = cwcfg.config_for(appid) |
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
|
484 |
if loglevel is not None: |
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
|
485 |
loglevel = 'LOG_%s' % loglevel.upper() |
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
|
486 |
config.global_set_option('log-threshold', 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
|
487 |
config.init_log(loglevel, debug=debug, force=True) |
3182 | 488 |
if self['profile']: |
0 | 489 |
config.global_set_option('profile', self.config.profile) |
490 |
helper = self.config_helper(config, cmdname='start') |
|
491 |
pidf = config['pid-file'] |
|
492 |
if exists(pidf) and not force: |
|
493 |
msg = "%s seems to be running. Remove %s by hand if necessary or use \ |
|
494 |
the --force option." |
|
495 |
raise ExecutionError(msg % (appid, pidf)) |
|
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
496 |
helper.start_server(config, debug) |
0 | 497 |
|
498 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
499 |
class StopInstanceCommand(InstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
500 |
"""Stop the given instances. |
1446 | 501 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
502 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
503 |
identifiers of the instances to stop. If no instance is |
0 | 504 |
given, stop them all. |
505 |
""" |
|
506 |
name = 'stop' |
|
507 |
actionverb = 'stopped' |
|
1446 | 508 |
|
0 | 509 |
def ordered_instances(self): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
510 |
instances = super(StopInstanceCommand, self).ordered_instances() |
0 | 511 |
instances.reverse() |
512 |
return instances |
|
1446 | 513 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
514 |
def stop_instance(self, appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
515 |
"""stop the instance's server""" |
1132 | 516 |
config = cwcfg.config_for(appid) |
0 | 517 |
helper = self.config_helper(config, cmdname='stop') |
518 |
helper.poststop() # do this anyway |
|
519 |
pidf = config['pid-file'] |
|
520 |
if not exists(pidf): |
|
521 |
print >> sys.stderr, "%s doesn't exist." % pidf |
|
522 |
return |
|
523 |
import signal |
|
524 |
pid = int(open(pidf).read().strip()) |
|
525 |
try: |
|
526 |
kill(pid, signal.SIGTERM) |
|
527 |
except: |
|
528 |
print >> sys.stderr, "process %s seems already dead." % pid |
|
529 |
else: |
|
530 |
try: |
|
531 |
wait_process_end(pid) |
|
532 |
except ExecutionError, ex: |
|
533 |
print >> sys.stderr, ex |
|
534 |
print >> sys.stderr, 'trying SIGKILL' |
|
535 |
try: |
|
536 |
kill(pid, signal.SIGKILL) |
|
537 |
except: |
|
538 |
# probably dead now |
|
539 |
pass |
|
540 |
wait_process_end(pid) |
|
541 |
try: |
|
542 |
remove(pidf) |
|
543 |
except OSError: |
|
544 |
# already removed by twistd |
|
545 |
pass |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
546 |
print 'instance %s stopped' % appid |
1446 | 547 |
|
0 | 548 |
|
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
549 |
class RestartInstanceCommand(StartInstanceCommand): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
550 |
"""Restart the given instances. |
1446 | 551 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
552 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
553 |
identifiers of the instances to restart. If no instance is |
0 | 554 |
given, restart them all. |
555 |
""" |
|
556 |
name = 'restart' |
|
557 |
actionverb = 'restarted' |
|
558 |
||
559 |
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
|
560 |
regdir = cwcfg.instances_dir() |
0 | 561 |
if not isfile(join(regdir, 'startorder')) or len(args) <= 1: |
562 |
# no specific startorder |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
563 |
super(RestartInstanceCommand, self).run_args(args, askconfirm) |
0 | 564 |
return |
565 |
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
|
566 |
'instances then restart them.') |
0 | 567 |
# get instances in startorder |
568 |
for appid in args: |
|
569 |
if askconfirm: |
|
570 |
print '*'*72 |
|
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
571 |
if not ASK.confirm('%s instance %r ?' % (self.name, appid)): |
0 | 572 |
continue |
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
573 |
StopInstanceCommand().stop_instance(appid) |
0 | 574 |
forkcmd = [w for w in sys.argv if not w in args] |
575 |
forkcmd[1] = 'start' |
|
576 |
forkcmd = ' '.join(forkcmd) |
|
577 |
for appid in reversed(args): |
|
578 |
status = system('%s %s' % (forkcmd, appid)) |
|
579 |
if status: |
|
580 |
sys.exit(status) |
|
1446 | 581 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
582 |
def restart_instance(self, appid): |
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
583 |
StopInstanceCommand().stop_instance(appid) |
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
584 |
self.start_instance(appid) |
0 | 585 |
|
1446 | 586 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
587 |
class ReloadConfigurationCommand(RestartInstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
588 |
"""Reload the given instances. This command is equivalent to a |
0 | 589 |
restart for now. |
1446 | 590 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
591 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
592 |
identifiers of the instances to reload. If no instance is |
0 | 593 |
given, reload them all. |
594 |
""" |
|
595 |
name = 'reload' |
|
1446 | 596 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
597 |
def reload_instance(self, appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
598 |
self.restart_instance(appid) |
1446 | 599 |
|
0 | 600 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
601 |
class StatusCommand(InstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
602 |
"""Display status information about the given instances. |
1446 | 603 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
604 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
605 |
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
|
606 |
given, get status information about all registered instances. |
0 | 607 |
""" |
608 |
name = 'status' |
|
609 |
options = () |
|
610 |
||
1132 | 611 |
@staticmethod |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
612 |
def status_instance(appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
613 |
"""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
|
614 |
status = 0 |
1132 | 615 |
for mode in cwcfg.possible_configurations(appid): |
616 |
config = cwcfg.config_for(appid, mode) |
|
0 | 617 |
print '[%s-%s]' % (appid, mode), |
618 |
try: |
|
619 |
pidf = config['pid-file'] |
|
620 |
except KeyError: |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
621 |
print 'buggy instance, pid file not specified' |
0 | 622 |
continue |
623 |
if not exists(pidf): |
|
624 |
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
|
625 |
status = 1 |
0 | 626 |
continue |
627 |
pid = int(open(pidf).read().strip()) |
|
628 |
# trick to guess whether or not the process is running |
|
629 |
try: |
|
630 |
getpgid(pid) |
|
631 |
except OSError: |
|
632 |
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
|
633 |
status = 1 |
0 | 634 |
continue |
635 |
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
|
636 |
return status |
0 | 637 |
|
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
638 |
class UpgradeInstanceCommand(InstanceCommandFork): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
639 |
"""Upgrade an instance after cubicweb and/or component(s) upgrade. |
0 | 640 |
|
641 |
For repository update, you will be prompted for a login / password to use |
|
642 |
to connect to the system database. For some upgrades, the given user |
|
643 |
should have create or alter table permissions. |
|
644 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
645 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
646 |
identifiers of the instances to upgrade. If no instance is |
0 | 647 |
given, upgrade them all. |
648 |
""" |
|
649 |
name = 'upgrade' |
|
650 |
actionverb = 'upgraded' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
651 |
options = InstanceCommand.options + ( |
0 | 652 |
('force-componant-version', |
653 |
{'short': 't', 'type' : 'csv', 'metavar': 'cube1=X.Y.Z,cube2=X.Y.Z', |
|
654 |
'default': None, |
|
655 |
'help': 'force migration from the indicated version for the specified cube.'}), |
|
656 |
('force-cubicweb-version', |
|
657 |
{'short': 'e', 'type' : 'string', 'metavar': 'X.Y.Z', |
|
658 |
'default': None, |
|
659 |
'help': 'force migration from the indicated cubicweb version.'}), |
|
1446 | 660 |
|
0 | 661 |
('fs-only', |
662 |
{'short': 's', 'action' : 'store_true', |
|
663 |
'default': False, |
|
664 |
'help': 'only upgrade files on the file system, not the database.'}), |
|
665 |
||
666 |
('nostartstop', |
|
667 |
{'short': 'n', 'action' : 'store_true', |
|
668 |
'default': False, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
669 |
'help': 'don\'t try to stop instance before migration and to restart it after.'}), |
1446 | 670 |
|
0 | 671 |
('verbosity', |
672 |
{'short': 'v', 'type' : 'int', 'metavar': '<0..2>', |
|
673 |
'default': 1, |
|
674 |
'help': "0: no confirmation, 1: only main commands confirmed, 2 ask \ |
|
675 |
for everything."}), |
|
1446 | 676 |
|
0 | 677 |
('backup-db', |
678 |
{'short': 'b', 'type' : 'yn', 'metavar': '<y or n>', |
|
679 |
'default': None, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
680 |
'help': "Backup the instance database before upgrade.\n"\ |
0 | 681 |
"If the option is ommitted, confirmation will be ask.", |
682 |
}), |
|
683 |
||
684 |
('ext-sources', |
|
685 |
{'short': 'E', 'type' : 'csv', 'metavar': '<sources>', |
|
686 |
'default': None, |
|
687 |
'help': "For multisources instances, specify to which sources the \ |
|
688 |
repository should connect to for upgrading. When unspecified or 'migration' is \ |
|
689 |
given, appropriate sources for migration will be automatically selected \ |
|
690 |
(recommended). If 'all' is given, will connect to all defined sources.", |
|
691 |
}), |
|
692 |
) |
|
693 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
694 |
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
|
695 |
print '\n' + underline_title('Upgrading the instance %s' % appid) |
0 | 696 |
from logilab.common.changelog import Version |
1132 | 697 |
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
|
698 |
config.repairing = True # notice we're not starting the server |
0 | 699 |
config.verbosity = self.config.verbosity |
1219
054bb575c013
take care, self.config may not be a server config
sylvain.thenault@logilab.fr
parents:
1015
diff
changeset
|
700 |
try: |
054bb575c013
take care, self.config may not be a server config
sylvain.thenault@logilab.fr
parents:
1015
diff
changeset
|
701 |
config.set_sources_mode(self.config.ext_sources or ('migration',)) |
054bb575c013
take care, self.config may not be a server config
sylvain.thenault@logilab.fr
parents:
1015
diff
changeset
|
702 |
except AttributeError: |
054bb575c013
take care, self.config may not be a server config
sylvain.thenault@logilab.fr
parents:
1015
diff
changeset
|
703 |
# not a server config |
054bb575c013
take care, self.config may not be a server config
sylvain.thenault@logilab.fr
parents:
1015
diff
changeset
|
704 |
pass |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
705 |
# get instance and installed versions for the server and the componants |
0 | 706 |
mih = config.migration_handler() |
707 |
repo = mih.repo_connect() |
|
708 |
vcconf = repo.get_versions() |
|
709 |
if self.config.force_componant_version: |
|
710 |
packversions = {} |
|
711 |
for vdef in self.config.force_componant_version: |
|
712 |
componant, version = vdef.split('=') |
|
713 |
packversions[componant] = Version(version) |
|
714 |
vcconf.update(packversions) |
|
715 |
toupgrade = [] |
|
716 |
for cube in config.cubes(): |
|
717 |
installedversion = config.cube_version(cube) |
|
718 |
try: |
|
719 |
applversion = vcconf[cube] |
|
720 |
except KeyError: |
|
721 |
config.error('no version information for %s' % cube) |
|
722 |
continue |
|
723 |
if installedversion > applversion: |
|
724 |
toupgrade.append( (cube, applversion, installedversion) ) |
|
1446 | 725 |
cubicwebversion = config.cubicweb_version() |
0 | 726 |
if self.config.force_cubicweb_version: |
727 |
applcubicwebversion = Version(self.config.force_cubicweb_version) |
|
728 |
vcconf['cubicweb'] = applcubicwebversion |
|
729 |
else: |
|
730 |
applcubicwebversion = vcconf.get('cubicweb') |
|
731 |
if cubicwebversion > applcubicwebversion: |
|
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2156
diff
changeset
|
732 |
toupgrade.append(('cubicweb', applcubicwebversion, cubicwebversion)) |
0 | 733 |
if not self.config.fs_only and not toupgrade: |
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
|
734 |
print '-> no data migration needed for instance %s.' % 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
|
735 |
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
|
736 |
mih.shutdown() |
0 | 737 |
return |
738 |
for cube, fromversion, toversion in toupgrade: |
|
2532
f7ca29d75183
[cleanup] improve dialog message consistency
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2512
diff
changeset
|
739 |
print '-> migration needed from %s to %s for %s' % (fromversion, toversion, cube) |
1404
971b19de6b85
stop application only once we're sure we've something to do, fixing #342689
sylvain.thenault@logilab.fr
parents:
1219
diff
changeset
|
740 |
# 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
|
741 |
if not (CWDEV or self.config.nostartstop): |
3188
34395d1f00d6
[c-c] fix 3.4.9 name error :'(
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3182
diff
changeset
|
742 |
StopInstanceCommand().stop_instance(appid) |
0 | 743 |
# run cubicweb/componants migration scripts |
744 |
mih.migrate(vcconf, reversed(toupgrade), self.config) |
|
745 |
# rewrite main configuration file |
|
746 |
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
|
747 |
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
|
748 |
# 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
|
749 |
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
|
750 |
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
|
751 |
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
|
752 |
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
|
753 |
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
|
754 |
# 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
|
755 |
# 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
|
756 |
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
|
757 |
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
|
758 |
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
|
759 |
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
|
760 |
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
|
761 |
|
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
|
762 |
def i18nupgrade(self, config): |
0 | 763 |
# handle i18n upgrade: |
764 |
# * install new languages |
|
765 |
# * 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
|
766 |
# 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
|
767 |
from cubicweb import i18n |
1132 | 768 |
templdir = cwcfg.cube_dir(config.cubes()[0]) |
0 | 769 |
langs = [lang for lang, _ in i18n.available_catalogs(join(templdir, 'i18n'))] |
770 |
errors = config.i18ncompile(langs) |
|
771 |
if errors: |
|
772 |
print '\n'.join(errors) |
|
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
773 |
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
|
774 |
'continue anyway?'): |
2512
106b2a05dc88
[cleanup] started to improve cubicweb-ctl dialog messages consistency
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2489
diff
changeset
|
775 |
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
|
776 |
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
|
777 |
return True |
0 | 778 |
|
779 |
class ShellCommand(Command): |
|
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
780 |
"""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
|
781 |
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
|
782 |
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
|
783 |
in batch mode. |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
784 |
|
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
785 |
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
|
786 |
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
|
787 |
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
|
788 |
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
|
789 |
available. |
0 | 790 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
791 |
<instance> |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
792 |
the identifier of the instance to connect. |
0 | 793 |
""" |
794 |
name = 'shell' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
795 |
arguments = '<instance> [batch command file]' |
0 | 796 |
options = ( |
797 |
('system-only', |
|
798 |
{'short': 'S', 'action' : 'store_true', |
|
799 |
'help': 'only connect to the system source when the instance is ' |
|
800 |
'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
|
801 |
'--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
|
802 |
'group': 'local' |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
803 |
}), |
1446 | 804 |
|
0 | 805 |
('ext-sources', |
806 |
{'short': 'E', 'type' : 'csv', 'metavar': '<sources>', |
|
807 |
'help': "For multisources instances, specify to which sources the \ |
|
808 |
repository should connect to for upgrading. When unspecified or 'all' given, \ |
|
809 |
will connect to all defined sources. If 'migration' is given, appropriate \ |
|
810 |
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
|
811 |
'group': 'local' |
0 | 812 |
}), |
1446 | 813 |
|
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
|
814 |
('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
|
815 |
{'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
|
816 |
'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
|
817 |
'group': 'local' |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
818 |
}), |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
819 |
|
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
820 |
('pyro', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
821 |
{'short': 'P', 'action' : 'store_true', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
822 |
'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
|
823 |
'group': 'remote', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
824 |
}), |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
825 |
('pyro-ns-host', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
826 |
{'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
|
827 |
'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
|
828 |
'using a broadcast query.', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
829 |
'group': 'remote' |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
830 |
}), |
0 | 831 |
) |
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
|
832 |
|
0 | 833 |
def run(self, args): |
4524
2eb36514ad6d
[cw-shell] do not set arbitrary limit on number of arguments
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4064
diff
changeset
|
834 |
appid = pop_arg(args, None, msg="No instance specified !") |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
835 |
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
|
836 |
from cubicweb import AuthenticationError |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
837 |
from cubicweb.dbapi import connect |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
838 |
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
|
839 |
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
|
840 |
while True: |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
841 |
try: |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
842 |
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
|
843 |
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
|
844 |
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
|
845 |
except AuthenticationError, ex: |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
846 |
print ex |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
847 |
except (KeyboardInterrupt, EOFError): |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
848 |
print |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
849 |
sys.exit(0) |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
850 |
else: |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
851 |
break |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
852 |
cnx.load_appobjects() |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
853 |
repo = cnx._repo |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
854 |
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
|
855 |
# 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
|
856 |
schema=1) |
0 | 857 |
else: |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
858 |
config = cwcfg.config_for(appid) |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
859 |
if self.config.ext_sources: |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
860 |
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
|
861 |
sources = self.config.ext_sources |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
862 |
elif self.config.system_only: |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
863 |
sources = ('system',) |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
864 |
else: |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
865 |
sources = ('all',) |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
866 |
config.set_sources_mode(sources) |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
867 |
config.repairing = self.config.force |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
868 |
mih = config.migration_handler() |
3709
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
869 |
try: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
870 |
if args: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
871 |
for arg in args: |
3715
e3ccadb126d7
[shell] make process_script available throuhg c-c shell / migration script context
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3709
diff
changeset
|
872 |
mih.cmd_process_script(arg) |
3709
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
873 |
else: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
874 |
mih.interactive_shell() |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
875 |
finally: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
876 |
if not self.config.pyro: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
877 |
mih.shutdown() |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
878 |
else: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
879 |
cnx.close() |
0 | 880 |
|
881 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
882 |
class RecompileInstanceCatalogsCommand(InstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
883 |
"""Recompile i18n catalogs for instances. |
1446 | 884 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
885 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
886 |
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
|
887 |
given, recompile for all registered instances. |
0 | 888 |
""" |
1898
39b37f90a8a4
[cw-ctl] rename i18n commands (see #342889)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1477
diff
changeset
|
889 |
name = 'i18ninstance' |
1132 | 890 |
|
891 |
@staticmethod |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
892 |
def i18ninstance_instance(appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
893 |
"""recompile instance's messages catalogs""" |
1132 | 894 |
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
|
895 |
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
|
896 |
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
|
897 |
if config._cubes is None: |
0 | 898 |
# 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
|
899 |
config.init_cubes(repo.get_cubes()) |
0 | 900 |
errors = config.i18ncompile() |
901 |
if errors: |
|
902 |
print '\n'.join(errors) |
|
903 |
||
904 |
||
905 |
class ListInstancesCommand(Command): |
|
906 |
"""list available instances, useful for bash completion.""" |
|
907 |
name = 'listinstances' |
|
908 |
hidden = True |
|
1446 | 909 |
|
0 | 910 |
def run(self, args): |
911 |
"""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
|
912 |
regdir = cwcfg.instances_dir() |
0 | 913 |
for appid in sorted(listdir(regdir)): |
914 |
print appid |
|
915 |
||
916 |
||
917 |
class ListCubesCommand(Command): |
|
918 |
"""list available componants, useful for bash completion.""" |
|
919 |
name = 'listcubes' |
|
920 |
hidden = True |
|
1446 | 921 |
|
0 | 922 |
def run(self, args): |
923 |
"""run the command with its specific arguments""" |
|
1132 | 924 |
for cube in cwcfg.available_cubes(): |
0 | 925 |
print cube |
926 |
||
927 |
register_commands((ListCommand, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
928 |
CreateInstanceCommand, |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
929 |
DeleteInstanceCommand, |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
930 |
StartInstanceCommand, |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
931 |
StopInstanceCommand, |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
932 |
RestartInstanceCommand, |
0 | 933 |
ReloadConfigurationCommand, |
934 |
StatusCommand, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
935 |
UpgradeInstanceCommand, |
0 | 936 |
ShellCommand, |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
937 |
RecompileInstanceCatalogsCommand, |
0 | 938 |
ListInstancesCommand, ListCubesCommand, |
939 |
)) |
|
940 |
||
1446 | 941 |
|
0 | 942 |
def run(args): |
943 |
"""command line tool""" |
|
1132 | 944 |
cwcfg.load_cwctl_plugins() |
4720
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
945 |
main_run(args, """%%prog %s [options] %s |
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
946 |
|
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
947 |
The CubicWeb swiss-knife. |
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
948 |
|
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
949 |
%s""" |
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
950 |
) |
0 | 951 |
|
952 |
if __name__ == '__main__': |
|
953 |
run(sys.argv[1:]) |