author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 28 Mar 2011 19:02:47 +0200 | |
branch | stable |
changeset 7131 | 5893b899c21f |
parent 7129 | 455b503fb7ff |
child 7140 | ba51dac1115d |
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 |
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 = 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
|
156 |
sys.exit(status) |
1446 | 157 |
|
0 | 158 |
def run_arg(self, appid): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
159 |
cmdmeth = getattr(self, '%s_instance' % self.name) |
0 | 160 |
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
|
161 |
status = cmdmeth(appid) |
0 | 162 |
except (KeyboardInterrupt, SystemExit): |
163 |
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
|
164 |
return 2 # specific error code |
0 | 165 |
except (ExecutionError, ConfigurationError), ex: |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
166 |
print >> sys.stderr, 'instance %s not %s: %s' % ( |
0 | 167 |
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
|
168 |
status = 4 |
0 | 169 |
except Exception, ex: |
170 |
import traceback |
|
171 |
traceback.print_exc() |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
172 |
print >> sys.stderr, 'instance %s not %s: %s' % ( |
0 | 173 |
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
|
174 |
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
|
175 |
return status |
0 | 176 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
177 |
class InstanceCommandFork(InstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
178 |
"""Same as `InstanceCommand`, but command is forked in a new environment |
0 | 179 |
for each argument |
180 |
""" |
|
181 |
||
182 |
def run_args(self, args, askconfirm): |
|
183 |
if len(args) > 1: |
|
184 |
forkcmd = ' '.join(w for w in sys.argv if not w in args) |
|
185 |
else: |
|
186 |
forkcmd = None |
|
187 |
for appid in args: |
|
188 |
if askconfirm: |
|
189 |
print '*'*72 |
|
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
190 |
if not ASK.confirm('%s instance %r ?' % (self.name, appid)): |
0 | 191 |
continue |
192 |
if forkcmd: |
|
193 |
status = system('%s %s' % (forkcmd, appid)) |
|
194 |
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
|
195 |
print '%s exited with status %s' % (forkcmd, status) |
0 | 196 |
else: |
197 |
self.run_arg(appid) |
|
1446 | 198 |
|
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
199 |
|
0 | 200 |
# base commands ############################################################### |
201 |
||
202 |
class ListCommand(Command): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
203 |
"""List configurations, cubes and instances. |
0 | 204 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
205 |
list available configurations, installed cubes, and registered instances |
0 | 206 |
""" |
207 |
name = 'list' |
|
208 |
options = ( |
|
209 |
('verbose', |
|
1446 | 210 |
{'short': 'v', 'action' : 'store_true', |
211 |
'help': "display more information."}), |
|
0 | 212 |
) |
1446 | 213 |
|
0 | 214 |
def run(self, args): |
215 |
"""run the command with its specific arguments""" |
|
216 |
if args: |
|
5608
f9ab62103ad4
proof read documentation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5498
diff
changeset
|
217 |
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
|
218 |
from cubicweb.migration import ConfigurationProblem |
3486
ea6bf6f9ba0c
[cwctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3198
diff
changeset
|
219 |
print 'CubicWeb %s (%s mode)' % (cwcfg.cubicweb_version(), cwcfg.mode) |
0 | 220 |
print |
221 |
print 'Available configurations:' |
|
222 |
for config in CONFIGURATIONS: |
|
223 |
print '*', config.name |
|
224 |
for line in config.__doc__.splitlines(): |
|
225 |
line = line.strip() |
|
226 |
if not line: |
|
227 |
continue |
|
228 |
print ' ', line |
|
1446 | 229 |
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
|
230 |
cfgpb = ConfigurationProblem(cwcfg) |
0 | 231 |
try: |
1342
4273e44852cb
no more cubes_dir class method
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
232 |
cubesdir = pathsep.join(cwcfg.cubes_search_path()) |
1132 | 233 |
namesize = max(len(x) for x in cwcfg.available_cubes()) |
0 | 234 |
except ConfigurationError, ex: |
235 |
print 'No cubes available:', ex |
|
236 |
except ValueError: |
|
237 |
print 'No cubes available in %s' % cubesdir |
|
238 |
else: |
|
239 |
print 'Available cubes (%s):' % cubesdir |
|
1132 | 240 |
for cube in cwcfg.available_cubes(): |
0 | 241 |
try: |
1132 | 242 |
tinfo = cwcfg.cube_pkginfo(cube) |
0 | 243 |
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
|
244 |
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
|
245 |
except (ConfigurationError, AttributeError), ex: |
0 | 246 |
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
|
247 |
tversion = '[missing cube information: %s]' % ex |
0 | 248 |
print '* %s %s' % (cube.ljust(namesize), tversion) |
249 |
if self.config.verbose: |
|
5025
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
250 |
if tinfo: |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
251 |
descr = getattr(tinfo, 'description', '') |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
252 |
if not descr: |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
253 |
descr = getattr(tinfo, 'short_desc', '') |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
254 |
if descr: |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
255 |
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
|
256 |
' pkginfo' % cube, DeprecationWarning) |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
257 |
else: |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
258 |
descr = tinfo.__doc__ |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
259 |
if descr: |
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
260 |
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
|
261 |
modes = detect_available_modes(cwcfg.cube_dir(cube)) |
0 | 262 |
print ' available modes: %s' % ', '.join(modes) |
263 |
print |
|
264 |
try: |
|
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4798
diff
changeset
|
265 |
regdir = cwcfg.instances_dir() |
0 | 266 |
except ConfigurationError, ex: |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
267 |
print 'No instance available:', ex |
0 | 268 |
print |
269 |
return |
|
270 |
instances = list_instances(regdir) |
|
271 |
if instances: |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
272 |
print 'Available instances (%s):' % regdir |
0 | 273 |
for appid in instances: |
1132 | 274 |
modes = cwcfg.possible_configurations(appid) |
0 | 275 |
if not modes: |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
276 |
print '* %s (BROKEN instance, no configuration found)' % appid |
0 | 277 |
continue |
278 |
print '* %s (%s)' % (appid, ', '.join(modes)) |
|
279 |
try: |
|
1132 | 280 |
config = cwcfg.config_for(appid, modes[0]) |
1446 | 281 |
except Exception, exc: |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
282 |
print ' (BROKEN instance, %s)' % exc |
0 | 283 |
continue |
284 |
else: |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
285 |
print 'No instance available in %s' % regdir |
0 | 286 |
print |
4656
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
287 |
# 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
|
288 |
cfgpb.solve() |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
289 |
if cfgpb.warnings: |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
290 |
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
|
291 |
if cfgpb.errors: |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
292 |
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
|
293 |
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
|
294 |
if op == 'add': |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
295 |
print '* cube', cube, |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
296 |
if version: |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
297 |
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
|
298 |
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
|
299 |
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
|
300 |
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
|
301 |
cube, cfgpb.cubes[cube], version, src) |
0 | 302 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
303 |
class CreateInstanceCommand(Command): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
304 |
"""Create an instance from a cube. This is an unified |
0 | 305 |
command which can handle web / server / all-in-one installation |
306 |
according to available parts of the software library and of the |
|
307 |
desired cube. |
|
308 |
||
309 |
<cube> |
|
310 |
the name of cube to use (list available cube names using |
|
311 |
the "list" command). You can use several cubes by separating |
|
312 |
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
|
313 |
<instance> |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
314 |
an identifier for the instance to create |
0 | 315 |
""" |
316 |
name = 'create' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
317 |
arguments = '<cube> <instance>' |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
318 |
min_args = max_args = 2 |
0 | 319 |
options = ( |
320 |
("config-level", |
|
321 |
{'short': 'l', 'type' : 'int', 'metavar': '<level>', |
|
322 |
'default': 0, |
|
323 |
'help': 'configuration level (0..2): 0 will ask for essential \ |
|
324 |
configuration parameters only while 2 will ask for all parameters', |
|
325 |
} |
|
326 |
), |
|
327 |
("config", |
|
328 |
{'short': 'c', 'type' : 'choice', 'metavar': '<install type>', |
|
329 |
'choices': ('all-in-one', 'repository', 'twisted'), |
|
330 |
'default': 'all-in-one', |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
331 |
'help': 'installation type, telling which part of an instance \ |
0 | 332 |
should be installed. You can list available configurations using the "list" \ |
333 |
command. Default to "all-in-one", e.g. an installation embedding both the RQL \ |
|
334 |
repository and the web server.', |
|
335 |
} |
|
336 |
), |
|
337 |
) |
|
1446 | 338 |
|
0 | 339 |
def run(self, args): |
340 |
"""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
|
341 |
from logilab.common.textutils import splitstrip |
0 | 342 |
configname = self.config.config |
6144
40af8e328e64
[c-c create] argument inversed accidentally
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
343 |
cubes, appid = args |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
344 |
cubes = splitstrip(cubes) |
0 | 345 |
# 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
|
346 |
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
|
347 |
cubes = config.expand_cubes(cubes) |
b4ffcea3275b
change cubes into expanded cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2032
diff
changeset
|
348 |
config.init_cubes(cubes) |
0 | 349 |
helper = self.config_helper(config) |
350 |
# check the cube exists |
|
351 |
try: |
|
1132 | 352 |
templdirs = [cwcfg.cube_dir(cube) |
0 | 353 |
for cube in cubes] |
354 |
except ConfigurationError, ex: |
|
355 |
print ex |
|
356 |
print '\navailable cubes:', |
|
1132 | 357 |
print ', '.join(cwcfg.available_cubes()) |
0 | 358 |
return |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
359 |
# 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
|
360 |
print '\n'+underline_title('Creating the instance %s' % appid) |
0 | 361 |
create_dir(config.apphome) |
362 |
# cubicweb-ctl configuration |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
363 |
print '\n'+underline_title('Configuring the instance (%s.conf)' % configname) |
0 | 364 |
config.input_config('main', self.config.config_level) |
365 |
# configuration'specific stuff |
|
366 |
print |
|
367 |
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
|
368 |
# 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
|
369 |
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
|
370 |
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
|
371 |
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
|
372 |
for section in sections: |
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
|
373 |
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
|
374 |
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
|
375 |
config.input_config(section, self.config.config_level) |
0 | 376 |
# write down configuration |
377 |
config.save() |
|
4064
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
378 |
self._handle_win32(config, appid) |
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2318
diff
changeset
|
379 |
print '-> generated %s' % config.main_config_file() |
0 | 380 |
# handle i18n files structure |
381 |
# in the first cube given |
|
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2318
diff
changeset
|
382 |
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
|
383 |
from cubicweb import i18n |
0 | 384 |
langs = [lang for lang, _ in i18n.available_catalogs(join(templdirs[0], 'i18n'))] |
385 |
errors = config.i18ncompile(langs) |
|
386 |
if errors: |
|
387 |
print '\n'.join(errors) |
|
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
388 |
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
|
389 |
'continue anyway ?'): |
0 | 390 |
print 'creation not completed' |
391 |
return |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
392 |
# create the additional data directory for this instance |
0 | 393 |
if config.appdatahome != config.apphome: # true in dev mode |
394 |
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
|
395 |
create_dir(join(config.appdatahome, 'backup')) |
0 | 396 |
if config['uid']: |
397 |
from logilab.common.shellutils import chown |
|
398 |
# this directory should be owned by the uid of the server process |
|
399 |
print 'set %s as owner of the data directory' % config['uid'] |
|
400 |
chown(config.appdatahome, config['uid']) |
|
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2318
diff
changeset
|
401 |
print '\n-> creation done for %r.\n' % config.apphome |
0 | 402 |
helper.postcreate() |
403 |
||
4064
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
404 |
def _handle_win32(self, config, appid): |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
405 |
if sys.platform != 'win32': |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
406 |
return |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
407 |
service_template = """ |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
408 |
import sys |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
409 |
import win32serviceutil |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
410 |
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
|
411 |
|
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
412 |
from cubicweb.etwist.service import CWService |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
413 |
|
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
414 |
classdict = {'_svc_name_': 'cubicweb-%(APPID)s', |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
415 |
'_svc_display_name_': 'CubicWeb ' + '%(CNAME)s', |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
416 |
'instance': '%(APPID)s'} |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
417 |
%(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
|
418 |
|
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
419 |
if __name__ == '__main__': |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
420 |
win32serviceutil.HandleCommandLine(%(CNAME)sService) |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
421 |
""" |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
422 |
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
|
423 |
service_template % {'APPID': appid, |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
424 |
'CNAME': appid.capitalize(), |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
425 |
'CWPATH': abspath(join(dirname(__file__), '..'))}) |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
426 |
|
1446 | 427 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
428 |
class DeleteInstanceCommand(Command): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
429 |
"""Delete an instance. Will remove instance's files and |
0 | 430 |
unregister it. |
431 |
""" |
|
432 |
name = 'delete' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
433 |
arguments = '<instance>' |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
434 |
min_args = max_args = 1 |
0 | 435 |
options = () |
436 |
||
437 |
def run(self, args): |
|
438 |
"""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
|
439 |
appid = args[0] |
1132 | 440 |
configs = [cwcfg.config_for(appid, configname) |
441 |
for configname in cwcfg.possible_configurations(appid)] |
|
0 | 442 |
if not configs: |
443 |
raise ExecutionError('unable to guess configuration for %s' % appid) |
|
444 |
for config in configs: |
|
445 |
helper = self.config_helper(config, required=False) |
|
446 |
if helper: |
|
447 |
helper.cleanup() |
|
448 |
# remove home |
|
449 |
rm(config.apphome) |
|
450 |
# remove instance data directory |
|
451 |
try: |
|
452 |
rm(config.appdatahome) |
|
453 |
except OSError, ex: |
|
454 |
import errno |
|
455 |
if ex.errno != errno.ENOENT: |
|
456 |
raise |
|
457 |
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
|
458 |
print '-> instance %s (%s) deleted.' % (appid, confignames) |
0 | 459 |
|
460 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
461 |
# instance commands ######################################################## |
0 | 462 |
|
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
463 |
class StartInstanceCommand(InstanceCommandFork): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
464 |
"""Start the given instances. If no instance is given, start them all. |
1446 | 465 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
466 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
467 |
identifiers of the instances to start. If no instance is |
0 | 468 |
given, start them all. |
469 |
""" |
|
470 |
name = 'start' |
|
471 |
actionverb = 'started' |
|
472 |
options = ( |
|
473 |
("debug", |
|
474 |
{'short': 'D', 'action' : 'store_true', |
|
475 |
'help': 'start server in debug mode.'}), |
|
476 |
("force", |
|
477 |
{'short': 'f', 'action' : 'store_true', |
|
478 |
'default': False, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
479 |
'help': 'start the instance even if it seems to be already \ |
0 | 480 |
running.'}), |
481 |
('profile', |
|
482 |
{'short': 'P', 'type' : 'string', 'metavar': '<stat file>', |
|
483 |
'default': None, |
|
484 |
'help': 'profile code and use the specified file to store stats', |
|
485 |
}), |
|
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
|
486 |
('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 |
{'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
|
488 |
'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
|
489 |
'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
|
490 |
}), |
0 | 491 |
) |
492 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
493 |
def start_instance(self, appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
494 |
"""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
|
495 |
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
|
496 |
init_cmdline_log_threshold(config, self['loglevel']) |
3182 | 497 |
if self['profile']: |
0 | 498 |
config.global_set_option('profile', self.config.profile) |
499 |
helper = self.config_helper(config, cmdname='start') |
|
500 |
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
|
501 |
if exists(pidf) and not self['force']: |
0 | 502 |
msg = "%s seems to be running. Remove %s by hand if necessary or use \ |
503 |
the --force option." |
|
504 |
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
|
505 |
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
|
506 |
print 'instance %s started' % appid |
0 | 507 |
|
508 |
||
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
|
509 |
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
|
510 |
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
|
511 |
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
|
512 |
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
|
513 |
|
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
|
514 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
515 |
class StopInstanceCommand(InstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
516 |
"""Stop the given instances. |
1446 | 517 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
518 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
519 |
identifiers of the instances to stop. If no instance is |
0 | 520 |
given, stop them all. |
521 |
""" |
|
522 |
name = 'stop' |
|
523 |
actionverb = 'stopped' |
|
1446 | 524 |
|
0 | 525 |
def ordered_instances(self): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
526 |
instances = super(StopInstanceCommand, self).ordered_instances() |
0 | 527 |
instances.reverse() |
528 |
return instances |
|
1446 | 529 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
530 |
def stop_instance(self, appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
531 |
"""stop the instance's server""" |
1132 | 532 |
config = cwcfg.config_for(appid) |
0 | 533 |
helper = self.config_helper(config, cmdname='stop') |
534 |
helper.poststop() # do this anyway |
|
535 |
pidf = config['pid-file'] |
|
536 |
if not exists(pidf): |
|
537 |
print >> sys.stderr, "%s doesn't exist." % pidf |
|
538 |
return |
|
539 |
import signal |
|
540 |
pid = int(open(pidf).read().strip()) |
|
541 |
try: |
|
542 |
kill(pid, signal.SIGTERM) |
|
543 |
except: |
|
544 |
print >> sys.stderr, "process %s seems already dead." % pid |
|
545 |
else: |
|
546 |
try: |
|
547 |
wait_process_end(pid) |
|
548 |
except ExecutionError, ex: |
|
549 |
print >> sys.stderr, ex |
|
550 |
print >> sys.stderr, 'trying SIGKILL' |
|
551 |
try: |
|
552 |
kill(pid, signal.SIGKILL) |
|
553 |
except: |
|
554 |
# probably dead now |
|
555 |
pass |
|
556 |
wait_process_end(pid) |
|
557 |
try: |
|
558 |
remove(pidf) |
|
559 |
except OSError: |
|
560 |
# already removed by twistd |
|
561 |
pass |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
562 |
print 'instance %s stopped' % appid |
1446 | 563 |
|
0 | 564 |
|
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
565 |
class RestartInstanceCommand(StartInstanceCommand): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
566 |
"""Restart the given instances. |
1446 | 567 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
568 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
569 |
identifiers of the instances to restart. If no instance is |
0 | 570 |
given, restart them all. |
571 |
""" |
|
572 |
name = 'restart' |
|
573 |
actionverb = 'restarted' |
|
574 |
||
575 |
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
|
576 |
regdir = cwcfg.instances_dir() |
0 | 577 |
if not isfile(join(regdir, 'startorder')) or len(args) <= 1: |
578 |
# no specific startorder |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
579 |
super(RestartInstanceCommand, self).run_args(args, askconfirm) |
0 | 580 |
return |
581 |
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
|
582 |
'instances then restart them.') |
0 | 583 |
# get instances in startorder |
584 |
for appid in args: |
|
585 |
if askconfirm: |
|
586 |
print '*'*72 |
|
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
587 |
if not ASK.confirm('%s instance %r ?' % (self.name, appid)): |
0 | 588 |
continue |
6145
528be1e059aa
more cwctl api update and fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6144
diff
changeset
|
589 |
StopInstanceCommand(self.logger).stop_instance(appid) |
0 | 590 |
forkcmd = [w for w in sys.argv if not w in args] |
591 |
forkcmd[1] = 'start' |
|
592 |
forkcmd = ' '.join(forkcmd) |
|
593 |
for appid in reversed(args): |
|
594 |
status = system('%s %s' % (forkcmd, appid)) |
|
595 |
if status: |
|
596 |
sys.exit(status) |
|
1446 | 597 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
598 |
def restart_instance(self, appid): |
6145
528be1e059aa
more cwctl api update and fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6144
diff
changeset
|
599 |
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
|
600 |
self.start_instance(appid) |
0 | 601 |
|
1446 | 602 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
603 |
class ReloadConfigurationCommand(RestartInstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
604 |
"""Reload the given instances. This command is equivalent to a |
0 | 605 |
restart for now. |
1446 | 606 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
607 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
608 |
identifiers of the instances to reload. If no instance is |
0 | 609 |
given, reload them all. |
610 |
""" |
|
611 |
name = 'reload' |
|
1446 | 612 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
613 |
def reload_instance(self, appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
614 |
self.restart_instance(appid) |
1446 | 615 |
|
0 | 616 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
617 |
class StatusCommand(InstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
618 |
"""Display status information about the given instances. |
1446 | 619 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
620 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
621 |
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
|
622 |
given, get status information about all registered instances. |
0 | 623 |
""" |
624 |
name = 'status' |
|
625 |
options = () |
|
626 |
||
1132 | 627 |
@staticmethod |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
628 |
def status_instance(appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
629 |
"""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
|
630 |
status = 0 |
1132 | 631 |
for mode in cwcfg.possible_configurations(appid): |
632 |
config = cwcfg.config_for(appid, mode) |
|
0 | 633 |
print '[%s-%s]' % (appid, mode), |
634 |
try: |
|
635 |
pidf = config['pid-file'] |
|
636 |
except KeyError: |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
637 |
print 'buggy instance, pid file not specified' |
0 | 638 |
continue |
639 |
if not exists(pidf): |
|
640 |
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
|
641 |
status = 1 |
0 | 642 |
continue |
643 |
pid = int(open(pidf).read().strip()) |
|
644 |
# trick to guess whether or not the process is running |
|
645 |
try: |
|
646 |
getpgid(pid) |
|
647 |
except OSError: |
|
648 |
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
|
649 |
status = 1 |
0 | 650 |
continue |
651 |
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
|
652 |
return status |
0 | 653 |
|
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
654 |
class UpgradeInstanceCommand(InstanceCommandFork): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
655 |
"""Upgrade an instance after cubicweb and/or component(s) upgrade. |
0 | 656 |
|
657 |
For repository update, you will be prompted for a login / password to use |
|
658 |
to connect to the system database. For some upgrades, the given user |
|
659 |
should have create or alter table permissions. |
|
660 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
661 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
662 |
identifiers of the instances to upgrade. If no instance is |
0 | 663 |
given, upgrade them all. |
664 |
""" |
|
665 |
name = 'upgrade' |
|
666 |
actionverb = 'upgraded' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
667 |
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
|
668 |
('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
|
669 |
{'short': 't', 'type' : 'named', 'metavar': 'cube1:X.Y.Z,cube2:X.Y.Z', |
0 | 670 |
'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
|
671 |
'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
|
672 |
|
0 | 673 |
('force-cubicweb-version', |
674 |
{'short': 'e', 'type' : 'string', 'metavar': 'X.Y.Z', |
|
675 |
'default': None, |
|
676 |
'help': 'force migration from the indicated cubicweb version.'}), |
|
1446 | 677 |
|
0 | 678 |
('fs-only', |
679 |
{'short': 's', 'action' : 'store_true', |
|
680 |
'default': False, |
|
681 |
'help': 'only upgrade files on the file system, not the database.'}), |
|
682 |
||
683 |
('nostartstop', |
|
684 |
{'short': 'n', 'action' : 'store_true', |
|
685 |
'default': False, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
686 |
'help': 'don\'t try to stop instance before migration and to restart it after.'}), |
1446 | 687 |
|
0 | 688 |
('verbosity', |
689 |
{'short': 'v', 'type' : 'int', 'metavar': '<0..2>', |
|
690 |
'default': 1, |
|
691 |
'help': "0: no confirmation, 1: only main commands confirmed, 2 ask \ |
|
692 |
for everything."}), |
|
1446 | 693 |
|
0 | 694 |
('backup-db', |
695 |
{'short': 'b', 'type' : 'yn', 'metavar': '<y or n>', |
|
696 |
'default': None, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
697 |
'help': "Backup the instance database before upgrade.\n"\ |
0 | 698 |
"If the option is ommitted, confirmation will be ask.", |
699 |
}), |
|
700 |
||
701 |
('ext-sources', |
|
702 |
{'short': 'E', 'type' : 'csv', 'metavar': '<sources>', |
|
703 |
'default': None, |
|
704 |
'help': "For multisources instances, specify to which sources the \ |
|
705 |
repository should connect to for upgrading. When unspecified or 'migration' is \ |
|
706 |
given, appropriate sources for migration will be automatically selected \ |
|
707 |
(recommended). If 'all' is given, will connect to all defined sources.", |
|
708 |
}), |
|
709 |
) |
|
710 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
711 |
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
|
712 |
print '\n' + underline_title('Upgrading the instance %s' % appid) |
0 | 713 |
from logilab.common.changelog import Version |
1132 | 714 |
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
|
715 |
config.repairing = True # notice we're not starting the server |
0 | 716 |
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
|
717 |
try: |
054bb575c013
take care, self.config may not be a server config
sylvain.thenault@logilab.fr
parents:
1015
diff
changeset
|
718 |
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
|
719 |
except AttributeError: |
054bb575c013
take care, self.config may not be a server config
sylvain.thenault@logilab.fr
parents:
1015
diff
changeset
|
720 |
# not a server config |
054bb575c013
take care, self.config may not be a server config
sylvain.thenault@logilab.fr
parents:
1015
diff
changeset
|
721 |
pass |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
722 |
# get instance and installed versions for the server and the componants |
0 | 723 |
mih = config.migration_handler() |
724 |
repo = mih.repo_connect() |
|
725 |
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
|
726 |
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
|
727 |
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
|
728 |
vcconf[cube] = Version(version) |
0 | 729 |
toupgrade = [] |
730 |
for cube in config.cubes(): |
|
731 |
installedversion = config.cube_version(cube) |
|
732 |
try: |
|
733 |
applversion = vcconf[cube] |
|
734 |
except KeyError: |
|
735 |
config.error('no version information for %s' % cube) |
|
736 |
continue |
|
737 |
if installedversion > applversion: |
|
738 |
toupgrade.append( (cube, applversion, installedversion) ) |
|
1446 | 739 |
cubicwebversion = config.cubicweb_version() |
0 | 740 |
if self.config.force_cubicweb_version: |
741 |
applcubicwebversion = Version(self.config.force_cubicweb_version) |
|
742 |
vcconf['cubicweb'] = applcubicwebversion |
|
743 |
else: |
|
744 |
applcubicwebversion = vcconf.get('cubicweb') |
|
745 |
if cubicwebversion > applcubicwebversion: |
|
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2156
diff
changeset
|
746 |
toupgrade.append(('cubicweb', applcubicwebversion, cubicwebversion)) |
0 | 747 |
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
|
748 |
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
|
749 |
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 |
mih.shutdown() |
0 | 751 |
return |
752 |
for cube, fromversion, toversion in toupgrade: |
|
2532
f7ca29d75183
[cleanup] improve dialog message consistency
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2512
diff
changeset
|
753 |
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
|
754 |
# 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
|
755 |
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
|
756 |
StopInstanceCommand(self.logger).stop_instance(appid) |
0 | 757 |
# run cubicweb/componants migration scripts |
758 |
mih.migrate(vcconf, reversed(toupgrade), self.config) |
|
759 |
# rewrite main configuration file |
|
760 |
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
|
761 |
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
|
762 |
# 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
|
763 |
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
|
764 |
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
|
765 |
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
|
766 |
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
|
767 |
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
|
768 |
# 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
|
769 |
# 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
|
770 |
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
|
771 |
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
|
772 |
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
|
773 |
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
|
774 |
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
|
775 |
|
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 |
def i18nupgrade(self, config): |
0 | 777 |
# handle i18n upgrade: |
778 |
# * install new languages |
|
779 |
# * 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
|
780 |
# 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
|
781 |
from cubicweb import i18n |
1132 | 782 |
templdir = cwcfg.cube_dir(config.cubes()[0]) |
0 | 783 |
langs = [lang for lang, _ in i18n.available_catalogs(join(templdir, 'i18n'))] |
784 |
errors = config.i18ncompile(langs) |
|
785 |
if errors: |
|
786 |
print '\n'.join(errors) |
|
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
787 |
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
|
788 |
'continue anyway?'): |
2512
106b2a05dc88
[cleanup] started to improve cubicweb-ctl dialog messages consistency
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2489
diff
changeset
|
789 |
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
|
790 |
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
|
791 |
return True |
0 | 792 |
|
793 |
class ShellCommand(Command): |
|
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
794 |
"""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
|
795 |
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
|
796 |
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
|
797 |
in batch mode. |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
798 |
|
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
799 |
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
|
800 |
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
|
801 |
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
|
802 |
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
|
803 |
available. |
0 | 804 |
|
5430
ed8f71e244f8
[shell] #715938: support of script parameters (using standard '--' as arguments separator)
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5426
diff
changeset
|
805 |
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
|
806 |
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
|
807 |
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
|
808 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
809 |
<instance> |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
810 |
the identifier of the instance to connect. |
0 | 811 |
""" |
812 |
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
|
813 |
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
|
814 |
min_args = 1 |
0 | 815 |
options = ( |
816 |
('system-only', |
|
817 |
{'short': 'S', 'action' : 'store_true', |
|
818 |
'help': 'only connect to the system source when the instance is ' |
|
819 |
'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
|
820 |
'--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
|
821 |
'group': 'local' |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
822 |
}), |
1446 | 823 |
|
0 | 824 |
('ext-sources', |
825 |
{'short': 'E', 'type' : 'csv', 'metavar': '<sources>', |
|
826 |
'help': "For multisources instances, specify to which sources the \ |
|
827 |
repository should connect to for upgrading. When unspecified or 'all' given, \ |
|
828 |
will connect to all defined sources. If 'migration' is given, appropriate \ |
|
829 |
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
|
830 |
'group': 'local' |
0 | 831 |
}), |
1446 | 832 |
|
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
|
833 |
('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
|
834 |
{'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
|
835 |
'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
|
836 |
'group': 'local' |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
837 |
}), |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
838 |
|
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
839 |
('pyro', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
840 |
{'short': 'P', 'action' : 'store_true', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
841 |
'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
|
842 |
'group': 'remote', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
843 |
}), |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
844 |
('pyro-ns-host', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
845 |
{'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
|
846 |
'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
|
847 |
'using a broadcast query.', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
848 |
'group': 'remote' |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
849 |
}), |
0 | 850 |
) |
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
|
851 |
|
0 | 852 |
def run(self, args): |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
853 |
appid = args.pop(0) |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
854 |
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
|
855 |
from cubicweb import AuthenticationError |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
856 |
from cubicweb.dbapi import connect |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
857 |
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
|
858 |
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
|
859 |
while True: |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
860 |
try: |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
861 |
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
|
862 |
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
|
863 |
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
|
864 |
except AuthenticationError, ex: |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
865 |
print ex |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
866 |
except (KeyboardInterrupt, EOFError): |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
867 |
print |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
868 |
sys.exit(0) |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
869 |
else: |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
870 |
break |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
871 |
cnx.load_appobjects() |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
872 |
repo = cnx._repo |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
873 |
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
|
874 |
# 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
|
875 |
schema=1) |
0 | 876 |
else: |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
877 |
config = cwcfg.config_for(appid) |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
878 |
if self.config.ext_sources: |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
879 |
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
|
880 |
sources = self.config.ext_sources |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
881 |
elif self.config.system_only: |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
882 |
sources = ('system',) |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
883 |
else: |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
884 |
sources = ('all',) |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
885 |
config.set_sources_mode(sources) |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
886 |
config.repairing = self.config.force |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
887 |
mih = config.migration_handler() |
3709
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
888 |
try: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
889 |
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
|
890 |
# 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
|
891 |
# 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
|
892 |
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
|
893 |
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
|
894 |
mih.cmd_process_script(script, scriptargs=args) |
3709
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
895 |
else: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
896 |
mih.interactive_shell() |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
897 |
finally: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
898 |
if not self.config.pyro: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
899 |
mih.shutdown() |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
900 |
else: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
901 |
cnx.close() |
0 | 902 |
|
903 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
904 |
class RecompileInstanceCatalogsCommand(InstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
905 |
"""Recompile i18n catalogs for instances. |
1446 | 906 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
907 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
908 |
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
|
909 |
given, recompile for all registered instances. |
0 | 910 |
""" |
1898
39b37f90a8a4
[cw-ctl] rename i18n commands (see #342889)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1477
diff
changeset
|
911 |
name = 'i18ninstance' |
1132 | 912 |
|
913 |
@staticmethod |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
914 |
def i18ninstance_instance(appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
915 |
"""recompile instance's messages catalogs""" |
1132 | 916 |
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
|
917 |
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
|
918 |
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
|
919 |
if config._cubes is None: |
0 | 920 |
# 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
|
921 |
config.init_cubes(repo.get_cubes()) |
0 | 922 |
errors = config.i18ncompile() |
923 |
if errors: |
|
924 |
print '\n'.join(errors) |
|
925 |
||
926 |
||
927 |
class ListInstancesCommand(Command): |
|
928 |
"""list available instances, useful for bash completion.""" |
|
929 |
name = 'listinstances' |
|
930 |
hidden = True |
|
1446 | 931 |
|
0 | 932 |
def run(self, args): |
933 |
"""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
|
934 |
regdir = cwcfg.instances_dir() |
0 | 935 |
for appid in sorted(listdir(regdir)): |
936 |
print appid |
|
937 |
||
938 |
||
939 |
class ListCubesCommand(Command): |
|
940 |
"""list available componants, useful for bash completion.""" |
|
941 |
name = 'listcubes' |
|
942 |
hidden = True |
|
1446 | 943 |
|
0 | 944 |
def run(self, args): |
945 |
"""run the command with its specific arguments""" |
|
1132 | 946 |
for cube in cwcfg.available_cubes(): |
0 | 947 |
print cube |
948 |
||
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
949 |
for cmdcls in (ListCommand, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
950 |
CreateInstanceCommand, DeleteInstanceCommand, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
951 |
StartInstanceCommand, StopInstanceCommand, RestartInstanceCommand, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
952 |
ReloadConfigurationCommand, StatusCommand, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
953 |
UpgradeInstanceCommand, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
954 |
ShellCommand, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
955 |
RecompileInstanceCatalogsCommand, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
956 |
ListInstancesCommand, ListCubesCommand, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
957 |
): |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
958 |
CWCTL.register(cmdcls) |
0 | 959 |
|
1446 | 960 |
|
0 | 961 |
def run(args): |
962 |
"""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
|
963 |
import os |
34be5986bca0
make stdout and stderr non buffered for cwctl commands (#1330647)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
6505
diff
changeset
|
964 |
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
|
965 |
sys.stderr = os.fdopen(sys.stderr.fileno(), 'w', 0) |
1132 | 966 |
cwcfg.load_cwctl_plugins() |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
967 |
try: |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
968 |
CWCTL.run(args) |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
969 |
except ConfigurationError, err: |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
970 |
print 'ERROR: ', err |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
971 |
sys.exit(1) |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
972 |
except ExecutionError, err: |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
973 |
print err |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
974 |
sys.exit(2) |
0 | 975 |
|
976 |
if __name__ == '__main__': |
|
977 |
run(sys.argv[1:]) |