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