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