author | Philippe Pepiot <philippe.pepiot@logilab.fr> |
Thu, 28 Mar 2019 10:11:36 +0100 | |
changeset 12548 | 6eec3213bec9 |
parent 12526 | b78e3472a7d6 |
child 12549 | e2db422752b4 |
permissions | -rw-r--r-- |
11867
c714e55fbce1
[cwctl] Kill deprecated ordered_instances method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11767
diff
changeset
|
1 |
# copyright 2003-2016 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 |
|
4718
3dc3ad02d091
avoid module import in c-c plugins module, and remind it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4684
diff
changeset
|
23 |
# *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
|
24 |
# 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
|
25 |
# completion). So import locally in command helpers. |
0 | 26 |
import sys |
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
27 |
from warnings import filterwarnings |
12526
b78e3472a7d6
Remove ctl commands using the Twisted backend
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12525
diff
changeset
|
28 |
from os import listdir, system, pathsep |
12524
8d3952d7124d
Remove _handle_win32() method from "create" command class
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12508
diff
changeset
|
29 |
from os.path import exists, join, isdir |
8682
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
30 |
|
3115
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
2905
diff
changeset
|
31 |
try: |
3562 | 32 |
from os import kill, getpgid |
3115
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
2905
diff
changeset
|
33 |
except ImportError: |
4721
8f63691ccb7f
pylint style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4720
diff
changeset
|
34 |
def kill(*args): |
8f63691ccb7f
pylint style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4720
diff
changeset
|
35 |
"""win32 kill implementation""" |
8f63691ccb7f
pylint style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4720
diff
changeset
|
36 |
def getpgid(): |
8f63691ccb7f
pylint style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4720
diff
changeset
|
37 |
"""win32 getpgid implementation""" |
3115
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
2905
diff
changeset
|
38 |
|
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
39 |
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
|
40 |
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
|
41 |
from logilab.common.configuration import merge_options |
11878
e42cb31e9301
[cwctl] on upgrade, clear instance_md5_version cache
Julien Cristau <julien.cristau@logilab.fr>
parents:
11870
diff
changeset
|
42 |
from logilab.common.decorators import clear_cache |
1132 | 43 |
|
2790
968108e16066
move underline_title to toolsutils
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2743
diff
changeset
|
44 |
from cubicweb import ConfigurationError, ExecutionError, BadCommandUsage |
12265
3f57a23e9954
[cwconfig] Get rid of CWDEV
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12253
diff
changeset
|
45 |
from cubicweb.cwconfig import CubicWebConfiguration as cwcfg, CONFIGURATIONS |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
46 |
from cubicweb.toolsutils import Command, rm, create_dir, underline_title |
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
47 |
from cubicweb.__pkginfo__ import version as cw_version |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
48 |
|
9371
1348202527a6
[cwctl] Don't check for old lgc versions
Julien Cristau <julien.cristau@logilab.fr>
parents:
9340
diff
changeset
|
49 |
# 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
|
50 |
CWCTL = CommandLine('cubicweb-ctl', 'The CubicWeb swiss-knife.', |
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
51 |
version=cw_version, check_duplicated_command=False) |
1446 | 52 |
|
11870
3a84a79c4ed5
Flake8 bits with some copyright updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11867
diff
changeset
|
53 |
|
0 | 54 |
def wait_process_end(pid, maxtry=10, waittime=1): |
55 |
"""wait for a process to actually die""" |
|
56 |
import signal |
|
57 |
from time import sleep |
|
58 |
nbtry = 0 |
|
59 |
while nbtry < maxtry: |
|
60 |
try: |
|
61 |
kill(pid, signal.SIGUSR1) |
|
11870
3a84a79c4ed5
Flake8 bits with some copyright updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11867
diff
changeset
|
62 |
except (OSError, AttributeError): # XXX win32 |
0 | 63 |
break |
64 |
nbtry += 1 |
|
65 |
sleep(waittime) |
|
66 |
else: |
|
67 |
raise ExecutionError('can\'t kill process %s' % pid) |
|
68 |
||
11870
3a84a79c4ed5
Flake8 bits with some copyright updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11867
diff
changeset
|
69 |
|
0 | 70 |
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
|
71 |
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
|
72 |
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
|
73 |
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
|
74 |
return [] |
0 | 75 |
|
11870
3a84a79c4ed5
Flake8 bits with some copyright updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
11867
diff
changeset
|
76 |
|
0 | 77 |
def detect_available_modes(templdir): |
78 |
modes = [] |
|
79 |
for fname in ('schema', 'schema.py'): |
|
80 |
if exists(join(templdir, fname)): |
|
81 |
modes.append('repository') |
|
82 |
break |
|
83 |
for fname in ('data', 'views', 'views.py'): |
|
84 |
if exists(join(templdir, fname)): |
|
85 |
modes.append('web ui') |
|
86 |
break |
|
87 |
return modes |
|
1446 | 88 |
|
89 |
||
12120
707139a9eb00
[cwctl] Drop 'cubicweb_' prefix when displaying cubes with 'cubicweb-ctl list'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
12068
diff
changeset
|
90 |
def available_cube_names(cwcfg): |
707139a9eb00
[cwctl] Drop 'cubicweb_' prefix when displaying cubes with 'cubicweb-ctl list'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
12068
diff
changeset
|
91 |
"""Return a list of available cube names, with 'cubicweb_' prefix dropped. |
707139a9eb00
[cwctl] Drop 'cubicweb_' prefix when displaying cubes with 'cubicweb-ctl list'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
12068
diff
changeset
|
92 |
""" |
707139a9eb00
[cwctl] Drop 'cubicweb_' prefix when displaying cubes with 'cubicweb-ctl list'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
12068
diff
changeset
|
93 |
def drop_prefix(cube): |
707139a9eb00
[cwctl] Drop 'cubicweb_' prefix when displaying cubes with 'cubicweb-ctl list'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
12068
diff
changeset
|
94 |
prefix = 'cubicweb_' |
707139a9eb00
[cwctl] Drop 'cubicweb_' prefix when displaying cubes with 'cubicweb-ctl list'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
12068
diff
changeset
|
95 |
if cube.startswith(prefix): |
707139a9eb00
[cwctl] Drop 'cubicweb_' prefix when displaying cubes with 'cubicweb-ctl list'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
12068
diff
changeset
|
96 |
cube = cube[len(prefix):] |
707139a9eb00
[cwctl] Drop 'cubicweb_' prefix when displaying cubes with 'cubicweb-ctl list'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
12068
diff
changeset
|
97 |
return cube |
707139a9eb00
[cwctl] Drop 'cubicweb_' prefix when displaying cubes with 'cubicweb-ctl list'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
12068
diff
changeset
|
98 |
|
707139a9eb00
[cwctl] Drop 'cubicweb_' prefix when displaying cubes with 'cubicweb-ctl list'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
12068
diff
changeset
|
99 |
return [drop_prefix(cube) for cube in cwcfg.available_cubes()] |
707139a9eb00
[cwctl] Drop 'cubicweb_' prefix when displaying cubes with 'cubicweb-ctl list'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
12068
diff
changeset
|
100 |
|
707139a9eb00
[cwctl] Drop 'cubicweb_' prefix when displaying cubes with 'cubicweb-ctl list'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
12068
diff
changeset
|
101 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
102 |
class InstanceCommand(Command): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
103 |
"""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
|
104 |
(0 meaning all registered instances) |
0 | 105 |
""" |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
106 |
arguments = '[<instance>...]' |
0 | 107 |
options = ( |
108 |
("force", |
|
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
109 |
{'short': 'f', 'action': 'store_true', |
0 | 110 |
'default': False, |
111 |
'help': 'force command without asking confirmation', |
|
112 |
} |
|
113 |
), |
|
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
114 |
) |
0 | 115 |
actionverb = None |
1446 | 116 |
|
0 | 117 |
def run(self, args): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
118 |
"""run the <command>_method on each argument (a list of instance |
0 | 119 |
identifiers) |
120 |
""" |
|
121 |
if not args: |
|
11104
269317987dc6
[cwctl] remove support for startorder file in /etc/cubicweb.d (closes #5618947)
David Douard <david.douard@logilab.fr>
parents:
10736
diff
changeset
|
122 |
args = list_instances(cwcfg.instances_dir()) |
0 | 123 |
try: |
124 |
askconfirm = not self.config.force |
|
125 |
except AttributeError: |
|
126 |
# no force option |
|
127 |
askconfirm = False |
|
128 |
else: |
|
129 |
askconfirm = False |
|
130 |
self.run_args(args, askconfirm) |
|
1446 | 131 |
|
0 | 132 |
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
|
133 |
status = 0 |
0 | 134 |
for appid in args: |
135 |
if askconfirm: |
|
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
136 |
print('*' * 72) |
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
137 |
if not ASK.confirm('%s instance %r ?' % (self.name, appid)): |
0 | 138 |
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
|
139 |
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
|
140 |
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
|
141 |
except (KeyboardInterrupt, SystemExit): |
7896
4c954e1e73ef
[lint] remove uses of "print >> sys.stderr" (closes #1908571)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
7815
diff
changeset
|
142 |
sys.stderr.write('%s aborted\n' % self.name) |
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
143 |
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
|
144 |
sys.exit(status) |
1446 | 145 |
|
0 | 146 |
def run_arg(self, appid): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
147 |
cmdmeth = getattr(self, '%s_instance' % self.name) |
0 | 148 |
try: |
12317
5166a1a7e4f4
[py3] Let InstanceCommand.run_arg() always return an int
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12265
diff
changeset
|
149 |
status = cmdmeth(appid) or 0 |
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8682
diff
changeset
|
150 |
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
|
151 |
sys.stderr.write('instance %s not %s: %s\n' % ( |
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
152 |
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
|
153 |
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
|
154 |
except Exception as ex: |
0 | 155 |
import traceback |
156 |
traceback.print_exc() |
|
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('instance %s not %s: %s\n' % ( |
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
158 |
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
|
159 |
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
|
160 |
return status |
0 | 161 |
|
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
162 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
163 |
class InstanceCommandFork(InstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
164 |
"""Same as `InstanceCommand`, but command is forked in a new environment |
0 | 165 |
for each argument |
166 |
""" |
|
167 |
||
168 |
def run_args(self, args, askconfirm): |
|
169 |
if len(args) > 1: |
|
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
170 |
forkcmd = ' '.join(w for w in sys.argv if w not in args) |
0 | 171 |
else: |
172 |
forkcmd = None |
|
173 |
for appid in args: |
|
174 |
if askconfirm: |
|
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
175 |
print('*' * 72) |
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
176 |
if not ASK.confirm('%s instance %r ?' % (self.name, appid)): |
0 | 177 |
continue |
178 |
if forkcmd: |
|
179 |
status = system('%s %s' % (forkcmd, appid)) |
|
180 |
if status: |
|
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
181 |
print('%s exited with status %s' % (forkcmd, status)) |
0 | 182 |
else: |
183 |
self.run_arg(appid) |
|
1446 | 184 |
|
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
185 |
|
0 | 186 |
# base commands ############################################################### |
187 |
||
188 |
class ListCommand(Command): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
189 |
"""List configurations, cubes and instances. |
0 | 190 |
|
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
|
191 |
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
|
192 |
|
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
193 |
If given, the optional argument allows to restrict listing only a category of items. |
0 | 194 |
""" |
195 |
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
|
196 |
arguments = '[all|cubes|configurations|instances]' |
0 | 197 |
options = ( |
198 |
('verbose', |
|
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
199 |
{'short': 'v', 'action': 'store_true', |
1446 | 200 |
'help': "display more information."}), |
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
201 |
) |
1446 | 202 |
|
0 | 203 |
def run(self, args): |
204 |
"""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
|
205 |
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
|
206 |
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
|
207 |
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
|
208 |
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
|
209 |
else: |
5608
f9ab62103ad4
proof read documentation
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
5498
diff
changeset
|
210 |
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
|
211 |
|
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
|
212 |
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
|
213 |
|
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
214 |
if mode == 'all': |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
215 |
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
|
216 |
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
|
217 |
|
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
218 |
if mode in ('all', 'config', 'configurations'): |
11997
7c296802980b
[ctl] Load available configurations in "cubicweb-ctl list"
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11767
diff
changeset
|
219 |
cwcfg.load_available_configs() |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
220 |
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
|
221 |
for config in CONFIGURATIONS: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
222 |
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
|
223 |
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
|
224 |
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
|
225 |
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
|
226 |
continue |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
227 |
print(' ', line) |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
228 |
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
|
229 |
|
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
230 |
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
|
231 |
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
|
232 |
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
|
233 |
cubesdir = pathsep.join(cwcfg.cubes_search_path()) |
12120
707139a9eb00
[cwctl] Drop 'cubicweb_' prefix when displaying cubes with 'cubicweb-ctl list'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
12068
diff
changeset
|
234 |
cube_names = available_cube_names(cwcfg) |
707139a9eb00
[cwctl] Drop 'cubicweb_' prefix when displaying cubes with 'cubicweb-ctl list'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
12068
diff
changeset
|
235 |
namesize = max(len(x) for x in cube_names) |
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 |
except ConfigurationError as ex: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
237 |
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
|
238 |
except ValueError: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
239 |
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
|
240 |
else: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
241 |
print('Available cubes (%s):' % cubesdir) |
12120
707139a9eb00
[cwctl] Drop 'cubicweb_' prefix when displaying cubes with 'cubicweb-ctl list'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
12068
diff
changeset
|
242 |
for cube in cube_names: |
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
|
243 |
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
|
244 |
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
|
245 |
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
|
246 |
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
|
247 |
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
|
248 |
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
|
249 |
tversion = '[missing cube information: %s]' % ex |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
250 |
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
|
251 |
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
|
252 |
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
|
253 |
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
|
254 |
if not descr: |
9255
46f41c3e1443
remove 3.8 bw compat
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9251
diff
changeset
|
255 |
descr = tinfo.__doc__ |
5025
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
256 |
if descr: |
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
257 |
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
|
258 |
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
|
259 |
print(' available modes: %s' % ', '.join(modes)) |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
260 |
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
|
261 |
|
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
262 |
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
|
263 |
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
|
264 |
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
|
265 |
except ConfigurationError as ex: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
266 |
print('No instance available:', ex) |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
267 |
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
|
268 |
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
|
269 |
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
|
270 |
if instances: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
271 |
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
|
272 |
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
|
273 |
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
|
274 |
if not modes: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
275 |
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
|
276 |
continue |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
277 |
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
|
278 |
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
|
279 |
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
|
280 |
except Exception as exc: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
281 |
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
|
282 |
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
|
283 |
else: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
284 |
print('No instance available in %s' % regdir) |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
285 |
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
|
286 |
|
bb14dc9848ec
[c-c list] add an optional argument to the list command (closes #2709703)
David Douard <david.douard@logilab.fr>
parents:
8718
diff
changeset
|
287 |
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
|
288 |
# 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
|
289 |
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
|
290 |
if cfgpb.warnings: |
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
291 |
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
|
292 |
if cfgpb.errors: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
293 |
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
|
294 |
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
|
295 |
if op == 'add': |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
296 |
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
|
297 |
if version: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
298 |
print(' version', version, end=' ') |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
299 |
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
|
300 |
else: |
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
301 |
print( |
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
302 |
'* cube %s version %s is installed, but version %s is required by %s' |
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
303 |
% (cube, cfgpb.cubes[cube], version, src) |
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
304 |
) |
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
305 |
|
0 | 306 |
|
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
|
307 |
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
|
308 |
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
|
309 |
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
|
310 |
'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
|
311 |
|
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
312 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
313 |
class CreateInstanceCommand(Command): |
9704 | 314 |
"""Create an instance from a cube. This is a unified |
0 | 315 |
command which can handle web / server / all-in-one installation |
316 |
according to available parts of the software library and of the |
|
317 |
desired cube. |
|
318 |
||
319 |
<cube> |
|
320 |
the name of cube to use (list available cube names using |
|
321 |
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
|
322 |
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
|
323 |
<instance> |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
324 |
an identifier for the instance to create |
0 | 325 |
""" |
326 |
name = 'create' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
327 |
arguments = '<cube> <instance>' |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
328 |
min_args = max_args = 2 |
0 | 329 |
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
|
330 |
('automatic', |
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
331 |
{'short': 'a', 'action': 'store_true', |
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
|
332 |
'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
|
333 |
'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
|
334 |
'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
|
335 |
'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
|
336 |
}), |
ba51dac1115d
[c-c create] unification of c-c create and its subcommands handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7131
diff
changeset
|
337 |
('config-level', |
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
338 |
{'short': 'l', 'type': 'int', 'metavar': '<level>', |
0 | 339 |
'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
|
340 |
'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
|
341 |
'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
|
342 |
}), |
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 |
('config', |
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
344 |
{'short': 'c', 'type': 'choice', 'metavar': '<install type>', |
12053
c3c9f2e1424c
[pyramid] Add a "pyramid" instance configuration type
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11992
diff
changeset
|
345 |
'choices': ('all-in-one', 'repository', 'pyramid'), |
0 | 346 |
'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
|
347 |
'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
|
348 |
'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
|
349 |
' "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
|
350 |
'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
|
351 |
}), |
9001
328c24289253
[cwctl] rename option no-post-create to no-db-create
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8930
diff
changeset
|
352 |
('no-db-create', |
328c24289253
[cwctl] rename option no-post-create to no-db-create
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8930
diff
changeset
|
353 |
{'short': 'S', |
8851
0020aa12af07
[c-c create] make post-create step optional (closes #2712041)
David Douard <david.douard@logilab.fr>
parents:
8829
diff
changeset
|
354 |
'action': 'store_true', |
0020aa12af07
[c-c create] make post-create step optional (closes #2712041)
David Douard <david.douard@logilab.fr>
parents:
8829
diff
changeset
|
355 |
'default': False, |
9001
328c24289253
[cwctl] rename option no-post-create to no-db-create
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8930
diff
changeset
|
356 |
'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
|
357 |
}), |
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
358 |
) |
1446 | 359 |
|
0 | 360 |
def run(self, args): |
361 |
"""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
|
362 |
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
|
363 |
check_options_consistency(self.config) |
0 | 364 |
configname = self.config.config |
6144
40af8e328e64
[c-c create] argument inversed accidentally
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
365 |
cubes, appid = args |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
366 |
cubes = splitstrip(cubes) |
0 | 367 |
# 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
|
368 |
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
|
369 |
cubes = config.expand_cubes(cubes) |
b4ffcea3275b
change cubes into expanded cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2032
diff
changeset
|
370 |
config.init_cubes(cubes) |
0 | 371 |
helper = self.config_helper(config) |
372 |
# check the cube exists |
|
373 |
try: |
|
1132 | 374 |
templdirs = [cwcfg.cube_dir(cube) |
0 | 375 |
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
|
376 |
except ConfigurationError as ex: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
377 |
print(ex) |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
378 |
print('\navailable cubes:', end=' ') |
12120
707139a9eb00
[cwctl] Drop 'cubicweb_' prefix when displaying cubes with 'cubicweb-ctl list'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
12068
diff
changeset
|
379 |
print(', '.join(available_cube_names(cwcfg))) |
0 | 380 |
return |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
381 |
# create the registry directory for this instance |
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
382 |
print('\n' + underline_title('Creating the instance %s' % appid)) |
0 | 383 |
create_dir(config.apphome) |
384 |
# 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
|
385 |
if not self.config.automatic: |
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
386 |
print('\n' + underline_title('Configuring the instance (%s.conf)' |
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
387 |
% 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
|
388 |
config.input_config('main', self.config.config_level) |
0 | 389 |
# configuration'specific stuff |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
390 |
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
|
391 |
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
|
392 |
# 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
|
393 |
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
|
394 |
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
|
395 |
if 'type' in odict |
11284
d4293b14c664
[py3k] Fix config-level comparison in "cubicweb-ctl create" command
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11279
diff
changeset
|
396 |
and odict.get('level', 0) <= self.config.config_level) |
9923
da09975300aa
[cwctl] don't prompt for cube options in automatic mode
Julien Cristau <julien.cristau@logilab.fr>
parents:
9704
diff
changeset
|
397 |
for section in sections: |
10235
684215aca046
Remove remote repository-access-through-pyro support
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
10109
diff
changeset
|
398 |
if section not in ('main', 'email', 'web'): |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
399 |
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
|
400 |
config.input_config(section, self.config.config_level) |
0 | 401 |
# write down configuration |
402 |
config.save() |
|
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
403 |
print('-> generated config %s' % config.main_config_file()) |
0 | 404 |
# handle i18n files structure |
405 |
# 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
|
406 |
from cubicweb import i18n |
0 | 407 |
langs = [lang for lang, _ in i18n.available_catalogs(join(templdirs[0], 'i18n'))] |
408 |
errors = config.i18ncompile(langs) |
|
409 |
if errors: |
|
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
410 |
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
|
411 |
if self.config.automatic \ |
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
412 |
or not ASK.confirm('error while compiling message catalogs, ' |
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
413 |
'continue anyway ?'): |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
414 |
print('creation not completed') |
0 | 415 |
return |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
416 |
# create the additional data directory for this instance |
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
417 |
if config.appdatahome != config.apphome: # true in dev mode |
0 | 418 |
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
|
419 |
create_dir(join(config.appdatahome, 'backup')) |
0 | 420 |
if config['uid']: |
421 |
from logilab.common.shellutils import chown |
|
422 |
# 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
|
423 |
print('set %s as owner of the data directory' % config['uid']) |
0 | 424 |
chown(config.appdatahome, config['uid']) |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
425 |
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
|
426 |
if not self.config.no_db_create: |
9013 | 427 |
helper.postcreate(self.config.automatic, self.config.config_level) |
0 | 428 |
|
1446 | 429 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
430 |
class DeleteInstanceCommand(Command): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
431 |
"""Delete an instance. Will remove instance's files and |
0 | 432 |
unregister it. |
433 |
""" |
|
434 |
name = 'delete' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
435 |
arguments = '<instance>' |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
436 |
min_args = max_args = 1 |
0 | 437 |
options = () |
438 |
||
439 |
def run(self, args): |
|
440 |
"""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
|
441 |
appid = args[0] |
1132 | 442 |
configs = [cwcfg.config_for(appid, configname) |
443 |
for configname in cwcfg.possible_configurations(appid)] |
|
0 | 444 |
if not configs: |
445 |
raise ExecutionError('unable to guess configuration for %s' % appid) |
|
446 |
for config in configs: |
|
447 |
helper = self.config_helper(config, required=False) |
|
448 |
if helper: |
|
449 |
helper.cleanup() |
|
450 |
# remove home |
|
451 |
rm(config.apphome) |
|
452 |
# remove instance data directory |
|
453 |
try: |
|
454 |
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
|
455 |
except OSError as ex: |
0 | 456 |
import errno |
457 |
if ex.errno != errno.ENOENT: |
|
458 |
raise |
|
459 |
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
|
460 |
print('-> instance %s (%s) deleted.' % (appid, confignames)) |
0 | 461 |
|
462 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
463 |
# instance commands ######################################################## |
0 | 464 |
|
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
|
465 |
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
|
466 |
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
|
467 |
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
|
468 |
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
|
469 |
|
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
|
470 |
|
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
471 |
class UpgradeInstanceCommand(InstanceCommandFork): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
472 |
"""Upgrade an instance after cubicweb and/or component(s) upgrade. |
0 | 473 |
|
474 |
For repository update, you will be prompted for a login / password to use |
|
475 |
to connect to the system database. For some upgrades, the given user |
|
476 |
should have create or alter table permissions. |
|
477 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
478 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
479 |
identifiers of the instances to upgrade. If no instance is |
0 | 480 |
given, upgrade them all. |
481 |
""" |
|
482 |
name = 'upgrade' |
|
483 |
actionverb = 'upgraded' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
484 |
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
|
485 |
('force-cube-version', |
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
486 |
{'short': 't', 'type': 'named', 'metavar': 'cube1:X.Y.Z,cube2:X.Y.Z', |
0 | 487 |
'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
|
488 |
'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
|
489 |
|
0 | 490 |
('force-cubicweb-version', |
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
491 |
{'short': 'e', 'type': 'string', 'metavar': 'X.Y.Z', |
0 | 492 |
'default': None, |
493 |
'help': 'force migration from the indicated cubicweb version.'}), |
|
1446 | 494 |
|
0 | 495 |
('fs-only', |
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
496 |
{'short': 's', 'action': 'store_true', |
0 | 497 |
'default': False, |
498 |
'help': 'only upgrade files on the file system, not the database.'}), |
|
499 |
||
12139
b5be819872bb
[cwctl] add a no-config-update option to the upgrade command (closes #17069607)
David Douard <david.douard@logilab.fr>
parents:
12120
diff
changeset
|
500 |
('no-config-update', |
b5be819872bb
[cwctl] add a no-config-update option to the upgrade command (closes #17069607)
David Douard <david.douard@logilab.fr>
parents:
12120
diff
changeset
|
501 |
{'short': 'C', 'action': 'store_true', |
b5be819872bb
[cwctl] add a no-config-update option to the upgrade command (closes #17069607)
David Douard <david.douard@logilab.fr>
parents:
12120
diff
changeset
|
502 |
'default': False, |
b5be819872bb
[cwctl] add a no-config-update option to the upgrade command (closes #17069607)
David Douard <david.douard@logilab.fr>
parents:
12120
diff
changeset
|
503 |
'help': 'do NOT update config file if set.'}), |
b5be819872bb
[cwctl] add a no-config-update option to the upgrade command (closes #17069607)
David Douard <david.douard@logilab.fr>
parents:
12120
diff
changeset
|
504 |
|
0 | 505 |
('verbosity', |
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
506 |
{'short': 'v', 'type': 'int', 'metavar': '<0..2>', |
0 | 507 |
'default': 1, |
508 |
'help': "0: no confirmation, 1: only main commands confirmed, 2 ask \ |
|
509 |
for everything."}), |
|
1446 | 510 |
|
0 | 511 |
('backup-db', |
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
512 |
{'short': 'b', 'type': 'yn', 'metavar': '<y or n>', |
0 | 513 |
'default': None, |
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
514 |
'help': "Backup the instance database before upgrade.\n" |
0 | 515 |
"If the option is ommitted, confirmation will be ask.", |
516 |
}), |
|
517 |
||
518 |
('ext-sources', |
|
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
519 |
{'short': 'E', 'type': 'csv', 'metavar': '<sources>', |
0 | 520 |
'default': None, |
521 |
'help': "For multisources instances, specify to which sources the \ |
|
522 |
repository should connect to for upgrading. When unspecified or 'migration' is \ |
|
523 |
given, appropriate sources for migration will be automatically selected \ |
|
524 |
(recommended). If 'all' is given, will connect to all defined sources.", |
|
525 |
}), |
|
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
526 |
) |
0 | 527 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
528 |
def upgrade_instance(self, appid): |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
529 |
print('\n' + underline_title('Upgrading the instance %s' % appid)) |
0 | 530 |
from logilab.common.changelog import Version |
1132 | 531 |
config = cwcfg.config_for(appid) |
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
532 |
config.repairing = True # notice we're not starting the server |
0 | 533 |
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
|
534 |
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
|
535 |
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
|
536 |
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
|
537 |
# get instance and installed versions for the server and the componants |
0 | 538 |
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
|
539 |
repo = mih.repo |
0 | 540 |
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
|
541 |
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
|
542 |
if self.config.force_cube_version: |
10662
10942ed172de
[py3k] dict.iteritems → dict.items
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10614
diff
changeset
|
543 |
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
|
544 |
vcconf[cube] = Version(version) |
0 | 545 |
toupgrade = [] |
546 |
for cube in config.cubes(): |
|
547 |
installedversion = config.cube_version(cube) |
|
548 |
try: |
|
549 |
applversion = vcconf[cube] |
|
550 |
except KeyError: |
|
551 |
config.error('no version information for %s' % cube) |
|
552 |
continue |
|
553 |
if installedversion > applversion: |
|
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
554 |
toupgrade.append((cube, applversion, installedversion)) |
1446 | 555 |
cubicwebversion = config.cubicweb_version() |
0 | 556 |
if self.config.force_cubicweb_version: |
557 |
applcubicwebversion = Version(self.config.force_cubicweb_version) |
|
558 |
vcconf['cubicweb'] = applcubicwebversion |
|
559 |
else: |
|
560 |
applcubicwebversion = vcconf.get('cubicweb') |
|
561 |
if cubicwebversion > applcubicwebversion: |
|
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2156
diff
changeset
|
562 |
toupgrade.append(('cubicweb', applcubicwebversion, cubicwebversion)) |
0 | 563 |
# 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
|
564 |
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
|
565 |
for cube, fromversion, toversion in toupgrade: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
566 |
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
|
567 |
with mih.cnx: |
9556
12ee310541bb
[server/migractions] finish migration to repoapi objects
Julien Cristau <julien.cristau@logilab.fr>
parents:
9511
diff
changeset
|
568 |
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
|
569 |
mih.migrate(vcconf, reversed(toupgrade), self.config) |
11878
e42cb31e9301
[cwctl] on upgrade, clear instance_md5_version cache
Julien Cristau <julien.cristau@logilab.fr>
parents:
11870
diff
changeset
|
570 |
clear_cache(config, 'instance_md5_version') |
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
|
571 |
else: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
572 |
print('-> no data migration needed for instance %s.' % appid) |
0 | 573 |
# rewrite main configuration file |
12139
b5be819872bb
[cwctl] add a no-config-update option to the upgrade command (closes #17069607)
David Douard <david.douard@logilab.fr>
parents:
12120
diff
changeset
|
574 |
if not self.config.no_config_update: |
b5be819872bb
[cwctl] add a no-config-update option to the upgrade command (closes #17069607)
David Douard <david.douard@logilab.fr>
parents:
12120
diff
changeset
|
575 |
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
|
576 |
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
|
577 |
# 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
|
578 |
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
|
579 |
return |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
580 |
print() |
9372
e87a808a4c32
[webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents:
9371
diff
changeset
|
581 |
if helper: |
e87a808a4c32
[webctl] Generate static data directory on upgrade (closes #2167873)
Julien Cristau <julien.cristau@logilab.fr>
parents:
9371
diff
changeset
|
582 |
helper.postupgrade(repo) |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
583 |
print('-> instance migrated.') |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
584 |
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
|
585 |
|
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
|
586 |
def i18nupgrade(self, config): |
0 | 587 |
# handle i18n upgrade: |
588 |
# * install new languages |
|
589 |
# * 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
|
590 |
# 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
|
591 |
from cubicweb import i18n |
1132 | 592 |
templdir = cwcfg.cube_dir(config.cubes()[0]) |
0 | 593 |
langs = [lang for lang, _ in i18n.available_catalogs(join(templdir, 'i18n'))] |
594 |
errors = config.i18ncompile(langs) |
|
595 |
if errors: |
|
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
596 |
print('\n'.join(errors)) |
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
597 |
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
|
598 |
'continue anyway?'): |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
599 |
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
|
600 |
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
|
601 |
return True |
0 | 602 |
|
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
|
603 |
|
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
|
604 |
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
|
605 |
"""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
|
606 |
|
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
|
607 |
<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
|
608 |
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
|
609 |
""" |
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
|
610 |
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
|
611 |
|
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
|
612 |
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
|
613 |
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
|
614 |
# 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
|
615 |
config.repairing = True |
9875
d4f6f4c77e9c
[cwctl] make cubicweb-ctl versions lighter (closes #4002158)
Julien Cristau <julien.cristau@logilab.fr>
parents:
9770
diff
changeset
|
616 |
# 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
|
617 |
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
|
618 |
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
|
619 |
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
|
620 |
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
|
621 |
for key in sorted(vcconf): |
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
622 |
print(key + ': %s.%s.%s' % vcconf[key]) |
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
623 |
|
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
|
624 |
|
0 | 625 |
class ShellCommand(Command): |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
626 |
"""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
|
627 |
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
|
628 |
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
|
629 |
in batch mode. |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
630 |
|
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
631 |
By default it will connect to a local instance using an in memory |
9700 | 632 |
connection, unless a URL to a running instance is specified. |
0 | 633 |
|
5430
ed8f71e244f8
[shell] #715938: support of script parameters (using standard '--' as arguments separator)
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
5426
diff
changeset
|
634 |
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
|
635 |
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
|
636 |
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
|
637 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
638 |
<instance> |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
639 |
the identifier of the instance to connect. |
0 | 640 |
""" |
641 |
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
|
642 |
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
|
643 |
min_args = 1 |
0 | 644 |
options = ( |
645 |
('system-only', |
|
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
646 |
{'short': 'S', 'action': 'store_true', |
0 | 647 |
'help': 'only connect to the system source when the instance is ' |
648 |
'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
|
649 |
'--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
|
650 |
'group': 'local' |
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
651 |
}), |
1446 | 652 |
|
0 | 653 |
('ext-sources', |
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
654 |
{'short': 'E', 'type': 'csv', 'metavar': '<sources>', |
0 | 655 |
'help': "For multisources instances, specify to which sources the \ |
656 |
repository should connect to for upgrading. When unspecified or 'all' given, \ |
|
657 |
will connect to all defined sources. If 'migration' is given, appropriate \ |
|
658 |
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
|
659 |
'group': 'local' |
0 | 660 |
}), |
1446 | 661 |
|
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
|
662 |
('force', |
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
663 |
{'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
|
664 |
'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
|
665 |
'group': 'local' |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
666 |
}), |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
667 |
|
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
668 |
) |
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
|
669 |
|
11189
3a39f145d530
[cwctl] remove networked remote shell
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
11129
diff
changeset
|
670 |
def _get_mih(self, appid): |
8682
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
671 |
""" 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
|
672 |
config = cwcfg.config_for(appid) |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
673 |
if self.config.ext_sources: |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
674 |
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
|
675 |
sources = self.config.ext_sources |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
676 |
elif self.config.system_only: |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
677 |
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
|
678 |
else: |
8682
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
679 |
sources = ('all',) |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
680 |
config.set_sources_mode(sources) |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
681 |
config.repairing = self.config.force |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
682 |
mih = config.migration_handler() |
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
683 |
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
|
684 |
|
0 | 685 |
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
|
686 |
appuri = args.pop(0) |
11189
3a39f145d530
[cwctl] remove networked remote shell
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
11129
diff
changeset
|
687 |
mih, shutdown_callback = self._get_mih(appuri) |
3709
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
688 |
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
|
689 |
with mih.cnx: |
9556
12ee310541bb
[server/migractions] finish migration to repoapi objects
Julien Cristau <julien.cristau@logilab.fr>
parents:
9511
diff
changeset
|
690 |
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
|
691 |
if args: |
12ee310541bb
[server/migractions] finish migration to repoapi objects
Julien Cristau <julien.cristau@logilab.fr>
parents:
9511
diff
changeset
|
692 |
# 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
|
693 |
# 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
|
694 |
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
|
695 |
for script in scripts: |
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
696 |
mih.cmd_process_script(script, scriptargs=args) |
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
697 |
mih.commit() |
9556
12ee310541bb
[server/migractions] finish migration to repoapi objects
Julien Cristau <julien.cristau@logilab.fr>
parents:
9511
diff
changeset
|
698 |
else: |
12ee310541bb
[server/migractions] finish migration to repoapi objects
Julien Cristau <julien.cristau@logilab.fr>
parents:
9511
diff
changeset
|
699 |
mih.interactive_shell() |
3709
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
700 |
finally: |
8682
20bd1cdf86ae
[cwctl] fix cubicweb-ctl shell command (closes #2583919)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
8669
diff
changeset
|
701 |
shutdown_callback() |
0 | 702 |
|
703 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
704 |
class RecompileInstanceCatalogsCommand(InstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
705 |
"""Recompile i18n catalogs for instances. |
1446 | 706 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
707 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
708 |
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
|
709 |
given, recompile for all registered instances. |
0 | 710 |
""" |
1898
39b37f90a8a4
[cw-ctl] rename i18n commands (see #342889)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1477
diff
changeset
|
711 |
name = 'i18ninstance' |
1132 | 712 |
|
713 |
@staticmethod |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
714 |
def i18ninstance_instance(appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
715 |
"""recompile instance's messages catalogs""" |
1132 | 716 |
config = cwcfg.config_for(appid) |
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
717 |
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
|
718 |
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
|
719 |
if config._cubes is None: |
0 | 720 |
# 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
|
721 |
config.init_cubes(repo.get_cubes()) |
0 | 722 |
errors = config.i18ncompile() |
723 |
if errors: |
|
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
724 |
print('\n'.join(errors)) |
0 | 725 |
|
726 |
||
727 |
class ListInstancesCommand(Command): |
|
728 |
"""list available instances, useful for bash completion.""" |
|
729 |
name = 'listinstances' |
|
730 |
hidden = True |
|
1446 | 731 |
|
0 | 732 |
def run(self, args): |
733 |
"""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
|
734 |
regdir = cwcfg.instances_dir() |
0 | 735 |
for appid in sorted(listdir(regdir)): |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
736 |
print(appid) |
0 | 737 |
|
738 |
||
739 |
class ListCubesCommand(Command): |
|
740 |
"""list available componants, useful for bash completion.""" |
|
741 |
name = 'listcubes' |
|
742 |
hidden = True |
|
1446 | 743 |
|
0 | 744 |
def run(self, args): |
745 |
"""run the command with its specific arguments""" |
|
1132 | 746 |
for cube in cwcfg.available_cubes(): |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
747 |
print(cube) |
0 | 748 |
|
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
749 |
|
9002
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
750 |
class ConfigureInstanceCommand(InstanceCommand): |
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
751 |
"""Configure instance. |
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
752 |
|
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
753 |
<instance>... |
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
754 |
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
|
755 |
""" |
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
756 |
name = 'configure' |
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
757 |
actionverb = 'configured' |
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
758 |
|
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
759 |
options = merge_options( |
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
760 |
InstanceCommand.options + ( |
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
761 |
('param', |
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
762 |
{'short': 'p', 'type': 'named', 'metavar': 'key1:value1,key2:value2', |
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
763 |
'default': None, |
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
764 |
'help': 'set <key> to <value> in configuration file.'}), |
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
765 |
), |
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
766 |
) |
9002
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
767 |
|
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
768 |
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
|
769 |
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
|
770 |
appcfg = cwcfg.config_for(appid) |
10662
10942ed172de
[py3k] dict.iteritems → dict.items
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10614
diff
changeset
|
771 |
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
|
772 |
try: |
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
773 |
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
|
774 |
except KeyError: |
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
775 |
raise ConfigurationError( |
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
776 |
'unknown configuration key "%s" for mode %s' % (key, appcfg.name)) |
9002
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
777 |
appcfg.save() |
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
778 |
|
9287
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
9255
diff
changeset
|
779 |
|
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
9255
diff
changeset
|
780 |
# WSGI ######### |
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
9255
diff
changeset
|
781 |
|
10104
cdc0b0216da2
[cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents:
9990
diff
changeset
|
782 |
WSGI_CHOICES = {} |
11243
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
783 |
try: |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
784 |
from cubicweb.wsgi import server as stdlib_server |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
785 |
except ImportError: |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
786 |
pass |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
787 |
else: |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
788 |
WSGI_CHOICES['stdlib'] = stdlib_server |
10104
cdc0b0216da2
[cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents:
9990
diff
changeset
|
789 |
try: |
cdc0b0216da2
[cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents:
9990
diff
changeset
|
790 |
from cubicweb.wsgi import wz |
cdc0b0216da2
[cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents:
9990
diff
changeset
|
791 |
except ImportError: |
cdc0b0216da2
[cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents:
9990
diff
changeset
|
792 |
pass |
cdc0b0216da2
[cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents:
9990
diff
changeset
|
793 |
else: |
cdc0b0216da2
[cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents:
9990
diff
changeset
|
794 |
WSGI_CHOICES['werkzeug'] = wz |
10106
3117f1736f00
[wsgi] add tornado http server
Alain Leufroy <alain@leufroy.fr>
parents:
10104
diff
changeset
|
795 |
try: |
3117f1736f00
[wsgi] add tornado http server
Alain Leufroy <alain@leufroy.fr>
parents:
10104
diff
changeset
|
796 |
from cubicweb.wsgi import tnd |
3117f1736f00
[wsgi] add tornado http server
Alain Leufroy <alain@leufroy.fr>
parents:
10104
diff
changeset
|
797 |
except ImportError: |
3117f1736f00
[wsgi] add tornado http server
Alain Leufroy <alain@leufroy.fr>
parents:
10104
diff
changeset
|
798 |
pass |
3117f1736f00
[wsgi] add tornado http server
Alain Leufroy <alain@leufroy.fr>
parents:
10104
diff
changeset
|
799 |
else: |
3117f1736f00
[wsgi] add tornado http server
Alain Leufroy <alain@leufroy.fr>
parents:
10104
diff
changeset
|
800 |
WSGI_CHOICES['tornado'] = tnd |
10104
cdc0b0216da2
[cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents:
9990
diff
changeset
|
801 |
|
cdc0b0216da2
[cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents:
9990
diff
changeset
|
802 |
|
9288
823cf14bcc37
[wsgi] also provide an example using werkzeug (if available)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9287
diff
changeset
|
803 |
def wsgichoices(): |
10104
cdc0b0216da2
[cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents:
9990
diff
changeset
|
804 |
return tuple(WSGI_CHOICES) |
cdc0b0216da2
[cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents:
9990
diff
changeset
|
805 |
|
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
806 |
|
11243
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
807 |
if WSGI_CHOICES: |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
808 |
class WSGIStartHandler(InstanceCommand): |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
809 |
"""Start an interactive wsgi server """ |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
810 |
name = 'wsgi' |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
811 |
actionverb = 'started' |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
812 |
arguments = '<instance>' |
10104
cdc0b0216da2
[cwctl] rewrite wsgi method choices
Alain Leufroy <alain@leufroy.fr>
parents:
9990
diff
changeset
|
813 |
|
11243
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
814 |
@property |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
815 |
def options(self): |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
816 |
return ( |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
817 |
("debug", |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
818 |
{'short': 'D', 'action': 'store_true', |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
819 |
'default': False, |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
820 |
'help': 'start server in debug mode.'}), |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
821 |
('method', |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
822 |
{'short': 'm', |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
823 |
'type': 'choice', |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
824 |
'metavar': '<method>', |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
825 |
'default': 'stdlib', |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
826 |
'choices': wsgichoices(), |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
827 |
'help': 'wsgi utility/method'}), |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
828 |
('loglevel', |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
829 |
{'short': 'l', |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
830 |
'type': 'choice', |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
831 |
'metavar': '<log level>', |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
832 |
'default': None, |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
833 |
'choices': ('debug', 'info', 'warning', 'error'), |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
834 |
'help': 'debug if -D is set, error otherwise', |
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
835 |
}), |
11243
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
836 |
) |
9287
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
9255
diff
changeset
|
837 |
|
11243
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
838 |
def wsgi_instance(self, appid): |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
839 |
config = cwcfg.config_for(appid, debugmode=self['debug']) |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
840 |
init_cmdline_log_threshold(config, self['loglevel']) |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
841 |
assert config.name == 'all-in-one' |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
842 |
meth = self['method'] |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
843 |
server = WSGI_CHOICES[meth] |
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
844 |
return server.run(config) |
9287
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
9255
diff
changeset
|
845 |
|
11243
6706c46e24ae
[cwctl] make cwctl not depends on cubicweb.wsgi (closes #12210063)
David Douard <david.douard@logilab.fr>
parents:
11104
diff
changeset
|
846 |
CWCTL.register(WSGIStartHandler) |
9287
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
9255
diff
changeset
|
847 |
|
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
9255
diff
changeset
|
848 |
|
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
849 |
for cmdcls in (ListCommand, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
850 |
CreateInstanceCommand, DeleteInstanceCommand, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
851 |
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
|
852 |
ListVersionsInstanceCommand, |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
853 |
ShellCommand, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
854 |
RecompileInstanceCatalogsCommand, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
855 |
ListInstancesCommand, ListCubesCommand, |
9002
f98d1c46ed9f
[cwctl] add configure command to cw-ctl (closes #2709702)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
9001
diff
changeset
|
856 |
ConfigureInstanceCommand, |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
857 |
): |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
858 |
CWCTL.register(cmdcls) |
0 | 859 |
|
9287
e70c8c70e344
[wsgi] add the simplest possible wsgi (debug) server
Aurelien Campeas
parents:
9255
diff
changeset
|
860 |
|
12253
9165f4b7426b
Set a default value for arguments of cubicweb.cwctl:run()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12139
diff
changeset
|
861 |
def run(args=sys.argv[1:]): |
0 | 862 |
"""command line tool""" |
10321
a4af502191d5
[cwctl] don't filter DeprecationWarnings
Julien Cristau <julien.cristau@logilab.fr>
parents:
10235
diff
changeset
|
863 |
filterwarnings('default', category=DeprecationWarning) |
1132 | 864 |
cwcfg.load_cwctl_plugins() |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
865 |
try: |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
866 |
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
|
867 |
except ConfigurationError as err: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
868 |
print('ERROR: ', err) |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
869 |
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
|
870 |
except ExecutionError as err: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10569
diff
changeset
|
871 |
print(err) |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5814
diff
changeset
|
872 |
sys.exit(2) |
0 | 873 |
|
12525
234079d86496
Flake8 cubicweb/cwctl.py
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12524
diff
changeset
|
874 |
|
0 | 875 |
if __name__ == '__main__': |
12253
9165f4b7426b
Set a default value for arguments of cubicweb.cwctl:run()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
12139
diff
changeset
|
876 |
run() |