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