author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 15 Apr 2010 17:57:41 +0200 | |
branch | stable |
changeset 5292 | 8b496574b65c |
parent 5288 | 92e9efc8cad5 |
child 5302 | dfd147de06b2 |
child 5421 | 8167de96c523 |
permissions | -rw-r--r-- |
4720
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
1 |
"""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
|
2 |
provide a pluggable commands system. |
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
3 |
|
0 | 4 |
|
4720
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
5 |
:organization: Logilab |
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
6 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
7 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
8 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
9 |
""" |
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
10 |
__docformat__ = "restructuredtext en" |
0 | 11 |
|
4718
3dc3ad02d091
avoid module import in c-c plugins module, and remind it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4684
diff
changeset
|
12 |
# *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
|
13 |
# 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
|
14 |
# completion). So import locally in command helpers. |
0 | 15 |
import sys |
3115
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
2905
diff
changeset
|
16 |
from os import remove, listdir, system, pathsep |
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
2905
diff
changeset
|
17 |
try: |
3562 | 18 |
from os import kill, getpgid |
3115
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
2905
diff
changeset
|
19 |
except ImportError: |
4721
8f63691ccb7f
pylint style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4720
diff
changeset
|
20 |
def kill(*args): |
8f63691ccb7f
pylint style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4720
diff
changeset
|
21 |
"""win32 kill implementation""" |
8f63691ccb7f
pylint style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4720
diff
changeset
|
22 |
def getpgid(): |
8f63691ccb7f
pylint style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4720
diff
changeset
|
23 |
"""win32 getpgid implementation""" |
3115
29262ba01464
minimal steps to have cw running on windows
Aurélien Campéas
parents:
2905
diff
changeset
|
24 |
|
4064
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
25 |
from os.path import exists, join, isfile, isdir, dirname, abspath |
0 | 26 |
|
1132 | 27 |
from logilab.common.clcommands import register_commands, pop_arg |
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
|
28 |
from logilab.common.shellutils import ASK |
1132 | 29 |
|
2790
968108e16066
move underline_title to toolsutils
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2743
diff
changeset
|
30 |
from cubicweb import ConfigurationError, ExecutionError, BadCommandUsage |
3638
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3619
diff
changeset
|
31 |
from cubicweb.cwconfig import CubicWebConfiguration as cwcfg, CWDEV, CONFIGURATIONS |
2790
968108e16066
move underline_title to toolsutils
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2743
diff
changeset
|
32 |
from cubicweb.toolsutils import Command, main_run, rm, create_dir, underline_title |
1446 | 33 |
|
0 | 34 |
def wait_process_end(pid, maxtry=10, waittime=1): |
35 |
"""wait for a process to actually die""" |
|
36 |
import signal |
|
37 |
from time import sleep |
|
38 |
nbtry = 0 |
|
39 |
while nbtry < maxtry: |
|
40 |
try: |
|
41 |
kill(pid, signal.SIGUSR1) |
|
3117
32686ae66c75
mostly adapt the i18n subsystem to limitation wrt redirection handinling in windows, using the -o argument of the utilities
Aurélien Campéas
parents:
3115
diff
changeset
|
42 |
except (OSError, AttributeError): # XXX win32 |
0 | 43 |
break |
44 |
nbtry += 1 |
|
45 |
sleep(waittime) |
|
46 |
else: |
|
47 |
raise ExecutionError('can\'t kill process %s' % pid) |
|
48 |
||
49 |
def list_instances(regdir): |
|
50 |
return sorted(idir for idir in listdir(regdir) if isdir(join(regdir, idir))) |
|
51 |
||
52 |
def detect_available_modes(templdir): |
|
53 |
modes = [] |
|
54 |
for fname in ('schema', 'schema.py'): |
|
55 |
if exists(join(templdir, fname)): |
|
56 |
modes.append('repository') |
|
57 |
break |
|
58 |
for fname in ('data', 'views', 'views.py'): |
|
59 |
if exists(join(templdir, fname)): |
|
60 |
modes.append('web ui') |
|
61 |
break |
|
62 |
return modes |
|
1446 | 63 |
|
64 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
65 |
class InstanceCommand(Command): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
66 |
"""base class for command taking 0 to n instance id as arguments |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
67 |
(0 meaning all registered instances) |
0 | 68 |
""" |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
69 |
arguments = '[<instance>...]' |
0 | 70 |
options = ( |
71 |
("force", |
|
72 |
{'short': 'f', 'action' : 'store_true', |
|
73 |
'default': False, |
|
74 |
'help': 'force command without asking confirmation', |
|
75 |
} |
|
76 |
), |
|
77 |
) |
|
78 |
actionverb = None |
|
1446 | 79 |
|
0 | 80 |
def ordered_instances(self): |
81 |
"""return instances in the order in which they should be started, |
|
82 |
considering $REGISTRY_DIR/startorder file if it exists (useful when |
|
3619
af81a4f7053e
enhance docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3562
diff
changeset
|
83 |
some instances depends on another as external source). |
af81a4f7053e
enhance docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3562
diff
changeset
|
84 |
|
af81a4f7053e
enhance docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3562
diff
changeset
|
85 |
Instance used by another one should appears first in the file (one |
af81a4f7053e
enhance docstring
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3562
diff
changeset
|
86 |
instance per line) |
0 | 87 |
""" |
1132 | 88 |
regdir = cwcfg.registry_dir() |
0 | 89 |
_allinstances = list_instances(regdir) |
90 |
if isfile(join(regdir, 'startorder')): |
|
91 |
allinstances = [] |
|
92 |
for line in file(join(regdir, 'startorder')): |
|
93 |
line = line.strip() |
|
94 |
if line and not line.startswith('#'): |
|
95 |
try: |
|
96 |
_allinstances.remove(line) |
|
97 |
allinstances.append(line) |
|
98 |
except ValueError: |
|
1132 | 99 |
print ('ERROR: startorder file contains unexistant ' |
100 |
'instance %s' % line) |
|
0 | 101 |
allinstances += _allinstances |
102 |
else: |
|
103 |
allinstances = _allinstances |
|
104 |
return allinstances |
|
1446 | 105 |
|
0 | 106 |
def run(self, args): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
107 |
"""run the <command>_method on each argument (a list of instance |
0 | 108 |
identifiers) |
109 |
""" |
|
110 |
if not args: |
|
111 |
args = self.ordered_instances() |
|
112 |
try: |
|
113 |
askconfirm = not self.config.force |
|
114 |
except AttributeError: |
|
115 |
# no force option |
|
116 |
askconfirm = False |
|
117 |
else: |
|
118 |
askconfirm = False |
|
119 |
self.run_args(args, askconfirm) |
|
1446 | 120 |
|
0 | 121 |
def run_args(self, args, askconfirm): |
122 |
for appid in args: |
|
123 |
if askconfirm: |
|
124 |
print '*'*72 |
|
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
125 |
if not ASK.confirm('%s instance %r ?' % (self.name, appid)): |
0 | 126 |
continue |
127 |
self.run_arg(appid) |
|
1446 | 128 |
|
0 | 129 |
def run_arg(self, appid): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
130 |
cmdmeth = getattr(self, '%s_instance' % self.name) |
0 | 131 |
try: |
132 |
cmdmeth(appid) |
|
133 |
except (KeyboardInterrupt, SystemExit): |
|
134 |
print >> sys.stderr, '%s aborted' % self.name |
|
135 |
sys.exit(2) # specific error code |
|
136 |
except (ExecutionError, ConfigurationError), ex: |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
137 |
print >> sys.stderr, 'instance %s not %s: %s' % ( |
0 | 138 |
appid, self.actionverb, ex) |
139 |
except Exception, ex: |
|
140 |
import traceback |
|
141 |
traceback.print_exc() |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
142 |
print >> sys.stderr, 'instance %s not %s: %s' % ( |
0 | 143 |
appid, self.actionverb, ex) |
144 |
||
145 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
146 |
class InstanceCommandFork(InstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
147 |
"""Same as `InstanceCommand`, but command is forked in a new environment |
0 | 148 |
for each argument |
149 |
""" |
|
150 |
||
151 |
def run_args(self, args, askconfirm): |
|
152 |
if len(args) > 1: |
|
153 |
forkcmd = ' '.join(w for w in sys.argv if not w in args) |
|
154 |
else: |
|
155 |
forkcmd = None |
|
156 |
for appid in args: |
|
157 |
if askconfirm: |
|
158 |
print '*'*72 |
|
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
159 |
if not ASK.confirm('%s instance %r ?' % (self.name, appid)): |
0 | 160 |
continue |
161 |
if forkcmd: |
|
162 |
status = system('%s %s' % (forkcmd, appid)) |
|
163 |
if status: |
|
2156
fadb86b040a9
continue to run command on other instances, do not exit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2104
diff
changeset
|
164 |
print '%s exited with status %s' % (forkcmd, status) |
0 | 165 |
else: |
166 |
self.run_arg(appid) |
|
1446 | 167 |
|
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
168 |
|
0 | 169 |
# base commands ############################################################### |
170 |
||
4721
8f63691ccb7f
pylint style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4720
diff
changeset
|
171 |
def version_strictly_lower(a, b): |
4684
876a79ece6f7
[cwctl] use l.c.changelog for version comparison
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4656
diff
changeset
|
172 |
from logilab.common.changelog import Version |
4656
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
173 |
if a: |
4684
876a79ece6f7
[cwctl] use l.c.changelog for version comparison
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4656
diff
changeset
|
174 |
a = Version(a) |
4656
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
175 |
if b: |
4684
876a79ece6f7
[cwctl] use l.c.changelog for version comparison
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4656
diff
changeset
|
176 |
b = Version(b) |
4656
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
177 |
return a < b |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
178 |
|
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
179 |
def max_version(a, b): |
4684
876a79ece6f7
[cwctl] use l.c.changelog for version comparison
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4656
diff
changeset
|
180 |
from logilab.common.changelog import Version |
876a79ece6f7
[cwctl] use l.c.changelog for version comparison
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4656
diff
changeset
|
181 |
return str(max(Version(a), Version(b))) |
4656
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
182 |
|
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
183 |
class ConfigurationProblem(object): |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
184 |
"""Each cube has its own list of dependencies on other cubes/versions. |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
185 |
|
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
186 |
The ConfigurationProblem is used to record the loaded cubes, then to detect |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
187 |
inconsistencies in their dependencies. |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
188 |
|
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
189 |
See configuration management on wikipedia for litterature. |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
190 |
""" |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
191 |
|
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
192 |
def __init__(self): |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
193 |
self.cubes = {} |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
194 |
|
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
195 |
def add_cube(self, name, info): |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
196 |
self.cubes[name] = info |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
197 |
|
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
198 |
def solve(self): |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
199 |
self.warnings = [] |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
200 |
self.errors = [] |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
201 |
self.read_constraints() |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
202 |
for cube, versions in sorted(self.constraints.items()): |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
203 |
oper, version = None, None |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
204 |
# simplify constraints |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
205 |
if versions: |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
206 |
for constraint in versions: |
4798
d5bd706e9005
[cwctl] list will warn about a badly formatted version constraint instead of crashing
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4721
diff
changeset
|
207 |
op, ver = constraint |
4656
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
208 |
if oper is None: |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
209 |
oper = op |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
210 |
version = ver |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
211 |
elif op == '>=' and oper == '>=': |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
212 |
version = max_version(ver, version) |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
213 |
else: |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
214 |
print 'unable to handle this case', oper, version, op, ver |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
215 |
# "solve" constraint satisfaction problem |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
216 |
if cube not in self.cubes: |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
217 |
self.errors.append( ('add', cube, version) ) |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
218 |
elif versions: |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
219 |
lower_strict = version_strictly_lower(self.cubes[cube].version, version) |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
220 |
if oper in ('>=','='): |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
221 |
if lower_strict: |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
222 |
self.errors.append( ('update', cube, version) ) |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
223 |
else: |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
224 |
print 'unknown operator', oper |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
225 |
|
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
226 |
def read_constraints(self): |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
227 |
self.constraints = {} |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
228 |
self.reverse_constraints = {} |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
229 |
for cube, info in self.cubes.items(): |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
230 |
if hasattr(info,'__depends_cubes__'): |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
231 |
use = info.__depends_cubes__ |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
232 |
if not isinstance(use, dict): |
4721
8f63691ccb7f
pylint style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4720
diff
changeset
|
233 |
use = dict((key, None) for key in use) |
4656
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
234 |
self.warnings.append('cube %s should define __depends_cubes__ as a dict not a list') |
5288
92e9efc8cad5
don't fail on cube's pkginfo without __use__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5092
diff
changeset
|
235 |
elif hasattr(info, '__use__'): |
4656
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
236 |
self.warnings.append('cube %s should define __depends_cubes__' % cube) |
4721
8f63691ccb7f
pylint style fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4720
diff
changeset
|
237 |
use = dict((key, None) for key in info.__use__) |
5288
92e9efc8cad5
don't fail on cube's pkginfo without __use__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5092
diff
changeset
|
238 |
else: |
92e9efc8cad5
don't fail on cube's pkginfo without __use__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5092
diff
changeset
|
239 |
continue |
4656
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
240 |
for name, constraint in use.items(): |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
241 |
self.constraints.setdefault(name,set()) |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
242 |
if constraint: |
4798
d5bd706e9005
[cwctl] list will warn about a badly formatted version constraint instead of crashing
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4721
diff
changeset
|
243 |
try: |
d5bd706e9005
[cwctl] list will warn about a badly formatted version constraint instead of crashing
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4721
diff
changeset
|
244 |
oper, version = constraint.split() |
d5bd706e9005
[cwctl] list will warn about a badly formatted version constraint instead of crashing
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4721
diff
changeset
|
245 |
self.constraints[name].add( (oper, version) ) |
d5bd706e9005
[cwctl] list will warn about a badly formatted version constraint instead of crashing
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4721
diff
changeset
|
246 |
except: |
d5bd706e9005
[cwctl] list will warn about a badly formatted version constraint instead of crashing
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4721
diff
changeset
|
247 |
self.warnings.append('cube %s depends on %s but constraint badly formatted: %s' |
d5bd706e9005
[cwctl] list will warn about a badly formatted version constraint instead of crashing
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4721
diff
changeset
|
248 |
% (cube, name, constraint)) |
4656
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
249 |
self.reverse_constraints.setdefault(name, set()).add(cube) |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
250 |
|
0 | 251 |
class ListCommand(Command): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
252 |
"""List configurations, cubes and instances. |
0 | 253 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
254 |
list available configurations, installed cubes, and registered instances |
0 | 255 |
""" |
256 |
name = 'list' |
|
257 |
options = ( |
|
258 |
('verbose', |
|
1446 | 259 |
{'short': 'v', 'action' : 'store_true', |
260 |
'help': "display more information."}), |
|
0 | 261 |
) |
1446 | 262 |
|
0 | 263 |
def run(self, args): |
264 |
"""run the command with its specific arguments""" |
|
265 |
if args: |
|
266 |
raise BadCommandUsage('Too much arguments') |
|
3486
ea6bf6f9ba0c
[cwctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3198
diff
changeset
|
267 |
print 'CubicWeb %s (%s mode)' % (cwcfg.cubicweb_version(), cwcfg.mode) |
0 | 268 |
print |
269 |
print 'Available configurations:' |
|
270 |
for config in CONFIGURATIONS: |
|
271 |
print '*', config.name |
|
272 |
for line in config.__doc__.splitlines(): |
|
273 |
line = line.strip() |
|
274 |
if not line: |
|
275 |
continue |
|
276 |
print ' ', line |
|
1446 | 277 |
print |
4656
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
278 |
cfgpb = ConfigurationProblem() |
0 | 279 |
try: |
1342
4273e44852cb
no more cubes_dir class method
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
280 |
cubesdir = pathsep.join(cwcfg.cubes_search_path()) |
1132 | 281 |
namesize = max(len(x) for x in cwcfg.available_cubes()) |
0 | 282 |
except ConfigurationError, ex: |
283 |
print 'No cubes available:', ex |
|
284 |
except ValueError: |
|
285 |
print 'No cubes available in %s' % cubesdir |
|
286 |
else: |
|
287 |
print 'Available cubes (%s):' % cubesdir |
|
1132 | 288 |
for cube in cwcfg.available_cubes(): |
0 | 289 |
if cube in ('CVS', '.svn', 'shared', '.hg'): |
290 |
continue |
|
291 |
try: |
|
1132 | 292 |
tinfo = cwcfg.cube_pkginfo(cube) |
0 | 293 |
tversion = tinfo.version |
4656
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
294 |
cfgpb.add_cube(cube, tinfo) |
0 | 295 |
except ConfigurationError: |
296 |
tinfo = None |
|
297 |
tversion = '[missing cube information]' |
|
298 |
print '* %s %s' % (cube.ljust(namesize), tversion) |
|
299 |
if self.config.verbose: |
|
300 |
shortdesc = tinfo and (getattr(tinfo, 'short_desc', '') |
|
301 |
or tinfo.__doc__) |
|
302 |
if shortdesc: |
|
303 |
print ' '+ ' \n'.join(shortdesc.splitlines()) |
|
2024
82128fe6798c
redo juj's fix in stable branch
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1898
diff
changeset
|
304 |
modes = detect_available_modes(cwcfg.cube_dir(cube)) |
0 | 305 |
print ' available modes: %s' % ', '.join(modes) |
306 |
print |
|
307 |
try: |
|
1132 | 308 |
regdir = cwcfg.registry_dir() |
0 | 309 |
except ConfigurationError, ex: |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
310 |
print 'No instance available:', ex |
0 | 311 |
print |
312 |
return |
|
313 |
instances = list_instances(regdir) |
|
314 |
if instances: |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
315 |
print 'Available instances (%s):' % regdir |
0 | 316 |
for appid in instances: |
1132 | 317 |
modes = cwcfg.possible_configurations(appid) |
0 | 318 |
if not modes: |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
319 |
print '* %s (BROKEN instance, no configuration found)' % appid |
0 | 320 |
continue |
321 |
print '* %s (%s)' % (appid, ', '.join(modes)) |
|
322 |
try: |
|
1132 | 323 |
config = cwcfg.config_for(appid, modes[0]) |
1446 | 324 |
except Exception, exc: |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
325 |
print ' (BROKEN instance, %s)' % exc |
0 | 326 |
continue |
327 |
else: |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
328 |
print 'No instance available in %s' % regdir |
0 | 329 |
print |
4656
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
330 |
# configuration management problem solving |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
331 |
cfgpb.solve() |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
332 |
if cfgpb.warnings: |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
333 |
print 'Warnings:\n', '\n'.join('* '+txt for txt in cfgpb.warnings) |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
334 |
if cfgpb.errors: |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
335 |
print 'Errors:' |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
336 |
for op, cube, version in cfgpb.errors: |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
337 |
if op == 'add': |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
338 |
print '* cube', cube, |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
339 |
if version: |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
340 |
print ' version', version, |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
341 |
print 'is not installed, but required by %s' % ' '.join(cfgpb.reverse_constraints[cube]) |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
342 |
else: |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
343 |
print '* cube %s version %s is installed, but version %s is required by (%s)' % ( |
027bbff3659f
[cwctl] modify command list to check for cube dependency problems
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
4610
diff
changeset
|
344 |
cube, cfgpb.cubes[cube].version, version, ', '.join(cfgpb.reverse_constraints[cube])) |
0 | 345 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
346 |
class CreateInstanceCommand(Command): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
347 |
"""Create an instance from a cube. This is an unified |
0 | 348 |
command which can handle web / server / all-in-one installation |
349 |
according to available parts of the software library and of the |
|
350 |
desired cube. |
|
351 |
||
352 |
<cube> |
|
353 |
the name of cube to use (list available cube names using |
|
354 |
the "list" command). You can use several cubes by separating |
|
355 |
them using comma (e.g. 'jpl,eemail') |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
356 |
<instance> |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
357 |
an identifier for the instance to create |
0 | 358 |
""" |
359 |
name = 'create' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
360 |
arguments = '<cube> <instance>' |
0 | 361 |
options = ( |
362 |
("config-level", |
|
363 |
{'short': 'l', 'type' : 'int', 'metavar': '<level>', |
|
364 |
'default': 0, |
|
365 |
'help': 'configuration level (0..2): 0 will ask for essential \ |
|
366 |
configuration parameters only while 2 will ask for all parameters', |
|
367 |
} |
|
368 |
), |
|
369 |
("config", |
|
370 |
{'short': 'c', 'type' : 'choice', 'metavar': '<install type>', |
|
371 |
'choices': ('all-in-one', 'repository', 'twisted'), |
|
372 |
'default': 'all-in-one', |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
373 |
'help': 'installation type, telling which part of an instance \ |
0 | 374 |
should be installed. You can list available configurations using the "list" \ |
375 |
command. Default to "all-in-one", e.g. an installation embedding both the RQL \ |
|
376 |
repository and the web server.', |
|
377 |
} |
|
378 |
), |
|
379 |
) |
|
1446 | 380 |
|
0 | 381 |
def run(self, args): |
382 |
"""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
|
383 |
from logilab.common.textutils import splitstrip |
0 | 384 |
configname = self.config.config |
2633
bc9386c3b2c9
get_csv is being renamed to splitstrip
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2615
diff
changeset
|
385 |
cubes = splitstrip(pop_arg(args, 1)) |
0 | 386 |
appid = pop_arg(args) |
387 |
# get the configuration and helper |
|
1132 | 388 |
config = cwcfg.config_for(appid, configname) |
0 | 389 |
config.set_language = False |
2104
b4ffcea3275b
change cubes into expanded cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2032
diff
changeset
|
390 |
cubes = config.expand_cubes(cubes) |
b4ffcea3275b
change cubes into expanded cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2032
diff
changeset
|
391 |
config.init_cubes(cubes) |
0 | 392 |
helper = self.config_helper(config) |
393 |
# check the cube exists |
|
394 |
try: |
|
1132 | 395 |
templdirs = [cwcfg.cube_dir(cube) |
0 | 396 |
for cube in cubes] |
397 |
except ConfigurationError, ex: |
|
398 |
print ex |
|
399 |
print '\navailable cubes:', |
|
1132 | 400 |
print ', '.join(cwcfg.available_cubes()) |
0 | 401 |
return |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
402 |
# create the registry directory for this instance |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
403 |
print '\n'+underline_title('Creating the instance %s' % appid) |
0 | 404 |
create_dir(config.apphome) |
405 |
# cubicweb-ctl configuration |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
406 |
print '\n'+underline_title('Configuring the instance (%s.conf)' % configname) |
0 | 407 |
config.input_config('main', self.config.config_level) |
408 |
# configuration'specific stuff |
|
409 |
print |
|
410 |
helper.bootstrap(cubes, 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
|
411 |
# input for cubes specific options |
7bf205b9a845
when creating an instance, ask for cubes specific options properly (fix #607349)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4609
diff
changeset
|
412 |
for section in set(sect.lower() for sect, opt, optdict in config.all_options() |
7bf205b9a845
when creating an instance, ask for cubes specific options properly (fix #607349)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4609
diff
changeset
|
413 |
if optdict.get('inputlevel') <= self.config.config_level): |
7bf205b9a845
when creating an instance, ask for cubes specific options properly (fix #607349)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4609
diff
changeset
|
414 |
if section not in ('main', 'email', 'pyro'): |
7bf205b9a845
when creating an instance, ask for cubes specific options properly (fix #607349)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4609
diff
changeset
|
415 |
print '\n' + underline_title('%s options' % section) |
7bf205b9a845
when creating an instance, ask for cubes specific options properly (fix #607349)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4609
diff
changeset
|
416 |
config.input_config(section, self.config.config_level) |
0 | 417 |
# write down configuration |
418 |
config.save() |
|
4064
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
419 |
self._handle_win32(config, appid) |
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2318
diff
changeset
|
420 |
print '-> generated %s' % config.main_config_file() |
0 | 421 |
# handle i18n files structure |
422 |
# in the first cube given |
|
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2318
diff
changeset
|
423 |
print '-> preparing i18n catalogs' |
4021
280c910c8710
move i18n / migration modules from cw.common to cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3720
diff
changeset
|
424 |
from cubicweb import i18n |
0 | 425 |
langs = [lang for lang, _ in i18n.available_catalogs(join(templdirs[0], 'i18n'))] |
426 |
errors = config.i18ncompile(langs) |
|
427 |
if errors: |
|
428 |
print '\n'.join(errors) |
|
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
429 |
if not ASK.confirm('error while compiling message catalogs, ' |
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
430 |
'continue anyway ?'): |
0 | 431 |
print 'creation not completed' |
432 |
return |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
433 |
# create the additional data directory for this instance |
0 | 434 |
if config.appdatahome != config.apphome: # true in dev mode |
435 |
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
|
436 |
create_dir(join(config.appdatahome, 'backup')) |
0 | 437 |
if config['uid']: |
438 |
from logilab.common.shellutils import chown |
|
439 |
# this directory should be owned by the uid of the server process |
|
440 |
print 'set %s as owner of the data directory' % config['uid'] |
|
441 |
chown(config.appdatahome, config['uid']) |
|
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2318
diff
changeset
|
442 |
print '\n-> creation done for %r.\n' % config.apphome |
0 | 443 |
helper.postcreate() |
444 |
||
4064
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
445 |
def _handle_win32(self, config, appid): |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
446 |
if sys.platform != 'win32': |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
447 |
return |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
448 |
service_template = """ |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
449 |
import sys |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
450 |
import win32serviceutil |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
451 |
sys.path.insert(0, r"%(CWPATH)s") |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
452 |
|
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
453 |
from cubicweb.etwist.service import CWService |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
454 |
|
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
455 |
classdict = {'_svc_name_': 'cubicweb-%(APPID)s', |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
456 |
'_svc_display_name_': 'CubicWeb ' + '%(CNAME)s', |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
457 |
'instance': '%(APPID)s'} |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
458 |
%(CNAME)sService = type('%(CNAME)sService', (CWService,), classdict) |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
459 |
|
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
460 |
if __name__ == '__main__': |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
461 |
win32serviceutil.HandleCommandLine(%(CNAME)sService) |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
462 |
""" |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
463 |
open(join(config.apphome, 'win32svc.py'), 'wb').write( |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
464 |
service_template % {'APPID': appid, |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
465 |
'CNAME': appid.capitalize(), |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
466 |
'CWPATH': abspath(join(dirname(__file__), '..'))}) |
3b12e4192983
be able to run cw instances as windows services
auc@giediprime.logilab.fr
parents:
3715
diff
changeset
|
467 |
|
1446 | 468 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
469 |
class DeleteInstanceCommand(Command): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
470 |
"""Delete an instance. Will remove instance's files and |
0 | 471 |
unregister it. |
472 |
""" |
|
473 |
name = 'delete' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
474 |
arguments = '<instance>' |
1446 | 475 |
|
0 | 476 |
options = () |
477 |
||
478 |
def run(self, args): |
|
479 |
"""run the command with its specific arguments""" |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
480 |
appid = pop_arg(args, msg="No instance specified !") |
1132 | 481 |
configs = [cwcfg.config_for(appid, configname) |
482 |
for configname in cwcfg.possible_configurations(appid)] |
|
0 | 483 |
if not configs: |
484 |
raise ExecutionError('unable to guess configuration for %s' % appid) |
|
485 |
for config in configs: |
|
486 |
helper = self.config_helper(config, required=False) |
|
487 |
if helper: |
|
488 |
helper.cleanup() |
|
489 |
# remove home |
|
490 |
rm(config.apphome) |
|
491 |
# remove instance data directory |
|
492 |
try: |
|
493 |
rm(config.appdatahome) |
|
494 |
except OSError, ex: |
|
495 |
import errno |
|
496 |
if ex.errno != errno.ENOENT: |
|
497 |
raise |
|
498 |
confignames = ', '.join([config.name for config in configs]) |
|
2532
f7ca29d75183
[cleanup] improve dialog message consistency
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2512
diff
changeset
|
499 |
print '-> instance %s (%s) deleted.' % (appid, confignames) |
0 | 500 |
|
501 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
502 |
# instance commands ######################################################## |
0 | 503 |
|
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
504 |
class StartInstanceCommand(InstanceCommandFork): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
505 |
"""Start the given instances. If no instance is given, start them all. |
1446 | 506 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
507 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
508 |
identifiers of the instances to start. If no instance is |
0 | 509 |
given, start them all. |
510 |
""" |
|
511 |
name = 'start' |
|
512 |
actionverb = 'started' |
|
513 |
options = ( |
|
514 |
("debug", |
|
515 |
{'short': 'D', 'action' : 'store_true', |
|
516 |
'help': 'start server in debug mode.'}), |
|
517 |
("force", |
|
518 |
{'short': 'f', 'action' : 'store_true', |
|
519 |
'default': False, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
520 |
'help': 'start the instance even if it seems to be already \ |
0 | 521 |
running.'}), |
522 |
('profile', |
|
523 |
{'short': 'P', 'type' : 'string', 'metavar': '<stat file>', |
|
524 |
'default': None, |
|
525 |
'help': 'profile code and use the specified file to store stats', |
|
526 |
}), |
|
2654
6512522860aa
[twisted] don't use twistd anymore, all-in-one.py file is needed anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2633
diff
changeset
|
527 |
('loglevel', |
6512522860aa
[twisted] don't use twistd anymore, all-in-one.py file is needed anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2633
diff
changeset
|
528 |
{'short': 'l', 'type' : 'choice', 'metavar': '<log level>', |
6512522860aa
[twisted] don't use twistd anymore, all-in-one.py file is needed anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2633
diff
changeset
|
529 |
'default': None, 'choices': ('debug', 'info', 'warning', 'error'), |
6512522860aa
[twisted] don't use twistd anymore, all-in-one.py file is needed anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2633
diff
changeset
|
530 |
'help': 'debug if -D is set, error otherwise', |
6512522860aa
[twisted] don't use twistd anymore, all-in-one.py file is needed anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2633
diff
changeset
|
531 |
}), |
0 | 532 |
) |
533 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
534 |
def start_instance(self, appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
535 |
"""start the instance's server""" |
3182 | 536 |
debug = self['debug'] |
537 |
force = self['force'] |
|
538 |
loglevel = self['loglevel'] |
|
1132 | 539 |
config = cwcfg.config_for(appid) |
2654
6512522860aa
[twisted] don't use twistd anymore, all-in-one.py file is needed anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2633
diff
changeset
|
540 |
if loglevel is not None: |
6512522860aa
[twisted] don't use twistd anymore, all-in-one.py file is needed anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2633
diff
changeset
|
541 |
loglevel = 'LOG_%s' % loglevel.upper() |
6512522860aa
[twisted] don't use twistd anymore, all-in-one.py file is needed anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2633
diff
changeset
|
542 |
config.global_set_option('log-threshold', loglevel) |
6512522860aa
[twisted] don't use twistd anymore, all-in-one.py file is needed anymore
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2633
diff
changeset
|
543 |
config.init_log(loglevel, debug=debug, force=True) |
3182 | 544 |
if self['profile']: |
0 | 545 |
config.global_set_option('profile', self.config.profile) |
546 |
helper = self.config_helper(config, cmdname='start') |
|
547 |
pidf = config['pid-file'] |
|
548 |
if exists(pidf) and not force: |
|
549 |
msg = "%s seems to be running. Remove %s by hand if necessary or use \ |
|
550 |
the --force option." |
|
551 |
raise ExecutionError(msg % (appid, pidf)) |
|
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
552 |
helper.start_server(config, debug) |
0 | 553 |
|
554 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
555 |
class StopInstanceCommand(InstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
556 |
"""Stop the given instances. |
1446 | 557 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
558 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
559 |
identifiers of the instances to stop. If no instance is |
0 | 560 |
given, stop them all. |
561 |
""" |
|
562 |
name = 'stop' |
|
563 |
actionverb = 'stopped' |
|
1446 | 564 |
|
0 | 565 |
def ordered_instances(self): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
566 |
instances = super(StopInstanceCommand, self).ordered_instances() |
0 | 567 |
instances.reverse() |
568 |
return instances |
|
1446 | 569 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
570 |
def stop_instance(self, appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
571 |
"""stop the instance's server""" |
1132 | 572 |
config = cwcfg.config_for(appid) |
0 | 573 |
helper = self.config_helper(config, cmdname='stop') |
574 |
helper.poststop() # do this anyway |
|
575 |
pidf = config['pid-file'] |
|
576 |
if not exists(pidf): |
|
577 |
print >> sys.stderr, "%s doesn't exist." % pidf |
|
578 |
return |
|
579 |
import signal |
|
580 |
pid = int(open(pidf).read().strip()) |
|
581 |
try: |
|
582 |
kill(pid, signal.SIGTERM) |
|
583 |
except: |
|
584 |
print >> sys.stderr, "process %s seems already dead." % pid |
|
585 |
else: |
|
586 |
try: |
|
587 |
wait_process_end(pid) |
|
588 |
except ExecutionError, ex: |
|
589 |
print >> sys.stderr, ex |
|
590 |
print >> sys.stderr, 'trying SIGKILL' |
|
591 |
try: |
|
592 |
kill(pid, signal.SIGKILL) |
|
593 |
except: |
|
594 |
# probably dead now |
|
595 |
pass |
|
596 |
wait_process_end(pid) |
|
597 |
try: |
|
598 |
remove(pidf) |
|
599 |
except OSError: |
|
600 |
# already removed by twistd |
|
601 |
pass |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
602 |
print 'instance %s stopped' % appid |
1446 | 603 |
|
0 | 604 |
|
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
605 |
class RestartInstanceCommand(StartInstanceCommand): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
606 |
"""Restart the given instances. |
1446 | 607 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
608 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
609 |
identifiers of the instances to restart. If no instance is |
0 | 610 |
given, restart them all. |
611 |
""" |
|
612 |
name = 'restart' |
|
613 |
actionverb = 'restarted' |
|
614 |
||
615 |
def run_args(self, args, askconfirm): |
|
1132 | 616 |
regdir = cwcfg.registry_dir() |
0 | 617 |
if not isfile(join(regdir, 'startorder')) or len(args) <= 1: |
618 |
# no specific startorder |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
619 |
super(RestartInstanceCommand, self).run_args(args, askconfirm) |
0 | 620 |
return |
621 |
print ('some specific start order is specified, will first stop all ' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
622 |
'instances then restart them.') |
0 | 623 |
# get instances in startorder |
624 |
for appid in args: |
|
625 |
if askconfirm: |
|
626 |
print '*'*72 |
|
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
627 |
if not ASK.confirm('%s instance %r ?' % (self.name, appid)): |
0 | 628 |
continue |
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
629 |
StopInstanceCommand().stop_instance(appid) |
0 | 630 |
forkcmd = [w for w in sys.argv if not w in args] |
631 |
forkcmd[1] = 'start' |
|
632 |
forkcmd = ' '.join(forkcmd) |
|
633 |
for appid in reversed(args): |
|
634 |
status = system('%s %s' % (forkcmd, appid)) |
|
635 |
if status: |
|
636 |
sys.exit(status) |
|
1446 | 637 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
638 |
def restart_instance(self, appid): |
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
639 |
StopInstanceCommand().stop_instance(appid) |
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
640 |
self.start_instance(appid) |
0 | 641 |
|
1446 | 642 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
643 |
class ReloadConfigurationCommand(RestartInstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
644 |
"""Reload the given instances. This command is equivalent to a |
0 | 645 |
restart for now. |
1446 | 646 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
647 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
648 |
identifiers of the instances to reload. If no instance is |
0 | 649 |
given, reload them all. |
650 |
""" |
|
651 |
name = 'reload' |
|
1446 | 652 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
653 |
def reload_instance(self, appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
654 |
self.restart_instance(appid) |
1446 | 655 |
|
0 | 656 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
657 |
class StatusCommand(InstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
658 |
"""Display status information about the given instances. |
1446 | 659 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
660 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
661 |
identifiers of the instances to status. If no instance is |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
662 |
given, get status information about all registered instances. |
0 | 663 |
""" |
664 |
name = 'status' |
|
665 |
options = () |
|
666 |
||
1132 | 667 |
@staticmethod |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
668 |
def status_instance(appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
669 |
"""print running status information for an instance""" |
1132 | 670 |
for mode in cwcfg.possible_configurations(appid): |
671 |
config = cwcfg.config_for(appid, mode) |
|
0 | 672 |
print '[%s-%s]' % (appid, mode), |
673 |
try: |
|
674 |
pidf = config['pid-file'] |
|
675 |
except KeyError: |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
676 |
print 'buggy instance, pid file not specified' |
0 | 677 |
continue |
678 |
if not exists(pidf): |
|
679 |
print "doesn't seem to be running" |
|
680 |
continue |
|
681 |
pid = int(open(pidf).read().strip()) |
|
682 |
# trick to guess whether or not the process is running |
|
683 |
try: |
|
684 |
getpgid(pid) |
|
685 |
except OSError: |
|
686 |
print "should be running with pid %s but the process can not be found" % pid |
|
687 |
continue |
|
688 |
print "running with pid %s" % (pid) |
|
689 |
||
690 |
||
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
691 |
class UpgradeInstanceCommand(InstanceCommandFork): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
692 |
"""Upgrade an instance after cubicweb and/or component(s) upgrade. |
0 | 693 |
|
694 |
For repository update, you will be prompted for a login / password to use |
|
695 |
to connect to the system database. For some upgrades, the given user |
|
696 |
should have create or alter table permissions. |
|
697 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
698 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
699 |
identifiers of the instances to upgrade. If no instance is |
0 | 700 |
given, upgrade them all. |
701 |
""" |
|
702 |
name = 'upgrade' |
|
703 |
actionverb = 'upgraded' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
704 |
options = InstanceCommand.options + ( |
0 | 705 |
('force-componant-version', |
706 |
{'short': 't', 'type' : 'csv', 'metavar': 'cube1=X.Y.Z,cube2=X.Y.Z', |
|
707 |
'default': None, |
|
708 |
'help': 'force migration from the indicated version for the specified cube.'}), |
|
709 |
('force-cubicweb-version', |
|
710 |
{'short': 'e', 'type' : 'string', 'metavar': 'X.Y.Z', |
|
711 |
'default': None, |
|
712 |
'help': 'force migration from the indicated cubicweb version.'}), |
|
1446 | 713 |
|
0 | 714 |
('fs-only', |
715 |
{'short': 's', 'action' : 'store_true', |
|
716 |
'default': False, |
|
717 |
'help': 'only upgrade files on the file system, not the database.'}), |
|
718 |
||
719 |
('nostartstop', |
|
720 |
{'short': 'n', 'action' : 'store_true', |
|
721 |
'default': False, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
722 |
'help': 'don\'t try to stop instance before migration and to restart it after.'}), |
1446 | 723 |
|
0 | 724 |
('verbosity', |
725 |
{'short': 'v', 'type' : 'int', 'metavar': '<0..2>', |
|
726 |
'default': 1, |
|
727 |
'help': "0: no confirmation, 1: only main commands confirmed, 2 ask \ |
|
728 |
for everything."}), |
|
1446 | 729 |
|
0 | 730 |
('backup-db', |
731 |
{'short': 'b', 'type' : 'yn', 'metavar': '<y or n>', |
|
732 |
'default': None, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
733 |
'help': "Backup the instance database before upgrade.\n"\ |
0 | 734 |
"If the option is ommitted, confirmation will be ask.", |
735 |
}), |
|
736 |
||
737 |
('ext-sources', |
|
738 |
{'short': 'E', 'type' : 'csv', 'metavar': '<sources>', |
|
739 |
'default': None, |
|
740 |
'help': "For multisources instances, specify to which sources the \ |
|
741 |
repository should connect to for upgrading. When unspecified or 'migration' is \ |
|
742 |
given, appropriate sources for migration will be automatically selected \ |
|
743 |
(recommended). If 'all' is given, will connect to all defined sources.", |
|
744 |
}), |
|
745 |
) |
|
746 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
747 |
def upgrade_instance(self, appid): |
2512
106b2a05dc88
[cleanup] started to improve cubicweb-ctl dialog messages consistency
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2489
diff
changeset
|
748 |
print '\n' + underline_title('Upgrading the instance %s' % appid) |
0 | 749 |
from logilab.common.changelog import Version |
1132 | 750 |
config = cwcfg.config_for(appid) |
2473
490f88fb99b6
new distinguish repairing/creating from regular start.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2395
diff
changeset
|
751 |
config.repairing = True # notice we're not starting the server |
0 | 752 |
config.verbosity = self.config.verbosity |
1219
054bb575c013
take care, self.config may not be a server config
sylvain.thenault@logilab.fr
parents:
1015
diff
changeset
|
753 |
try: |
054bb575c013
take care, self.config may not be a server config
sylvain.thenault@logilab.fr
parents:
1015
diff
changeset
|
754 |
config.set_sources_mode(self.config.ext_sources or ('migration',)) |
054bb575c013
take care, self.config may not be a server config
sylvain.thenault@logilab.fr
parents:
1015
diff
changeset
|
755 |
except AttributeError: |
054bb575c013
take care, self.config may not be a server config
sylvain.thenault@logilab.fr
parents:
1015
diff
changeset
|
756 |
# not a server config |
054bb575c013
take care, self.config may not be a server config
sylvain.thenault@logilab.fr
parents:
1015
diff
changeset
|
757 |
pass |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
758 |
# get instance and installed versions for the server and the componants |
0 | 759 |
mih = config.migration_handler() |
760 |
repo = mih.repo_connect() |
|
761 |
vcconf = repo.get_versions() |
|
762 |
if self.config.force_componant_version: |
|
763 |
packversions = {} |
|
764 |
for vdef in self.config.force_componant_version: |
|
765 |
componant, version = vdef.split('=') |
|
766 |
packversions[componant] = Version(version) |
|
767 |
vcconf.update(packversions) |
|
768 |
toupgrade = [] |
|
769 |
for cube in config.cubes(): |
|
770 |
installedversion = config.cube_version(cube) |
|
771 |
try: |
|
772 |
applversion = vcconf[cube] |
|
773 |
except KeyError: |
|
774 |
config.error('no version information for %s' % cube) |
|
775 |
continue |
|
776 |
if installedversion > applversion: |
|
777 |
toupgrade.append( (cube, applversion, installedversion) ) |
|
1446 | 778 |
cubicwebversion = config.cubicweb_version() |
0 | 779 |
if self.config.force_cubicweb_version: |
780 |
applcubicwebversion = Version(self.config.force_cubicweb_version) |
|
781 |
vcconf['cubicweb'] = applcubicwebversion |
|
782 |
else: |
|
783 |
applcubicwebversion = vcconf.get('cubicweb') |
|
784 |
if cubicwebversion > applcubicwebversion: |
|
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2156
diff
changeset
|
785 |
toupgrade.append(('cubicweb', applcubicwebversion, cubicwebversion)) |
0 | 786 |
if not self.config.fs_only and not toupgrade: |
2512
106b2a05dc88
[cleanup] started to improve cubicweb-ctl dialog messages consistency
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2489
diff
changeset
|
787 |
print '-> no software migration needed for instance %s.' % appid |
0 | 788 |
return |
789 |
for cube, fromversion, toversion in toupgrade: |
|
2532
f7ca29d75183
[cleanup] improve dialog message consistency
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2512
diff
changeset
|
790 |
print '-> migration needed from %s to %s for %s' % (fromversion, toversion, cube) |
1404
971b19de6b85
stop application only once we're sure we've something to do, fixing #342689
sylvain.thenault@logilab.fr
parents:
1219
diff
changeset
|
791 |
# only stop once we're sure we have something to do |
3638
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3619
diff
changeset
|
792 |
if not (CWDEV or self.config.nostartstop): |
3188
34395d1f00d6
[c-c] fix 3.4.9 name error :'(
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3182
diff
changeset
|
793 |
StopInstanceCommand().stop_instance(appid) |
0 | 794 |
# run cubicweb/componants migration scripts |
795 |
mih.migrate(vcconf, reversed(toupgrade), self.config) |
|
796 |
# rewrite main configuration file |
|
797 |
mih.rewrite_configuration() |
|
798 |
# handle i18n upgrade: |
|
799 |
# * install new languages |
|
800 |
# * 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
|
801 |
# 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
|
802 |
from cubicweb import i18n |
1132 | 803 |
templdir = cwcfg.cube_dir(config.cubes()[0]) |
0 | 804 |
langs = [lang for lang, _ in i18n.available_catalogs(join(templdir, 'i18n'))] |
805 |
errors = config.i18ncompile(langs) |
|
806 |
if errors: |
|
807 |
print '\n'.join(errors) |
|
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
808 |
if not ASK.confirm('Error while compiling message catalogs, ' |
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
809 |
'continue anyway ?'): |
2512
106b2a05dc88
[cleanup] started to improve cubicweb-ctl dialog messages consistency
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2489
diff
changeset
|
810 |
print '-> migration not completed.' |
0 | 811 |
return |
812 |
mih.shutdown() |
|
813 |
print |
|
2512
106b2a05dc88
[cleanup] started to improve cubicweb-ctl dialog messages consistency
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2489
diff
changeset
|
814 |
print '-> instance migrated.' |
3638
648d6dbec630
system/user modes + CWDEV instead of installed/dev mixed modes. Fix behaviour when setting CW_MODE explicitly
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3619
diff
changeset
|
815 |
if not (CWDEV or self.config.nostartstop): |
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
|
816 |
# restart instance through fork to get a proper environment, avoid |
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
|
817 |
# uicfg pb (and probably gettext catalogs, to check...) |
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
|
818 |
forkcmd = '%s start %s' % (sys.argv[0], appid) |
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
|
819 |
status = system(forkcmd) |
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
|
820 |
if status: |
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
|
821 |
print '%s exited with status %s' % (forkcmd, status) |
0 | 822 |
print |
823 |
||
824 |
||
825 |
class ShellCommand(Command): |
|
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
826 |
"""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
|
827 |
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
|
828 |
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
|
829 |
in batch mode. |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
830 |
|
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
831 |
By default it will connect to a local instance using an in memory |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
832 |
connection, unless -P option is specified, in which case you will be |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
833 |
connected through pyro. In the later case, you won't have access to |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
834 |
repository internals (session, etc...) so most migration commands won't be |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
835 |
available. |
0 | 836 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
837 |
<instance> |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
838 |
the identifier of the instance to connect. |
0 | 839 |
""" |
840 |
name = 'shell' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
841 |
arguments = '<instance> [batch command file]' |
0 | 842 |
options = ( |
843 |
('system-only', |
|
844 |
{'short': 'S', 'action' : 'store_true', |
|
845 |
'help': 'only connect to the system source when the instance is ' |
|
846 |
'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
|
847 |
'--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
|
848 |
'group': 'local' |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
849 |
}), |
1446 | 850 |
|
0 | 851 |
('ext-sources', |
852 |
{'short': 'E', 'type' : 'csv', 'metavar': '<sources>', |
|
853 |
'help': "For multisources instances, specify to which sources the \ |
|
854 |
repository should connect to for upgrading. When unspecified or 'all' given, \ |
|
855 |
will connect to all defined sources. If 'migration' is given, appropriate \ |
|
856 |
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
|
857 |
'group': 'local' |
0 | 858 |
}), |
1446 | 859 |
|
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
|
860 |
('force', |
b23bbb31368c
backport change from default to get -f option on cw shell, may be necessary for the forthcoming migration...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2743
diff
changeset
|
861 |
{'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
|
862 |
'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
|
863 |
'group': 'local' |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
864 |
}), |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
865 |
|
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
866 |
('pyro', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
867 |
{'short': 'P', 'action' : 'store_true', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
868 |
'help': 'connect to a running instance through Pyro.', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
869 |
'group': 'remote', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
870 |
}), |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
871 |
('pyro-ns-host', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
872 |
{'short': 'H', 'type' : 'string', 'metavar': '<host[:port]>', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
873 |
'help': 'Pyro name server host. If not set, will be detected by ' |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
874 |
'using a broadcast query.', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
875 |
'group': 'remote' |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
876 |
}), |
0 | 877 |
) |
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
|
878 |
|
0 | 879 |
def run(self, args): |
4524
2eb36514ad6d
[cw-shell] do not set arbitrary limit on number of arguments
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
4064
diff
changeset
|
880 |
appid = pop_arg(args, None, msg="No instance specified !") |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
881 |
if self.config.pyro: |
3707
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
882 |
from cubicweb import AuthenticationError |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
883 |
from cubicweb.dbapi import connect |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
884 |
from cubicweb.server.utils import manager_userpasswd |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
885 |
from cubicweb.server.migractions import ServerMigrationHelper |
3707
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
886 |
while True: |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
887 |
try: |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
888 |
login, pwd = manager_userpasswd(msg=None) |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
889 |
cnx = connect(appid, login=login, password=pwd, |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
890 |
host=self.config.pyro_ns_host, mulcnx=False) |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
891 |
except AuthenticationError, ex: |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
892 |
print ex |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
893 |
except (KeyboardInterrupt, EOFError): |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
894 |
print |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
895 |
sys.exit(0) |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
896 |
else: |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
897 |
break |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
898 |
cnx.load_appobjects() |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
899 |
repo = cnx._repo |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
900 |
mih = ServerMigrationHelper(None, repo=repo, cnx=cnx, |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
901 |
# hack so it don't try to load fs schema |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
902 |
schema=1) |
0 | 903 |
else: |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
904 |
config = cwcfg.config_for(appid) |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
905 |
if self.config.ext_sources: |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
906 |
assert not self.config.system_only |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
907 |
sources = self.config.ext_sources |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
908 |
elif self.config.system_only: |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
909 |
sources = ('system',) |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
910 |
else: |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
911 |
sources = ('all',) |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
912 |
config.set_sources_mode(sources) |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
913 |
config.repairing = self.config.force |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
914 |
mih = config.migration_handler() |
3709
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
915 |
try: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
916 |
if args: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
917 |
for arg in args: |
3715
e3ccadb126d7
[shell] make process_script available throuhg c-c shell / migration script context
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3709
diff
changeset
|
918 |
mih.cmd_process_script(arg) |
3709
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
919 |
else: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
920 |
mih.interactive_shell() |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
921 |
finally: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
922 |
if not self.config.pyro: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
923 |
mih.shutdown() |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
924 |
else: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
925 |
cnx.close() |
0 | 926 |
|
927 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
928 |
class RecompileInstanceCatalogsCommand(InstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
929 |
"""Recompile i18n catalogs for instances. |
1446 | 930 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
931 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
932 |
identifiers of the instances to consider. If no instance is |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
933 |
given, recompile for all registered instances. |
0 | 934 |
""" |
1898
39b37f90a8a4
[cw-ctl] rename i18n commands (see #342889)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1477
diff
changeset
|
935 |
name = 'i18ninstance' |
1132 | 936 |
|
937 |
@staticmethod |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
938 |
def i18ninstance_instance(appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
939 |
"""recompile instance's messages catalogs""" |
1132 | 940 |
config = cwcfg.config_for(appid) |
5043
fe52dd3936cf
[repo config] cleanup read_instance_schema / bootstrap_schema / creating mess
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5042
diff
changeset
|
941 |
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
|
942 |
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
|
943 |
if config._cubes is None: |
0 | 944 |
# 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
|
945 |
config.init_cubes(repo.get_cubes()) |
0 | 946 |
errors = config.i18ncompile() |
947 |
if errors: |
|
948 |
print '\n'.join(errors) |
|
949 |
||
950 |
||
951 |
class ListInstancesCommand(Command): |
|
952 |
"""list available instances, useful for bash completion.""" |
|
953 |
name = 'listinstances' |
|
954 |
hidden = True |
|
1446 | 955 |
|
0 | 956 |
def run(self, args): |
957 |
"""run the command with its specific arguments""" |
|
1132 | 958 |
regdir = cwcfg.registry_dir() |
0 | 959 |
for appid in sorted(listdir(regdir)): |
960 |
print appid |
|
961 |
||
962 |
||
963 |
class ListCubesCommand(Command): |
|
964 |
"""list available componants, useful for bash completion.""" |
|
965 |
name = 'listcubes' |
|
966 |
hidden = True |
|
1446 | 967 |
|
0 | 968 |
def run(self, args): |
969 |
"""run the command with its specific arguments""" |
|
1132 | 970 |
for cube in cwcfg.available_cubes(): |
0 | 971 |
print cube |
972 |
||
973 |
register_commands((ListCommand, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
974 |
CreateInstanceCommand, |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
975 |
DeleteInstanceCommand, |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
976 |
StartInstanceCommand, |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
977 |
StopInstanceCommand, |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
978 |
RestartInstanceCommand, |
0 | 979 |
ReloadConfigurationCommand, |
980 |
StatusCommand, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
981 |
UpgradeInstanceCommand, |
0 | 982 |
ShellCommand, |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
983 |
RecompileInstanceCatalogsCommand, |
0 | 984 |
ListInstancesCommand, ListCubesCommand, |
985 |
)) |
|
986 |
||
1446 | 987 |
|
0 | 988 |
def run(args): |
989 |
"""command line tool""" |
|
1132 | 990 |
cwcfg.load_cwctl_plugins() |
4720
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
991 |
main_run(args, """%%prog %s [options] %s |
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
992 |
|
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
993 |
The CubicWeb swiss-knife. |
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
994 |
|
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
995 |
%s""" |
ddf4f19eb07a
don't use module doc string as usage string
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4718
diff
changeset
|
996 |
) |
0 | 997 |
|
998 |
if __name__ == '__main__': |
|
999 |
run(sys.argv[1:]) |