author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Wed, 16 Jul 2014 10:48:47 +0200 | |
changeset 11008 | de86c6592cc7 |
parent 10736 | 8d49849ec2a6 |
child 11104 | 269317987dc6 |
permissions | -rw-r--r-- |
10235
684215aca046
Remove remote repository-access-through-pyro support
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10109
diff
changeset
|
1 |
# copyright 2003-2014 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 |
""" |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
21 |
from __future__ import print_function |
0 | 22 |
|
4720
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
23 |
__docformat__ = "restructuredtext en" |
0 | 24 |
|
4718
3dc3ad02d091
avoid module import in c-c plugins module, and remind it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4684
diff
changeset
|
25 |
# *ctl module should limit the number of import to be imported as quickly as |
3dc3ad02d091
avoid module import in c-c plugins module, and remind it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4684
diff
changeset
|
26 |
# possible (for cubicweb-ctl reactivity, necessary for instance for usable bash |
3dc3ad02d091
avoid module import in c-c plugins module, and remind it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4684
diff
changeset
|
27 |
# completion). So import locally in command helpers. |
0 | 28 |
import sys |
10321
a4af502191d5
[cwctl] don't filter DeprecationWarnings
Julien Cristau <julien.cristau@logilab.fr>
parents:
10235
diff
changeset
|
29 |
from warnings import warn, filterwarnings |
3115
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
2905
diff
changeset
|
30 |
from os import remove, listdir, system, pathsep |
8669
62213a34726e
[db-api/configuration] simplify db-api and configuration so that all the connection information is in the repository url, closes #2521848
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8564
diff
changeset
|
31 |
from os.path import exists, join, isfile, isdir, dirname, abspath |
8682
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
32 |
|
3115
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
2905
diff
changeset
|
33 |
try: |
3562 | 34 |
from os import kill, getpgid |
3115
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
2905
diff
changeset
|
35 |
except ImportError: |
4721
8f63691ccb7f
pylint style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4720
diff
changeset
|
36 |
def kill(*args): |
8f63691ccb7f
pylint style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4720
diff
changeset
|
37 |
"""win32 kill implementation""" |
8f63691ccb7f
pylint style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4720
diff
changeset
|
38 |
def getpgid(): |
8f63691ccb7f
pylint style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4720
diff
changeset
|
39 |
"""win32 getpgid implementation""" |
3115
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
2905
diff
changeset
|
40 |
|
10603
65ad6980976e
[py3k] import URL mangling functions using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10589
diff
changeset
|
41 |
from six.moves.urllib.parse import urlparse |
65ad6980976e
[py3k] import URL mangling functions using six.moves
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10589
diff
changeset
|
42 |
|
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
43 |
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
|
44 |
from logilab.common.shellutils import ASK |
9002
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
45 |
from logilab.common.configuration import merge_options |
1132 | 46 |
|
2790
968108e16066
move underline_title to toolsutils
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2743
diff
changeset
|
47 |
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
|
48 |
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
|
49 |
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
|
50 |
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
|
51 |
from cubicweb.__pkginfo__ import version |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
52 |
|
9371
1348202527a6
[cwctl] Don't check for old lgc versions
Julien Cristau <julien.cristau@logilab.fr>
parents:
9340
diff
changeset
|
53 |
# don't check duplicated commands, it occurs when reloading site_cubicweb |
1348202527a6
[cwctl] Don't check for old lgc versions
Julien Cristau <julien.cristau@logilab.fr>
parents:
9340
diff
changeset
|
54 |
CWCTL = CommandLine('cubicweb-ctl', 'The CubicWeb swiss-knife.', |
1348202527a6
[cwctl] Don't check for old lgc versions
Julien Cristau <julien.cristau@logilab.fr>
parents:
9340
diff
changeset
|
55 |
version=version, check_duplicated_command=False) |
1446 | 56 |
|
0 | 57 |
def wait_process_end(pid, maxtry=10, waittime=1): |
58 |
"""wait for a process to actually die""" |
|
59 |
import signal |
|
60 |
from time import sleep |
|
61 |
nbtry = 0 |
|
62 |
while nbtry < maxtry: |
|
63 |
try: |
|
64 |
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
|
65 |
except (OSError, AttributeError): # XXX win32 |
0 | 66 |
break |
67 |
nbtry += 1 |
|
68 |
sleep(waittime) |
|
69 |
else: |
|
70 |
raise ExecutionError('can\'t kill process %s' % pid) |
|
71 |
||
72 |
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
|
73 |
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
|
74 |
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
|
75 |
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
|
76 |
return [] |
0 | 77 |
|
78 |
def detect_available_modes(templdir): |
|
79 |
modes = [] |
|
80 |
for fname in ('schema', 'schema.py'): |
|
81 |
if exists(join(templdir, fname)): |
|
82 |
modes.append('repository') |
|
83 |
break |
|
84 |
for fname in ('data', 'views', 'views.py'): |
|
85 |
if exists(join(templdir, fname)): |
|
86 |
modes.append('web ui') |
|
87 |
break |
|
88 |
return modes |
|
1446 | 89 |
|
90 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
91 |
class InstanceCommand(Command): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
92 |
"""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
|
93 |
(0 meaning all registered instances) |
0 | 94 |
""" |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
95 |
arguments = '[<instance>...]' |
0 | 96 |
options = ( |
97 |
("force", |
|
98 |
{'short': 'f', 'action' : 'store_true', |
|
99 |
'default': False, |
|
100 |
'help': 'force command without asking confirmation', |
|
101 |
} |
|
102 |
), |
|
103 |
) |
|
104 |
actionverb = None |
|
1446 | 105 |
|
0 | 106 |
def ordered_instances(self): |
107 |
"""return instances in the order in which they should be started, |
|
108 |
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
|
109 |
some instances depends on another as external source). |
af81a4f7053e
enhance docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3562
diff
changeset
|
110 |
|
af81a4f7053e
enhance docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3562
diff
changeset
|
111 |
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
|
112 |
instance per line) |
0 | 113 |
""" |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4798
diff
changeset
|
114 |
regdir = cwcfg.instances_dir() |
0 | 115 |
_allinstances = list_instances(regdir) |
116 |
if isfile(join(regdir, 'startorder')): |
|
117 |
allinstances = [] |
|
10614
57dfde80df11
[py3k] file → open
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10603
diff
changeset
|
118 |
for line in open(join(regdir, 'startorder')): |
0 | 119 |
line = line.strip() |
120 |
if line and not line.startswith('#'): |
|
121 |
try: |
|
122 |
_allinstances.remove(line) |
|
123 |
allinstances.append(line) |
|
124 |
except ValueError: |
|
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
125 |
print('ERROR: startorder file contains unexistant ' |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
126 |
'instance %s' % line) |
0 | 127 |
allinstances += _allinstances |
128 |
else: |
|
129 |
allinstances = _allinstances |
|
130 |
return allinstances |
|
1446 | 131 |
|
0 | 132 |
def run(self, args): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
133 |
"""run the <command>_method on each argument (a list of instance |
0 | 134 |
identifiers) |
135 |
""" |
|
136 |
if not args: |
|
137 |
args = self.ordered_instances() |
|
138 |
try: |
|
139 |
askconfirm = not self.config.force |
|
140 |
except AttributeError: |
|
141 |
# no force option |
|
142 |
askconfirm = False |
|
143 |
else: |
|
144 |
askconfirm = False |
|
145 |
self.run_args(args, askconfirm) |
|
1446 | 146 |
|
0 | 147 |
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
|
148 |
status = 0 |
0 | 149 |
for appid in args: |
150 |
if askconfirm: |
|
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
151 |
print('*'*72) |
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
152 |
if not ASK.confirm('%s instance %r ?' % (self.name, appid)): |
0 | 153 |
continue |
7593
0c1024b3e7fc
[c-c instance commands] keyboard interrupt should stop the command, not jump to the next instance. Closes #1794850
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7538
diff
changeset
|
154 |
try: |
0c1024b3e7fc
[c-c instance commands] keyboard interrupt should stop the command, not jump to the next instance. Closes #1794850
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7538
diff
changeset
|
155 |
status = max(status, self.run_arg(appid)) |
0c1024b3e7fc
[c-c instance commands] keyboard interrupt should stop the command, not jump to the next instance. Closes #1794850
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7538
diff
changeset
|
156 |
except (KeyboardInterrupt, SystemExit): |
7896
4c954e1e73ef
[lint] remove uses of "print >> sys.stderr" (closes #1908571)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7815
diff
changeset
|
157 |
sys.stderr.write('%s aborted\n' % self.name) |
7593
0c1024b3e7fc
[c-c instance commands] keyboard interrupt should stop the command, not jump to the next instance. Closes #1794850
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7538
diff
changeset
|
158 |
return 2 # specific error code |
5380
a4e7e87d315f
[c-c status] return status code 1 when some instances isn't running. Closes #510817
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5323
diff
changeset
|
159 |
sys.exit(status) |
1446 | 160 |
|
0 | 161 |
def run_arg(self, appid): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
162 |
cmdmeth = getattr(self, '%s_instance' % self.name) |
0 | 163 |
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
|
164 |
status = cmdmeth(appid) |
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8682
diff
changeset
|
165 |
except (ExecutionError, ConfigurationError) as ex: |
7896
4c954e1e73ef
[lint] remove uses of "print >> sys.stderr" (closes #1908571)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7815
diff
changeset
|
166 |
sys.stderr.write('instance %s not %s: %s\n' % ( |
4c954e1e73ef
[lint] remove uses of "print >> sys.stderr" (closes #1908571)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7815
diff
changeset
|
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 |
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8682
diff
changeset
|
169 |
except Exception as ex: |
0 | 170 |
import traceback |
171 |
traceback.print_exc() |
|
7896
4c954e1e73ef
[lint] remove uses of "print >> sys.stderr" (closes #1908571)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7815
diff
changeset
|
172 |
sys.stderr.write('instance %s not %s: %s\n' % ( |
4c954e1e73ef
[lint] remove uses of "print >> sys.stderr" (closes #1908571)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7815
diff
changeset
|
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: |
|
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
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: |
|
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
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 |
|
8829
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
205 |
List available configurations, installed cubes, and registered instances. |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
206 |
|
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
207 |
If given, the optional argument allows to restrict listing only a category of items. |
0 | 208 |
""" |
209 |
name = 'list' |
|
8829
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
210 |
arguments = '[all|cubes|configurations|instances]' |
0 | 211 |
options = ( |
212 |
('verbose', |
|
1446 | 213 |
{'short': 'v', 'action' : 'store_true', |
214 |
'help': "display more information."}), |
|
0 | 215 |
) |
1446 | 216 |
|
0 | 217 |
def run(self, args): |
218 |
"""run the command with its specific arguments""" |
|
8829
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
219 |
if not args: |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
220 |
mode = 'all' |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
221 |
elif len(args) == 1: |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
222 |
mode = args[0] |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
223 |
else: |
5608
f9ab62103ad4
proof read documentation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5498
diff
changeset
|
224 |
raise BadCommandUsage('Too many arguments') |
8829
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
225 |
|
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
|
226 |
from cubicweb.migration import ConfigurationProblem |
8829
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
227 |
|
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
228 |
if mode == 'all': |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
229 |
print('CubicWeb %s (%s mode)' % (cwcfg.cubicweb_version(), cwcfg.mode)) |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
230 |
print() |
8829
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
231 |
|
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
232 |
if mode in ('all', 'config', 'configurations'): |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
233 |
print('Available configurations:') |
8829
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
234 |
for config in CONFIGURATIONS: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
235 |
print('*', config.name) |
8829
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
236 |
for line in config.__doc__.splitlines(): |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
237 |
line = line.strip() |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
238 |
if not line: |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
239 |
continue |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
240 |
print(' ', line) |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
241 |
print() |
8829
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
242 |
|
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
243 |
if mode in ('all', 'cubes'): |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
244 |
cfgpb = ConfigurationProblem(cwcfg) |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
245 |
try: |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
246 |
cubesdir = pathsep.join(cwcfg.cubes_search_path()) |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
247 |
namesize = max(len(x) for x in cwcfg.available_cubes()) |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
248 |
except ConfigurationError as ex: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
249 |
print('No cubes available:', ex) |
8829
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
250 |
except ValueError: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
251 |
print('No cubes available in %s' % cubesdir) |
8829
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
252 |
else: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
253 |
print('Available cubes (%s):' % cubesdir) |
8829
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
254 |
for cube in cwcfg.available_cubes(): |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
255 |
try: |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
256 |
tinfo = cwcfg.cube_pkginfo(cube) |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
257 |
tversion = tinfo.version |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
258 |
cfgpb.add_cube(cube, tversion) |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
259 |
except (ConfigurationError, AttributeError) as ex: |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
260 |
tinfo = None |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
261 |
tversion = '[missing cube information: %s]' % ex |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
262 |
print('* %s %s' % (cube.ljust(namesize), tversion)) |
8829
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
263 |
if self.config.verbose: |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
264 |
if tinfo: |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
265 |
descr = getattr(tinfo, 'description', '') |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
266 |
if not descr: |
9255
46f41c3e1443
remove 3.8 bw compat
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9251
diff
changeset
|
267 |
descr = tinfo.__doc__ |
5025
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
268 |
if descr: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
269 |
print(' '+ ' \n'.join(descr.splitlines())) |
8829
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
270 |
modes = detect_available_modes(cwcfg.cube_dir(cube)) |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
271 |
print(' available modes: %s' % ', '.join(modes)) |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
272 |
print() |
8829
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
273 |
|
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
274 |
if mode in ('all', 'instances'): |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
275 |
try: |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
276 |
regdir = cwcfg.instances_dir() |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
277 |
except ConfigurationError as ex: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
278 |
print('No instance available:', ex) |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
279 |
print() |
8829
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
280 |
return |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
281 |
instances = list_instances(regdir) |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
282 |
if instances: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
283 |
print('Available instances (%s):' % regdir) |
8829
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
284 |
for appid in instances: |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
285 |
modes = cwcfg.possible_configurations(appid) |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
286 |
if not modes: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
287 |
print('* %s (BROKEN instance, no configuration found)' % appid) |
8829
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
288 |
continue |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
289 |
print('* %s (%s)' % (appid, ', '.join(modes))) |
8829
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
290 |
try: |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
291 |
config = cwcfg.config_for(appid, modes[0]) |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
292 |
except Exception as exc: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
293 |
print(' (BROKEN instance, %s)' % exc) |
8829
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
294 |
continue |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
295 |
else: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
296 |
print('No instance available in %s' % regdir) |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
297 |
print() |
8829
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
298 |
|
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
299 |
if mode == 'all': |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
300 |
# configuration management problem solving |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
301 |
cfgpb.solve() |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
302 |
if cfgpb.warnings: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
303 |
print('Warnings:\n', '\n'.join('* '+txt for txt in cfgpb.warnings)) |
8829
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
304 |
if cfgpb.errors: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
305 |
print('Errors:') |
8829
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
306 |
for op, cube, version, src in cfgpb.errors: |
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
307 |
if op == 'add': |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
308 |
print('* cube', cube, end=' ') |
8829
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
309 |
if version: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
310 |
print(' version', version, end=' ') |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
311 |
print('is not installed, but required by %s' % src) |
8829
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
312 |
else: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
313 |
print('* cube %s version %s is installed, but version %s is required by %s' % ( |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
314 |
cube, cfgpb.cubes[cube], version, src)) |
0 | 315 |
|
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
|
316 |
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
|
317 |
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
|
318 |
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
|
319 |
'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
|
320 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
321 |
class CreateInstanceCommand(Command): |
9704 | 322 |
"""Create an instance from a cube. This is a unified |
0 | 323 |
command which can handle web / server / all-in-one installation |
324 |
according to available parts of the software library and of the |
|
325 |
desired cube. |
|
326 |
||
327 |
<cube> |
|
328 |
the name of cube to use (list available cube names using |
|
329 |
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
|
330 |
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
|
331 |
<instance> |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
332 |
an identifier for the instance to create |
0 | 333 |
""" |
334 |
name = 'create' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
335 |
arguments = '<cube> <instance>' |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
336 |
min_args = max_args = 2 |
0 | 337 |
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
|
338 |
('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
|
339 |
{'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
|
340 |
'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
|
341 |
'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
|
342 |
'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
|
343 |
'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
|
344 |
}), |
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 |
('config-level', |
0 | 346 |
{'short': 'l', 'type' : 'int', 'metavar': '<level>', |
347 |
'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
|
348 |
'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
|
349 |
'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
|
350 |
}), |
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
351 |
('config', |
0 | 352 |
{'short': 'c', 'type' : 'choice', 'metavar': '<install type>', |
9251
e4d753c8b1c4
remove "twisted" configuration (closes #2919310)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9013
diff
changeset
|
353 |
'choices': ('all-in-one', 'repository'), |
0 | 354 |
'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
|
355 |
'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
|
356 |
'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
|
357 |
' "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
|
358 |
'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
|
359 |
}), |
9001
328c24289253
[cwctl] rename option no-post-create to no-db-create
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8930
diff
changeset
|
360 |
('no-db-create', |
328c24289253
[cwctl] rename option no-post-create to no-db-create
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8930
diff
changeset
|
361 |
{'short': 'S', |
8851
0020aa12af07
[c-c create] make post-create step optional (closes #2712041)
David Douard <david.douard@logilab.fr>
parents:
8829
diff
changeset
|
362 |
'action': 'store_true', |
0020aa12af07
[c-c create] make post-create step optional (closes #2712041)
David Douard <david.douard@logilab.fr>
parents:
8829
diff
changeset
|
363 |
'default': False, |
9001
328c24289253
[cwctl] rename option no-post-create to no-db-create
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8930
diff
changeset
|
364 |
'help': 'stop after creation and do not continue with db-create', |
8851
0020aa12af07
[c-c create] make post-create step optional (closes #2712041)
David Douard <david.douard@logilab.fr>
parents:
8829
diff
changeset
|
365 |
}), |
0 | 366 |
) |
1446 | 367 |
|
0 | 368 |
def run(self, args): |
369 |
"""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
|
370 |
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
|
371 |
check_options_consistency(self.config) |
0 | 372 |
configname = self.config.config |
6144
40af8e328e64
[c-c create] argument inversed accidentally
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
373 |
cubes, appid = args |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
374 |
cubes = splitstrip(cubes) |
0 | 375 |
# 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
|
376 |
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
|
377 |
cubes = config.expand_cubes(cubes) |
b4ffcea3275b
change cubes into expanded cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2032
diff
changeset
|
378 |
config.init_cubes(cubes) |
0 | 379 |
helper = self.config_helper(config) |
380 |
# check the cube exists |
|
381 |
try: |
|
1132 | 382 |
templdirs = [cwcfg.cube_dir(cube) |
0 | 383 |
for cube in cubes] |
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8682
diff
changeset
|
384 |
except ConfigurationError as ex: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
385 |
print(ex) |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
386 |
print('\navailable cubes:', end=' ') |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
387 |
print(', '.join(cwcfg.available_cubes())) |
0 | 388 |
return |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
389 |
# create the registry directory for this instance |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
390 |
print('\n'+underline_title('Creating the instance %s' % appid)) |
0 | 391 |
create_dir(config.apphome) |
392 |
# 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
|
393 |
if not self.config.automatic: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
394 |
print('\n'+underline_title('Configuring the instance (%s.conf)' |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
395 |
% configname)) |
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
|
396 |
config.input_config('main', self.config.config_level) |
0 | 397 |
# configuration'specific stuff |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
398 |
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
|
399 |
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
|
400 |
# input for cubes specific options |
9923
da09975300aa
[cwctl] don't prompt for cube options in automatic mode
Julien Cristau <julien.cristau@logilab.fr>
parents:
9704
diff
changeset
|
401 |
if not self.config.automatic: |
da09975300aa
[cwctl] don't prompt for cube options in automatic mode
Julien Cristau <julien.cristau@logilab.fr>
parents:
9704
diff
changeset
|
402 |
sections = set(sect.lower() for sect, opt, odict in config.all_options() |
da09975300aa
[cwctl] don't prompt for cube options in automatic mode
Julien Cristau <julien.cristau@logilab.fr>
parents:
9704
diff
changeset
|
403 |
if 'type' in odict |
da09975300aa
[cwctl] don't prompt for cube options in automatic mode
Julien Cristau <julien.cristau@logilab.fr>
parents:
9704
diff
changeset
|
404 |
and odict.get('level') <= self.config.config_level) |
da09975300aa
[cwctl] don't prompt for cube options in automatic mode
Julien Cristau <julien.cristau@logilab.fr>
parents:
9704
diff
changeset
|
405 |
for section in sections: |
10235
684215aca046
Remove remote repository-access-through-pyro support
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10109
diff
changeset
|
406 |
if section not in ('main', 'email', 'web'): |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
407 |
print('\n' + underline_title('%s options' % section)) |
9923
da09975300aa
[cwctl] don't prompt for cube options in automatic mode
Julien Cristau <julien.cristau@logilab.fr>
parents:
9704
diff
changeset
|
408 |
config.input_config(section, self.config.config_level) |
0 | 409 |
# write down configuration |
410 |
config.save() |
|
4064
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
411 |
self._handle_win32(config, appid) |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
412 |
print('-> generated config %s' % config.main_config_file()) |
0 | 413 |
# handle i18n files structure |
414 |
# 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
|
415 |
from cubicweb import i18n |
0 | 416 |
langs = [lang for lang, _ in i18n.available_catalogs(join(templdirs[0], 'i18n'))] |
417 |
errors = config.i18ncompile(langs) |
|
418 |
if errors: |
|
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
419 |
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
|
420 |
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
|
421 |
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
|
422 |
'continue anyway ?'): |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
423 |
print('creation not completed') |
0 | 424 |
return |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
425 |
# create the additional data directory for this instance |
0 | 426 |
if config.appdatahome != config.apphome: # true in dev mode |
427 |
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
|
428 |
create_dir(join(config.appdatahome, 'backup')) |
0 | 429 |
if config['uid']: |
430 |
from logilab.common.shellutils import chown |
|
431 |
# this directory should be owned by the uid of the server process |
|
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
432 |
print('set %s as owner of the data directory' % config['uid']) |
0 | 433 |
chown(config.appdatahome, config['uid']) |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
434 |
print('\n-> creation done for %s\n' % repr(config.apphome)[1:-1]) |
9001
328c24289253
[cwctl] rename option no-post-create to no-db-create
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8930
diff
changeset
|
435 |
if not self.config.no_db_create: |
9013 | 436 |
helper.postcreate(self.config.automatic, self.config.config_level) |
0 | 437 |
|
4064
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
438 |
def _handle_win32(self, config, appid): |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
439 |
if sys.platform != 'win32': |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
440 |
return |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
441 |
service_template = """ |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
442 |
import sys |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
443 |
import win32serviceutil |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
444 |
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
|
445 |
|
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
446 |
from cubicweb.etwist.service import CWService |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
447 |
|
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
448 |
classdict = {'_svc_name_': 'cubicweb-%(APPID)s', |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
449 |
'_svc_display_name_': 'CubicWeb ' + '%(CNAME)s', |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
450 |
'instance': '%(APPID)s'} |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
451 |
%(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
|
452 |
|
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
453 |
if __name__ == '__main__': |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
454 |
win32serviceutil.HandleCommandLine(%(CNAME)sService) |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
455 |
""" |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
456 |
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
|
457 |
service_template % {'APPID': appid, |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
458 |
'CNAME': appid.capitalize(), |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
459 |
'CWPATH': abspath(join(dirname(__file__), '..'))}) |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
460 |
|
1446 | 461 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
462 |
class DeleteInstanceCommand(Command): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
463 |
"""Delete an instance. Will remove instance's files and |
0 | 464 |
unregister it. |
465 |
""" |
|
466 |
name = 'delete' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
467 |
arguments = '<instance>' |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
468 |
min_args = max_args = 1 |
0 | 469 |
options = () |
470 |
||
471 |
def run(self, args): |
|
472 |
"""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
|
473 |
appid = args[0] |
1132 | 474 |
configs = [cwcfg.config_for(appid, configname) |
475 |
for configname in cwcfg.possible_configurations(appid)] |
|
0 | 476 |
if not configs: |
477 |
raise ExecutionError('unable to guess configuration for %s' % appid) |
|
478 |
for config in configs: |
|
479 |
helper = self.config_helper(config, required=False) |
|
480 |
if helper: |
|
481 |
helper.cleanup() |
|
482 |
# remove home |
|
483 |
rm(config.apphome) |
|
484 |
# remove instance data directory |
|
485 |
try: |
|
486 |
rm(config.appdatahome) |
|
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8682
diff
changeset
|
487 |
except OSError as ex: |
0 | 488 |
import errno |
489 |
if ex.errno != errno.ENOENT: |
|
490 |
raise |
|
491 |
confignames = ', '.join([config.name for config in configs]) |
|
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
492 |
print('-> instance %s (%s) deleted.' % (appid, confignames)) |
0 | 493 |
|
494 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
495 |
# instance commands ######################################################## |
0 | 496 |
|
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
497 |
class StartInstanceCommand(InstanceCommandFork): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
498 |
"""Start the given instances. If no instance is given, start them all. |
1446 | 499 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
500 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
501 |
identifiers of the instances to start. If no instance is |
0 | 502 |
given, start them all. |
503 |
""" |
|
504 |
name = 'start' |
|
505 |
actionverb = 'started' |
|
506 |
options = ( |
|
507 |
("debug", |
|
508 |
{'short': 'D', 'action' : 'store_true', |
|
509 |
'help': 'start server in debug mode.'}), |
|
510 |
("force", |
|
511 |
{'short': 'f', 'action' : 'store_true', |
|
512 |
'default': False, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
513 |
'help': 'start the instance even if it seems to be already \ |
0 | 514 |
running.'}), |
515 |
('profile', |
|
516 |
{'short': 'P', 'type' : 'string', 'metavar': '<stat file>', |
|
517 |
'default': None, |
|
518 |
'help': 'profile code and use the specified file to store stats', |
|
519 |
}), |
|
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
|
520 |
('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
|
521 |
{'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
|
522 |
'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
|
523 |
'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
|
524 |
}), |
10474
1dcc52f5e340
[cwctl] allow overriding config settings from the command line (closes #5557656)
David Douard <david.douard@logilab.fr>
parents:
10321
diff
changeset
|
525 |
('param', |
1dcc52f5e340
[cwctl] allow overriding config settings from the command line (closes #5557656)
David Douard <david.douard@logilab.fr>
parents:
10321
diff
changeset
|
526 |
{'short': 'p', 'type' : 'named', 'metavar' : 'key1:value1,key2:value2', |
1dcc52f5e340
[cwctl] allow overriding config settings from the command line (closes #5557656)
David Douard <david.douard@logilab.fr>
parents:
10321
diff
changeset
|
527 |
'default': {}, |
1dcc52f5e340
[cwctl] allow overriding config settings from the command line (closes #5557656)
David Douard <david.douard@logilab.fr>
parents:
10321
diff
changeset
|
528 |
'help': 'override <key> configuration file option with <value>.', |
1dcc52f5e340
[cwctl] allow overriding config settings from the command line (closes #5557656)
David Douard <david.douard@logilab.fr>
parents:
10321
diff
changeset
|
529 |
}), |
1dcc52f5e340
[cwctl] allow overriding config settings from the command line (closes #5557656)
David Douard <david.douard@logilab.fr>
parents:
10321
diff
changeset
|
530 |
) |
0 | 531 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
532 |
def start_instance(self, appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
533 |
"""start the instance's server""" |
10109
479190f019cc
[pkg] Make twisted recommended only
Christophe de Vienne <christophe@unlish.com>
parents:
10106
diff
changeset
|
534 |
try: |
479190f019cc
[pkg] Make twisted recommended only
Christophe de Vienne <christophe@unlish.com>
parents:
10106
diff
changeset
|
535 |
import twisted # noqa |
479190f019cc
[pkg] Make twisted recommended only
Christophe de Vienne <christophe@unlish.com>
parents:
10106
diff
changeset
|
536 |
except ImportError: |
479190f019cc
[pkg] Make twisted recommended only
Christophe de Vienne <christophe@unlish.com>
parents:
10106
diff
changeset
|
537 |
msg = ( |
479190f019cc
[pkg] Make twisted recommended only
Christophe de Vienne <christophe@unlish.com>
parents:
10106
diff
changeset
|
538 |
"Twisted is required by the 'start' command\n" |
479190f019cc
[pkg] Make twisted recommended only
Christophe de Vienne <christophe@unlish.com>
parents:
10106
diff
changeset
|
539 |
"Either install it, or use one of the alternative commands:\n" |
479190f019cc
[pkg] Make twisted recommended only
Christophe de Vienne <christophe@unlish.com>
parents:
10106
diff
changeset
|
540 |
"- '{ctl} wsgi {appid}'\n" |
479190f019cc
[pkg] Make twisted recommended only
Christophe de Vienne <christophe@unlish.com>
parents:
10106
diff
changeset
|
541 |
"- '{ctl} pyramid {appid}' (requires the pyramid cube)\n") |
479190f019cc
[pkg] Make twisted recommended only
Christophe de Vienne <christophe@unlish.com>
parents:
10106
diff
changeset
|
542 |
raise ExecutionError(msg.format(ctl='cubicweb-ctl', appid=appid)) |
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
|
543 |
config = cwcfg.config_for(appid, debugmode=self['debug']) |
10474
1dcc52f5e340
[cwctl] allow overriding config settings from the command line (closes #5557656)
David Douard <david.douard@logilab.fr>
parents:
10321
diff
changeset
|
544 |
# override config file values with cmdline options |
1dcc52f5e340
[cwctl] allow overriding config settings from the command line (closes #5557656)
David Douard <david.douard@logilab.fr>
parents:
10321
diff
changeset
|
545 |
config.cmdline_options = self.config.param |
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
|
546 |
init_cmdline_log_threshold(config, self['loglevel']) |
3182 | 547 |
if self['profile']: |
0 | 548 |
config.global_set_option('profile', self.config.profile) |
549 |
helper = self.config_helper(config, cmdname='start') |
|
550 |
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
|
551 |
if exists(pidf) and not self['force']: |
0 | 552 |
msg = "%s seems to be running. Remove %s by hand if necessary or use \ |
553 |
the --force option." |
|
554 |
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
|
555 |
if helper.start_server(config) == 1: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
556 |
print('instance %s started' % appid) |
0 | 557 |
|
558 |
||
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
|
559 |
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
|
560 |
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
|
561 |
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
|
562 |
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
|
563 |
|
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
|
564 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
565 |
class StopInstanceCommand(InstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
566 |
"""Stop the given instances. |
1446 | 567 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
568 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
569 |
identifiers of the instances to stop. If no instance is |
0 | 570 |
given, stop them all. |
571 |
""" |
|
572 |
name = 'stop' |
|
573 |
actionverb = 'stopped' |
|
1446 | 574 |
|
0 | 575 |
def ordered_instances(self): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
576 |
instances = super(StopInstanceCommand, self).ordered_instances() |
0 | 577 |
instances.reverse() |
578 |
return instances |
|
1446 | 579 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
580 |
def stop_instance(self, appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
581 |
"""stop the instance's server""" |
1132 | 582 |
config = cwcfg.config_for(appid) |
0 | 583 |
helper = self.config_helper(config, cmdname='stop') |
584 |
helper.poststop() # do this anyway |
|
585 |
pidf = config['pid-file'] |
|
586 |
if not exists(pidf): |
|
7896
4c954e1e73ef
[lint] remove uses of "print >> sys.stderr" (closes #1908571)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7815
diff
changeset
|
587 |
sys.stderr.write("%s doesn't exist.\n" % pidf) |
0 | 588 |
return |
589 |
import signal |
|
590 |
pid = int(open(pidf).read().strip()) |
|
591 |
try: |
|
592 |
kill(pid, signal.SIGTERM) |
|
7815
2a164a9cf81c
[exceptions] stop catching any exception in various places (closes #1942716)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7595
diff
changeset
|
593 |
except Exception: |
7896
4c954e1e73ef
[lint] remove uses of "print >> sys.stderr" (closes #1908571)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7815
diff
changeset
|
594 |
sys.stderr.write("process %s seems already dead.\n" % pid) |
0 | 595 |
else: |
596 |
try: |
|
597 |
wait_process_end(pid) |
|
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8682
diff
changeset
|
598 |
except ExecutionError as ex: |
7896
4c954e1e73ef
[lint] remove uses of "print >> sys.stderr" (closes #1908571)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7815
diff
changeset
|
599 |
sys.stderr.write('%s\ntrying SIGKILL\n' % ex) |
0 | 600 |
try: |
601 |
kill(pid, signal.SIGKILL) |
|
7815
2a164a9cf81c
[exceptions] stop catching any exception in various places (closes #1942716)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7595
diff
changeset
|
602 |
except Exception: |
0 | 603 |
# probably dead now |
604 |
pass |
|
605 |
wait_process_end(pid) |
|
606 |
try: |
|
607 |
remove(pidf) |
|
608 |
except OSError: |
|
609 |
# already removed by twistd |
|
610 |
pass |
|
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
611 |
print('instance %s stopped' % appid) |
1446 | 612 |
|
0 | 613 |
|
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
614 |
class RestartInstanceCommand(StartInstanceCommand): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
615 |
"""Restart the given instances. |
1446 | 616 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
617 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
618 |
identifiers of the instances to restart. If no instance is |
0 | 619 |
given, restart them all. |
620 |
""" |
|
621 |
name = 'restart' |
|
622 |
actionverb = 'restarted' |
|
623 |
||
624 |
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
|
625 |
regdir = cwcfg.instances_dir() |
0 | 626 |
if not isfile(join(regdir, 'startorder')) or len(args) <= 1: |
627 |
# no specific startorder |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
628 |
super(RestartInstanceCommand, self).run_args(args, askconfirm) |
0 | 629 |
return |
630 |
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
|
631 |
'instances then restart them.') |
0 | 632 |
# get instances in startorder |
633 |
for appid in args: |
|
634 |
if askconfirm: |
|
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
635 |
print('*'*72) |
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
636 |
if not ASK.confirm('%s instance %r ?' % (self.name, appid)): |
0 | 637 |
continue |
6145
528be1e059aa
more cwctl api update and fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6144
diff
changeset
|
638 |
StopInstanceCommand(self.logger).stop_instance(appid) |
0 | 639 |
forkcmd = [w for w in sys.argv if not w in args] |
640 |
forkcmd[1] = 'start' |
|
641 |
forkcmd = ' '.join(forkcmd) |
|
642 |
for appid in reversed(args): |
|
643 |
status = system('%s %s' % (forkcmd, appid)) |
|
644 |
if status: |
|
645 |
sys.exit(status) |
|
1446 | 646 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
647 |
def restart_instance(self, appid): |
6145
528be1e059aa
more cwctl api update and fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6144
diff
changeset
|
648 |
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
|
649 |
self.start_instance(appid) |
0 | 650 |
|
1446 | 651 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
652 |
class ReloadConfigurationCommand(RestartInstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
653 |
"""Reload the given instances. This command is equivalent to a |
0 | 654 |
restart for now. |
1446 | 655 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
656 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
657 |
identifiers of the instances to reload. If no instance is |
0 | 658 |
given, reload them all. |
659 |
""" |
|
660 |
name = 'reload' |
|
1446 | 661 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
662 |
def reload_instance(self, appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
663 |
self.restart_instance(appid) |
1446 | 664 |
|
0 | 665 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
666 |
class StatusCommand(InstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
667 |
"""Display status information about the given instances. |
1446 | 668 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
669 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
670 |
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
|
671 |
given, get status information about all registered instances. |
0 | 672 |
""" |
673 |
name = 'status' |
|
674 |
options = () |
|
675 |
||
1132 | 676 |
@staticmethod |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
677 |
def status_instance(appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
678 |
"""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
|
679 |
status = 0 |
1132 | 680 |
for mode in cwcfg.possible_configurations(appid): |
681 |
config = cwcfg.config_for(appid, mode) |
|
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
682 |
print('[%s-%s]' % (appid, mode), end=' ') |
0 | 683 |
try: |
684 |
pidf = config['pid-file'] |
|
685 |
except KeyError: |
|
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
686 |
print('buggy instance, pid file not specified') |
0 | 687 |
continue |
688 |
if not exists(pidf): |
|
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
689 |
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
|
690 |
status = 1 |
0 | 691 |
continue |
692 |
pid = int(open(pidf).read().strip()) |
|
693 |
# trick to guess whether or not the process is running |
|
694 |
try: |
|
695 |
getpgid(pid) |
|
696 |
except OSError: |
|
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
697 |
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
|
698 |
status = 1 |
0 | 699 |
continue |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
700 |
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
|
701 |
return status |
0 | 702 |
|
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
703 |
class UpgradeInstanceCommand(InstanceCommandFork): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
704 |
"""Upgrade an instance after cubicweb and/or component(s) upgrade. |
0 | 705 |
|
706 |
For repository update, you will be prompted for a login / password to use |
|
707 |
to connect to the system database. For some upgrades, the given user |
|
708 |
should have create or alter table permissions. |
|
709 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
710 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
711 |
identifiers of the instances to upgrade. If no instance is |
0 | 712 |
given, upgrade them all. |
713 |
""" |
|
714 |
name = 'upgrade' |
|
715 |
actionverb = 'upgraded' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
716 |
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
|
717 |
('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
|
718 |
{'short': 't', 'type' : 'named', 'metavar': 'cube1:X.Y.Z,cube2:X.Y.Z', |
0 | 719 |
'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
|
720 |
'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
|
721 |
|
0 | 722 |
('force-cubicweb-version', |
723 |
{'short': 'e', 'type' : 'string', 'metavar': 'X.Y.Z', |
|
724 |
'default': None, |
|
725 |
'help': 'force migration from the indicated cubicweb version.'}), |
|
1446 | 726 |
|
0 | 727 |
('fs-only', |
728 |
{'short': 's', 'action' : 'store_true', |
|
729 |
'default': False, |
|
730 |
'help': 'only upgrade files on the file system, not the database.'}), |
|
731 |
||
732 |
('nostartstop', |
|
733 |
{'short': 'n', 'action' : 'store_true', |
|
734 |
'default': False, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
735 |
'help': 'don\'t try to stop instance before migration and to restart it after.'}), |
1446 | 736 |
|
0 | 737 |
('verbosity', |
738 |
{'short': 'v', 'type' : 'int', 'metavar': '<0..2>', |
|
739 |
'default': 1, |
|
740 |
'help': "0: no confirmation, 1: only main commands confirmed, 2 ask \ |
|
741 |
for everything."}), |
|
1446 | 742 |
|
0 | 743 |
('backup-db', |
744 |
{'short': 'b', 'type' : 'yn', 'metavar': '<y or n>', |
|
745 |
'default': None, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
746 |
'help': "Backup the instance database before upgrade.\n"\ |
0 | 747 |
"If the option is ommitted, confirmation will be ask.", |
748 |
}), |
|
749 |
||
750 |
('ext-sources', |
|
751 |
{'short': 'E', 'type' : 'csv', 'metavar': '<sources>', |
|
752 |
'default': None, |
|
753 |
'help': "For multisources instances, specify to which sources the \ |
|
754 |
repository should connect to for upgrading. When unspecified or 'migration' is \ |
|
755 |
given, appropriate sources for migration will be automatically selected \ |
|
756 |
(recommended). If 'all' is given, will connect to all defined sources.", |
|
757 |
}), |
|
758 |
) |
|
759 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
760 |
def upgrade_instance(self, appid): |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
761 |
print('\n' + underline_title('Upgrading the instance %s' % appid)) |
0 | 762 |
from logilab.common.changelog import Version |
1132 | 763 |
config = cwcfg.config_for(appid) |
9315
5298cfb132e6
[cwctl] Only start the instance after upgrade if it was running before
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9013
diff
changeset
|
764 |
instance_running = exists(config['pid-file']) |
2473
490f88fb99b6
new distinguish repairing/creating from regular start.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2395
diff
changeset
|
765 |
config.repairing = True # notice we're not starting the server |
0 | 766 |
config.verbosity = self.config.verbosity |
7577
9892937d9041
[all] remove pattern "try: function() except AttributeError: pass" (closes #1787966)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7538
diff
changeset
|
767 |
set_sources_mode = getattr(config, 'set_sources_mode', None) |
9892937d9041
[all] remove pattern "try: function() except AttributeError: pass" (closes #1787966)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7538
diff
changeset
|
768 |
if set_sources_mode is not None: |
9892937d9041
[all] remove pattern "try: function() except AttributeError: pass" (closes #1787966)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7538
diff
changeset
|
769 |
set_sources_mode(self.config.ext_sources or ('migration',)) |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
770 |
# get instance and installed versions for the server and the componants |
0 | 771 |
mih = config.migration_handler() |
10569
af47954c1015
[migration] remove repo_connect and use config.repository() instead
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10474
diff
changeset
|
772 |
repo = mih.repo |
0 | 773 |
vcconf = repo.get_versions() |
9372
e87a808a4c32
[webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents:
9371
diff
changeset
|
774 |
helper = self.config_helper(config, required=False) |
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
|
775 |
if self.config.force_cube_version: |
10662
10942ed172de
[py3k] dict.iteritems → dict.items
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10614
diff
changeset
|
776 |
for cube, version in self.config.force_cube_version.items(): |
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
|
777 |
vcconf[cube] = Version(version) |
0 | 778 |
toupgrade = [] |
779 |
for cube in config.cubes(): |
|
780 |
installedversion = config.cube_version(cube) |
|
781 |
try: |
|
782 |
applversion = vcconf[cube] |
|
783 |
except KeyError: |
|
784 |
config.error('no version information for %s' % cube) |
|
785 |
continue |
|
786 |
if installedversion > applversion: |
|
787 |
toupgrade.append( (cube, applversion, installedversion) ) |
|
1446 | 788 |
cubicwebversion = config.cubicweb_version() |
0 | 789 |
if self.config.force_cubicweb_version: |
790 |
applcubicwebversion = Version(self.config.force_cubicweb_version) |
|
791 |
vcconf['cubicweb'] = applcubicwebversion |
|
792 |
else: |
|
793 |
applcubicwebversion = vcconf.get('cubicweb') |
|
794 |
if cubicwebversion > applcubicwebversion: |
|
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2156
diff
changeset
|
795 |
toupgrade.append(('cubicweb', applcubicwebversion, cubicwebversion)) |
1404
971b19de6b85
stop application only once we're sure we've something to do, fixing #342689
sylvain.thenault@logilab.fr
parents:
1219
diff
changeset
|
796 |
# only stop once we're sure we have something to do |
9315
5298cfb132e6
[cwctl] Only start the instance after upgrade if it was running before
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9013
diff
changeset
|
797 |
if instance_running and 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
|
798 |
StopInstanceCommand(self.logger).stop_instance(appid) |
0 | 799 |
# run cubicweb/componants migration scripts |
7538
849c04098f3f
[migration] when there are no data migration needed, we still want to rewrite the configuration and to restart the server. Closes #1760927
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7372
diff
changeset
|
800 |
if self.config.fs_only or toupgrade: |
849c04098f3f
[migration] when there are no data migration needed, we still want to rewrite the configuration and to restart the server. Closes #1760927
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7372
diff
changeset
|
801 |
for cube, fromversion, toversion in toupgrade: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
802 |
print('-> migration needed from %s to %s for %s' % (fromversion, toversion, cube)) |
9511
241b1232ed7f
Use repoapi instead of dbapi for cwctl shell, upgrade and db-init
Julien Cristau <julien.cristau@logilab.fr>
parents:
9372
diff
changeset
|
803 |
with mih.cnx: |
9556
12ee310541bb
[server/migractions] finish migration to repoapi objects
Julien Cristau <julien.cristau@logilab.fr>
parents:
9511
diff
changeset
|
804 |
with mih.cnx.security_enabled(False, False): |
12ee310541bb
[server/migractions] finish migration to repoapi objects
Julien Cristau <julien.cristau@logilab.fr>
parents:
9511
diff
changeset
|
805 |
mih.migrate(vcconf, reversed(toupgrade), self.config) |
7538
849c04098f3f
[migration] when there are no data migration needed, we still want to rewrite the configuration and to restart the server. Closes #1760927
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7372
diff
changeset
|
806 |
else: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
807 |
print('-> no data migration needed for instance %s.' % appid) |
0 | 808 |
# rewrite main configuration file |
809 |
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
|
810 |
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
|
811 |
# 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
|
812 |
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
|
813 |
return |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
814 |
print() |
9372
e87a808a4c32
[webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents:
9371
diff
changeset
|
815 |
if helper: |
e87a808a4c32
[webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents:
9371
diff
changeset
|
816 |
helper.postupgrade(repo) |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
817 |
print('-> instance migrated.') |
9315
5298cfb132e6
[cwctl] Only start the instance after upgrade if it was running before
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9013
diff
changeset
|
818 |
if instance_running and not (CWDEV or self.config.nostartstop): |
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
|
819 |
# 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
|
820 |
# 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
|
821 |
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
|
822 |
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
|
823 |
if status: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
824 |
print('%s exited with status %s' % (forkcmd, status)) |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
825 |
print() |
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
|
826 |
|
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
|
827 |
def i18nupgrade(self, config): |
0 | 828 |
# handle i18n upgrade: |
829 |
# * install new languages |
|
830 |
# * 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
|
831 |
# 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
|
832 |
from cubicweb import i18n |
1132 | 833 |
templdir = cwcfg.cube_dir(config.cubes()[0]) |
0 | 834 |
langs = [lang for lang, _ in i18n.available_catalogs(join(templdir, 'i18n'))] |
835 |
errors = config.i18ncompile(langs) |
|
836 |
if errors: |
|
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
837 |
print('\n'.join(errors)) |
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
838 |
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
|
839 |
'continue anyway?'): |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
840 |
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
|
841 |
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
|
842 |
return True |
0 | 843 |
|
7591
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
844 |
|
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
845 |
class ListVersionsInstanceCommand(InstanceCommand): |
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
846 |
"""List versions used by an instance. |
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
847 |
|
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
848 |
<instance>... |
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
849 |
identifiers of the instances to list versions for. |
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
850 |
""" |
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
851 |
name = 'versions' |
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
852 |
|
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
853 |
def versions_instance(self, appid): |
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
854 |
config = cwcfg.config_for(appid) |
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
855 |
# should not raise error if db versions don't match fs versions |
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
856 |
config.repairing = True |
9875
d4f6f4c77e9c
[cwctl] make cubicweb-ctl versions lighter (closes #4002158)
Julien Cristau <julien.cristau@logilab.fr>
parents:
9770
diff
changeset
|
857 |
# no need to load all appobjects and schema |
d4f6f4c77e9c
[cwctl] make cubicweb-ctl versions lighter (closes #4002158)
Julien Cristau <julien.cristau@logilab.fr>
parents:
9770
diff
changeset
|
858 |
config.quick_start = True |
7591
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
859 |
if hasattr(config, 'set_sources_mode'): |
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
860 |
config.set_sources_mode(('migration',)) |
10569
af47954c1015
[migration] remove repo_connect and use config.repository() instead
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10474
diff
changeset
|
861 |
vcconf = config.repository().get_versions() |
7591
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
862 |
for key in sorted(vcconf): |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
863 |
print(key+': %s.%s.%s' % vcconf[key]) |
7591
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
864 |
|
0 | 865 |
class ShellCommand(Command): |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
866 |
"""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
|
867 |
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
|
868 |
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
|
869 |
in batch mode. |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
870 |
|
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
871 |
By default it will connect to a local instance using an in memory |
9700 | 872 |
connection, unless a URL to a running instance is specified. |
0 | 873 |
|
5430
ed8f71e244f8
[shell] #715938: support of script parameters (using standard '--' as arguments separator)
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5426
diff
changeset
|
874 |
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
|
875 |
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
|
876 |
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
|
877 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
878 |
<instance> |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
879 |
the identifier of the instance to connect. |
0 | 880 |
""" |
881 |
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
|
882 |
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
|
883 |
min_args = 1 |
0 | 884 |
options = ( |
885 |
('system-only', |
|
886 |
{'short': 'S', 'action' : 'store_true', |
|
887 |
'help': 'only connect to the system source when the instance is ' |
|
888 |
'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
|
889 |
'--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
|
890 |
'group': 'local' |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
891 |
}), |
1446 | 892 |
|
0 | 893 |
('ext-sources', |
894 |
{'short': 'E', 'type' : 'csv', 'metavar': '<sources>', |
|
895 |
'help': "For multisources instances, specify to which sources the \ |
|
896 |
repository should connect to for upgrading. When unspecified or 'all' given, \ |
|
897 |
will connect to all defined sources. If 'migration' is given, appropriate \ |
|
898 |
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
|
899 |
'group': 'local' |
0 | 900 |
}), |
1446 | 901 |
|
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
|
902 |
('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
|
903 |
{'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
|
904 |
'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
|
905 |
'group': 'local' |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
906 |
}), |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
907 |
|
8352
0e3b41118631
[dbapi] add possibility to connect to a remote ZMQRepository (closes #2290126)
Vincent Michel <vincent.michel@logilab.fr>
parents:
7896
diff
changeset
|
908 |
('repo-uri', |
0e3b41118631
[dbapi] add possibility to connect to a remote ZMQRepository (closes #2290126)
Vincent Michel <vincent.michel@logilab.fr>
parents:
7896
diff
changeset
|
909 |
{'short': 'H', 'type' : 'string', 'metavar': '<protocol>://<[host][:port]>', |
0e3b41118631
[dbapi] add possibility to connect to a remote ZMQRepository (closes #2290126)
Vincent Michel <vincent.michel@logilab.fr>
parents:
7896
diff
changeset
|
910 |
'help': 'URI of the CubicWeb repository to connect to. URI can be \ |
10235
684215aca046
Remove remote repository-access-through-pyro support
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10109
diff
changeset
|
911 |
a ZMQ URL or inmemory:// (default) use an in-memory repository. THIS OPTION IS DEPRECATED, \ |
8669
62213a34726e
[db-api/configuration] simplify db-api and configuration so that all the connection information is in the repository url, closes #2521848
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8564
diff
changeset
|
912 |
directly give URI as instance id instead', |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
913 |
'group': 'remote' |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
914 |
}), |
0 | 915 |
) |
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
|
916 |
|
8682
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
917 |
def _handle_inmemory(self, appid): |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
918 |
""" returns migration context handler & shutdown function """ |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
919 |
config = cwcfg.config_for(appid) |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
920 |
if self.config.ext_sources: |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
921 |
assert not self.config.system_only |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
922 |
sources = self.config.ext_sources |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
923 |
elif self.config.system_only: |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
924 |
sources = ('system',) |
8352
0e3b41118631
[dbapi] add possibility to connect to a remote ZMQRepository (closes #2290126)
Vincent Michel <vincent.michel@logilab.fr>
parents:
7896
diff
changeset
|
925 |
else: |
8682
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
926 |
sources = ('all',) |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
927 |
config.set_sources_mode(sources) |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
928 |
config.repairing = self.config.force |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
929 |
mih = config.migration_handler() |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
930 |
return mih, lambda: mih.shutdown() |
8352
0e3b41118631
[dbapi] add possibility to connect to a remote ZMQRepository (closes #2290126)
Vincent Michel <vincent.michel@logilab.fr>
parents:
7896
diff
changeset
|
931 |
|
8682
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
932 |
def _handle_networked(self, appuri): |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
933 |
""" returns migration context handler & shutdown function """ |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
934 |
from cubicweb import AuthenticationError |
9511
241b1232ed7f
Use repoapi instead of dbapi for cwctl shell, upgrade and db-init
Julien Cristau <julien.cristau@logilab.fr>
parents:
9372
diff
changeset
|
935 |
from cubicweb.repoapi import connect, get_repository |
8682
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
936 |
from cubicweb.server.utils import manager_userpasswd |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
937 |
from cubicweb.server.migractions import ServerMigrationHelper |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
938 |
while True: |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
939 |
try: |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
940 |
login, pwd = manager_userpasswd(msg=None) |
9511
241b1232ed7f
Use repoapi instead of dbapi for cwctl shell, upgrade and db-init
Julien Cristau <julien.cristau@logilab.fr>
parents:
9372
diff
changeset
|
941 |
repo = get_repository(appuri) |
241b1232ed7f
Use repoapi instead of dbapi for cwctl shell, upgrade and db-init
Julien Cristau <julien.cristau@logilab.fr>
parents:
9372
diff
changeset
|
942 |
cnx = connect(repo, login=login, password=pwd, mulcnx=False) |
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8682
diff
changeset
|
943 |
except AuthenticationError as ex: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
944 |
print(ex) |
8682
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
945 |
except (KeyboardInterrupt, EOFError): |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
946 |
print() |
8682
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
947 |
sys.exit(0) |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
948 |
else: |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
949 |
break |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
950 |
cnx.load_appobjects() |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
951 |
repo = cnx._repo |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
952 |
mih = ServerMigrationHelper(None, repo=repo, cnx=cnx, verbosity=0, |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
953 |
# hack so it don't try to load fs schema |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
954 |
schema=1) |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
955 |
return mih, lambda: cnx.close() |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
956 |
|
0 | 957 |
def run(self, args): |
8669
62213a34726e
[db-api/configuration] simplify db-api and configuration so that all the connection information is in the repository url, closes #2521848
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8564
diff
changeset
|
958 |
appuri = args.pop(0) |
8352
0e3b41118631
[dbapi] add possibility to connect to a remote ZMQRepository (closes #2290126)
Vincent Michel <vincent.michel@logilab.fr>
parents:
7896
diff
changeset
|
959 |
if self.config.repo_uri: |
8669
62213a34726e
[db-api/configuration] simplify db-api and configuration so that all the connection information is in the repository url, closes #2521848
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8564
diff
changeset
|
960 |
warn('[3.16] --repo-uri option is deprecated, directly give the URI as instance id', |
62213a34726e
[db-api/configuration] simplify db-api and configuration so that all the connection information is in the repository url, closes #2521848
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8564
diff
changeset
|
961 |
DeprecationWarning) |
10235
684215aca046
Remove remote repository-access-through-pyro support
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10109
diff
changeset
|
962 |
if urlparse(self.config.repo_uri).scheme == 'inmemory': |
8669
62213a34726e
[db-api/configuration] simplify db-api and configuration so that all the connection information is in the repository url, closes #2521848
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8564
diff
changeset
|
963 |
appuri = '%s/%s' % (self.config.repo_uri.rstrip('/'), appuri) |
8682
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
964 |
|
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
965 |
from cubicweb.utils import parse_repo_uri |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
966 |
protocol, hostport, appid = parse_repo_uri(appuri) |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
967 |
if protocol == 'inmemory': |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
968 |
mih, shutdown_callback = self._handle_inmemory(appid) |
0 | 969 |
else: |
8682
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
970 |
mih, shutdown_callback = self._handle_networked(appuri) |
3709
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
971 |
try: |
9511
241b1232ed7f
Use repoapi instead of dbapi for cwctl shell, upgrade and db-init
Julien Cristau <julien.cristau@logilab.fr>
parents:
9372
diff
changeset
|
972 |
with mih.cnx: |
9556
12ee310541bb
[server/migractions] finish migration to repoapi objects
Julien Cristau <julien.cristau@logilab.fr>
parents:
9511
diff
changeset
|
973 |
with mih.cnx.security_enabled(False, False): |
12ee310541bb
[server/migractions] finish migration to repoapi objects
Julien Cristau <julien.cristau@logilab.fr>
parents:
9511
diff
changeset
|
974 |
if args: |
12ee310541bb
[server/migractions] finish migration to repoapi objects
Julien Cristau <julien.cristau@logilab.fr>
parents:
9511
diff
changeset
|
975 |
# use cmdline parser to access left/right attributes only |
12ee310541bb
[server/migractions] finish migration to repoapi objects
Julien Cristau <julien.cristau@logilab.fr>
parents:
9511
diff
changeset
|
976 |
# remember that usage requires instance appid as first argument |
12ee310541bb
[server/migractions] finish migration to repoapi objects
Julien Cristau <julien.cristau@logilab.fr>
parents:
9511
diff
changeset
|
977 |
scripts, args = self.cmdline_parser.largs[1:], self.cmdline_parser.rargs |
12ee310541bb
[server/migractions] finish migration to repoapi objects
Julien Cristau <julien.cristau@logilab.fr>
parents:
9511
diff
changeset
|
978 |
for script in scripts: |
12ee310541bb
[server/migractions] finish migration to repoapi objects
Julien Cristau <julien.cristau@logilab.fr>
parents:
9511
diff
changeset
|
979 |
mih.cmd_process_script(script, scriptargs=args) |
12ee310541bb
[server/migractions] finish migration to repoapi objects
Julien Cristau <julien.cristau@logilab.fr>
parents:
9511
diff
changeset
|
980 |
mih.commit() |
12ee310541bb
[server/migractions] finish migration to repoapi objects
Julien Cristau <julien.cristau@logilab.fr>
parents:
9511
diff
changeset
|
981 |
else: |
12ee310541bb
[server/migractions] finish migration to repoapi objects
Julien Cristau <julien.cristau@logilab.fr>
parents:
9511
diff
changeset
|
982 |
mih.interactive_shell() |
3709
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
983 |
finally: |
8682
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
984 |
shutdown_callback() |
0 | 985 |
|
986 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
987 |
class RecompileInstanceCatalogsCommand(InstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
988 |
"""Recompile i18n catalogs for instances. |
1446 | 989 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
990 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
991 |
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
|
992 |
given, recompile for all registered instances. |
0 | 993 |
""" |
1898
39b37f90a8a4
[cw-ctl] rename i18n commands (see #342889)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1477
diff
changeset
|
994 |
name = 'i18ninstance' |
1132 | 995 |
|
996 |
@staticmethod |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
997 |
def i18ninstance_instance(appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
998 |
"""recompile instance's messages catalogs""" |
1132 | 999 |
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
|
1000 |
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
|
1001 |
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
|
1002 |
if config._cubes is None: |
0 | 1003 |
# 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
|
1004 |
config.init_cubes(repo.get_cubes()) |
0 | 1005 |
errors = config.i18ncompile() |
1006 |
if errors: |
|
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
1007 |
print('\n'.join(errors)) |
0 | 1008 |
|
1009 |
||
1010 |
class ListInstancesCommand(Command): |
|
1011 |
"""list available instances, useful for bash completion.""" |
|
1012 |
name = 'listinstances' |
|
1013 |
hidden = True |
|
1446 | 1014 |
|
0 | 1015 |
def run(self, args): |
1016 |
"""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
|
1017 |
regdir = cwcfg.instances_dir() |
0 | 1018 |
for appid in sorted(listdir(regdir)): |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
1019 |
print(appid) |
0 | 1020 |
|
1021 |
||
1022 |
class ListCubesCommand(Command): |
|
1023 |
"""list available componants, useful for bash completion.""" |
|
1024 |
name = 'listcubes' |
|
1025 |
hidden = True |
|
1446 | 1026 |
|
0 | 1027 |
def run(self, args): |
1028 |
"""run the command with its specific arguments""" |
|
1132 | 1029 |
for cube in cwcfg.available_cubes(): |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
1030 |
print(cube) |
0 | 1031 |
|
9002
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
1032 |
class ConfigureInstanceCommand(InstanceCommand): |
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
1033 |
"""Configure instance. |
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
1034 |
|
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
1035 |
<instance>... |
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
1036 |
identifier of the instance to configure. |
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
1037 |
""" |
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
1038 |
name = 'configure' |
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
1039 |
actionverb = 'configured' |
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
1040 |
|
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
1041 |
options = merge_options(InstanceCommand.options + |
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
1042 |
(('param', |
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
1043 |
{'short': 'p', 'type' : 'named', 'metavar' : 'key1:value1,key2:value2', |
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
1044 |
'default': None, |
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
1045 |
'help': 'set <key> to <value> in configuration file.', |
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
1046 |
}), |
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
1047 |
)) |
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
1048 |
|
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
1049 |
def configure_instance(self, appid): |
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
1050 |
if self.config.param is not None: |
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
1051 |
appcfg = cwcfg.config_for(appid) |
10662
10942ed172de
[py3k] dict.iteritems → dict.items
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10614
diff
changeset
|
1052 |
for key, value in self.config.param.items(): |
9002
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
1053 |
try: |
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
1054 |
appcfg.global_set_option(key, value) |
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
1055 |
except KeyError: |
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
1056 |
raise ConfigurationError('unknown configuration key "%s" for mode %s' % (key, appcfg.name)) |
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
1057 |
appcfg.save() |
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
1058 |
|
9287
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
9255
diff
changeset
|
1059 |
|
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
9255
diff
changeset
|
1060 |
# WSGI ######### |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
9255
diff
changeset
|
1061 |
|
10104
cdc0b0216da2
[cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents:
9990
diff
changeset
|
1062 |
WSGI_CHOICES = {} |
cdc0b0216da2
[cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents:
9990
diff
changeset
|
1063 |
from cubicweb.wsgi import server as stdlib_server |
cdc0b0216da2
[cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents:
9990
diff
changeset
|
1064 |
WSGI_CHOICES['stdlib'] = stdlib_server |
cdc0b0216da2
[cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents:
9990
diff
changeset
|
1065 |
try: |
cdc0b0216da2
[cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents:
9990
diff
changeset
|
1066 |
from cubicweb.wsgi import wz |
cdc0b0216da2
[cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents:
9990
diff
changeset
|
1067 |
except ImportError: |
cdc0b0216da2
[cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents:
9990
diff
changeset
|
1068 |
pass |
cdc0b0216da2
[cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents:
9990
diff
changeset
|
1069 |
else: |
cdc0b0216da2
[cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents:
9990
diff
changeset
|
1070 |
WSGI_CHOICES['werkzeug'] = wz |
10106
3117f1736f00
[wsgi] add tornado http server
Alain Leufroy <alain@leufroy.fr>
parents:
10104
diff
changeset
|
1071 |
try: |
3117f1736f00
[wsgi] add tornado http server
Alain Leufroy <alain@leufroy.fr>
parents:
10104
diff
changeset
|
1072 |
from cubicweb.wsgi import tnd |
3117f1736f00
[wsgi] add tornado http server
Alain Leufroy <alain@leufroy.fr>
parents:
10104
diff
changeset
|
1073 |
except ImportError: |
3117f1736f00
[wsgi] add tornado http server
Alain Leufroy <alain@leufroy.fr>
parents:
10104
diff
changeset
|
1074 |
pass |
3117f1736f00
[wsgi] add tornado http server
Alain Leufroy <alain@leufroy.fr>
parents:
10104
diff
changeset
|
1075 |
else: |
3117f1736f00
[wsgi] add tornado http server
Alain Leufroy <alain@leufroy.fr>
parents:
10104
diff
changeset
|
1076 |
WSGI_CHOICES['tornado'] = tnd |
10104
cdc0b0216da2
[cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents:
9990
diff
changeset
|
1077 |
|
cdc0b0216da2
[cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents:
9990
diff
changeset
|
1078 |
|
9288
823cf14bcc37
[wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9287
diff
changeset
|
1079 |
def wsgichoices(): |
10104
cdc0b0216da2
[cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents:
9990
diff
changeset
|
1080 |
return tuple(WSGI_CHOICES) |
cdc0b0216da2
[cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents:
9990
diff
changeset
|
1081 |
|
9288
823cf14bcc37
[wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9287
diff
changeset
|
1082 |
|
9945
cf5b0d0f5731
[wsgi] add the --debug / -D option to the wsgi command
Christophe de Vienne <christophe@unlish.com>
parents:
9770
diff
changeset
|
1083 |
class WSGIStartHandler(InstanceCommand): |
9287
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
9255
diff
changeset
|
1084 |
"""Start an interactive wsgi server """ |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
9255
diff
changeset
|
1085 |
name = 'wsgi' |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
9255
diff
changeset
|
1086 |
actionverb = 'started' |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
9255
diff
changeset
|
1087 |
arguments = '<instance>' |
10104
cdc0b0216da2
[cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents:
9990
diff
changeset
|
1088 |
|
cdc0b0216da2
[cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents:
9990
diff
changeset
|
1089 |
@property |
cdc0b0216da2
[cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents:
9990
diff
changeset
|
1090 |
def options(self): |
cdc0b0216da2
[cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents:
9990
diff
changeset
|
1091 |
return ( |
9945
cf5b0d0f5731
[wsgi] add the --debug / -D option to the wsgi command
Christophe de Vienne <christophe@unlish.com>
parents:
9770
diff
changeset
|
1092 |
("debug", |
cf5b0d0f5731
[wsgi] add the --debug / -D option to the wsgi command
Christophe de Vienne <christophe@unlish.com>
parents:
9770
diff
changeset
|
1093 |
{'short': 'D', 'action': 'store_true', |
cf5b0d0f5731
[wsgi] add the --debug / -D option to the wsgi command
Christophe de Vienne <christophe@unlish.com>
parents:
9770
diff
changeset
|
1094 |
'default': False, |
cf5b0d0f5731
[wsgi] add the --debug / -D option to the wsgi command
Christophe de Vienne <christophe@unlish.com>
parents:
9770
diff
changeset
|
1095 |
'help': 'start server in debug mode.'}), |
9288
823cf14bcc37
[wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9287
diff
changeset
|
1096 |
('method', |
823cf14bcc37
[wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9287
diff
changeset
|
1097 |
{'short': 'm', |
823cf14bcc37
[wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9287
diff
changeset
|
1098 |
'type': 'choice', |
823cf14bcc37
[wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9287
diff
changeset
|
1099 |
'metavar': '<method>', |
823cf14bcc37
[wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9287
diff
changeset
|
1100 |
'default': 'stdlib', |
823cf14bcc37
[wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9287
diff
changeset
|
1101 |
'choices': wsgichoices(), |
823cf14bcc37
[wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9287
diff
changeset
|
1102 |
'help': 'wsgi utility/method'}), |
9287
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
9255
diff
changeset
|
1103 |
('loglevel', |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
9255
diff
changeset
|
1104 |
{'short': 'l', |
9945
cf5b0d0f5731
[wsgi] add the --debug / -D option to the wsgi command
Christophe de Vienne <christophe@unlish.com>
parents:
9770
diff
changeset
|
1105 |
'type': 'choice', |
9287
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
9255
diff
changeset
|
1106 |
'metavar': '<log level>', |
9945
cf5b0d0f5731
[wsgi] add the --debug / -D option to the wsgi command
Christophe de Vienne <christophe@unlish.com>
parents:
9770
diff
changeset
|
1107 |
'default': None, |
9287
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
9255
diff
changeset
|
1108 |
'choices': ('debug', 'info', 'warning', 'error'), |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
9255
diff
changeset
|
1109 |
'help': 'debug if -D is set, error otherwise', |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
9255
diff
changeset
|
1110 |
}), |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
9255
diff
changeset
|
1111 |
) |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
9255
diff
changeset
|
1112 |
|
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
9255
diff
changeset
|
1113 |
def wsgi_instance(self, appid): |
9945
cf5b0d0f5731
[wsgi] add the --debug / -D option to the wsgi command
Christophe de Vienne <christophe@unlish.com>
parents:
9770
diff
changeset
|
1114 |
config = cwcfg.config_for(appid, debugmode=self['debug']) |
9287
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
9255
diff
changeset
|
1115 |
init_cmdline_log_threshold(config, self['loglevel']) |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
9255
diff
changeset
|
1116 |
assert config.name == 'all-in-one' |
9288
823cf14bcc37
[wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9287
diff
changeset
|
1117 |
meth = self['method'] |
10104
cdc0b0216da2
[cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents:
9990
diff
changeset
|
1118 |
server = WSGI_CHOICES[meth] |
9287
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
9255
diff
changeset
|
1119 |
return server.run(config) |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
9255
diff
changeset
|
1120 |
|
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
9255
diff
changeset
|
1121 |
|
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
9255
diff
changeset
|
1122 |
|
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
1123 |
for cmdcls in (ListCommand, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
1124 |
CreateInstanceCommand, DeleteInstanceCommand, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
1125 |
StartInstanceCommand, StopInstanceCommand, RestartInstanceCommand, |
9945
cf5b0d0f5731
[wsgi] add the --debug / -D option to the wsgi command
Christophe de Vienne <christophe@unlish.com>
parents:
9770
diff
changeset
|
1126 |
WSGIStartHandler, |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
1127 |
ReloadConfigurationCommand, StatusCommand, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
1128 |
UpgradeInstanceCommand, |
7591
cb6ece9cdb78
[cw-ctl] add command versions to list versions of cubes used by an instance (closes #508052)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7577
diff
changeset
|
1129 |
ListVersionsInstanceCommand, |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
1130 |
ShellCommand, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
1131 |
RecompileInstanceCatalogsCommand, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
1132 |
ListInstancesCommand, ListCubesCommand, |
9002
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
1133 |
ConfigureInstanceCommand, |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
1134 |
): |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
1135 |
CWCTL.register(cmdcls) |
0 | 1136 |
|
9287
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
9255
diff
changeset
|
1137 |
|
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
9255
diff
changeset
|
1138 |
|
0 | 1139 |
def run(args): |
1140 |
"""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
|
1141 |
import os |
10321
a4af502191d5
[cwctl] don't filter DeprecationWarnings
Julien Cristau <julien.cristau@logilab.fr>
parents:
10235
diff
changeset
|
1142 |
filterwarnings('default', category=DeprecationWarning) |
1132 | 1143 |
cwcfg.load_cwctl_plugins() |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
1144 |
try: |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
1145 |
CWCTL.run(args) |
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8682
diff
changeset
|
1146 |
except ConfigurationError as err: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
1147 |
print('ERROR: ', err) |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
1148 |
sys.exit(1) |
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8682
diff
changeset
|
1149 |
except ExecutionError as err: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
1150 |
print(err) |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
1151 |
sys.exit(2) |
0 | 1152 |
|
1153 |
if __name__ == '__main__': |
|
1154 |
run(sys.argv[1:]) |