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