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