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