author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 16 Oct 2009 17:11:44 +0200 | |
branch | stable |
changeset 3709 | e67ade20bf80 |
parent 3707 | 78596919ede3 |
child 3715 | e3ccadb126d7 |
permissions | -rw-r--r-- |
0 | 1 |
"""%%prog %s [options] %s |
2 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
3 |
CubicWeb main instances controller. |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1898
diff
changeset
|
4 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
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 |
|
0 | 15 |
from os.path import exists, join, isfile, isdir |
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 |
|
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2318
diff
changeset
|
20 |
from cubicweb import ConfigurationError, ExecutionError, BadCommandUsage, underline_title |
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 |
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
|
22 |
from cubicweb.toolsutils import Command, main_run, rm, create_dir |
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 |
||
161 |
class ListCommand(Command): |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
162 |
"""List configurations, cubes and instances. |
0 | 163 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
164 |
list available configurations, installed cubes, and registered instances |
0 | 165 |
""" |
166 |
name = 'list' |
|
167 |
options = ( |
|
168 |
('verbose', |
|
1446 | 169 |
{'short': 'v', 'action' : 'store_true', |
170 |
'help': "display more information."}), |
|
0 | 171 |
) |
1446 | 172 |
|
0 | 173 |
def run(self, args): |
174 |
"""run the command with its specific arguments""" |
|
175 |
if args: |
|
176 |
raise BadCommandUsage('Too much arguments') |
|
3486
ea6bf6f9ba0c
[cwctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
3198
diff
changeset
|
177 |
print 'CubicWeb %s (%s mode)' % (cwcfg.cubicweb_version(), cwcfg.mode) |
0 | 178 |
print |
179 |
print 'Available configurations:' |
|
180 |
for config in CONFIGURATIONS: |
|
181 |
print '*', config.name |
|
182 |
for line in config.__doc__.splitlines(): |
|
183 |
line = line.strip() |
|
184 |
if not line: |
|
185 |
continue |
|
186 |
print ' ', line |
|
1446 | 187 |
print |
0 | 188 |
try: |
1342
4273e44852cb
no more cubes_dir class method
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
189 |
cubesdir = pathsep.join(cwcfg.cubes_search_path()) |
1132 | 190 |
namesize = max(len(x) for x in cwcfg.available_cubes()) |
0 | 191 |
except ConfigurationError, ex: |
192 |
print 'No cubes available:', ex |
|
193 |
except ValueError: |
|
194 |
print 'No cubes available in %s' % cubesdir |
|
195 |
else: |
|
196 |
print 'Available cubes (%s):' % cubesdir |
|
1132 | 197 |
for cube in cwcfg.available_cubes(): |
0 | 198 |
if cube in ('CVS', '.svn', 'shared', '.hg'): |
199 |
continue |
|
200 |
try: |
|
1132 | 201 |
tinfo = cwcfg.cube_pkginfo(cube) |
0 | 202 |
tversion = tinfo.version |
203 |
except ConfigurationError: |
|
204 |
tinfo = None |
|
205 |
tversion = '[missing cube information]' |
|
206 |
print '* %s %s' % (cube.ljust(namesize), tversion) |
|
207 |
if self.config.verbose: |
|
208 |
shortdesc = tinfo and (getattr(tinfo, 'short_desc', '') |
|
209 |
or tinfo.__doc__) |
|
210 |
if shortdesc: |
|
211 |
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
|
212 |
modes = detect_available_modes(cwcfg.cube_dir(cube)) |
0 | 213 |
print ' available modes: %s' % ', '.join(modes) |
214 |
print |
|
215 |
try: |
|
1132 | 216 |
regdir = cwcfg.registry_dir() |
0 | 217 |
except ConfigurationError, ex: |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
218 |
print 'No instance available:', ex |
0 | 219 |
print |
220 |
return |
|
221 |
instances = list_instances(regdir) |
|
222 |
if instances: |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
223 |
print 'Available instances (%s):' % regdir |
0 | 224 |
for appid in instances: |
1132 | 225 |
modes = cwcfg.possible_configurations(appid) |
0 | 226 |
if not modes: |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
227 |
print '* %s (BROKEN instance, no configuration found)' % appid |
0 | 228 |
continue |
229 |
print '* %s (%s)' % (appid, ', '.join(modes)) |
|
230 |
try: |
|
1132 | 231 |
config = cwcfg.config_for(appid, modes[0]) |
1446 | 232 |
except Exception, exc: |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
233 |
print ' (BROKEN instance, %s)' % exc |
0 | 234 |
continue |
235 |
else: |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
236 |
print 'No instance available in %s' % regdir |
0 | 237 |
print |
238 |
||
239 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
240 |
class CreateInstanceCommand(Command): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
241 |
"""Create an instance from a cube. This is an unified |
0 | 242 |
command which can handle web / server / all-in-one installation |
243 |
according to available parts of the software library and of the |
|
244 |
desired cube. |
|
245 |
||
246 |
<cube> |
|
247 |
the name of cube to use (list available cube names using |
|
248 |
the "list" command). You can use several cubes by separating |
|
249 |
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
|
250 |
<instance> |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
251 |
an identifier for the instance to create |
0 | 252 |
""" |
253 |
name = 'create' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
254 |
arguments = '<cube> <instance>' |
0 | 255 |
options = ( |
256 |
("config-level", |
|
257 |
{'short': 'l', 'type' : 'int', 'metavar': '<level>', |
|
258 |
'default': 0, |
|
259 |
'help': 'configuration level (0..2): 0 will ask for essential \ |
|
260 |
configuration parameters only while 2 will ask for all parameters', |
|
261 |
} |
|
262 |
), |
|
263 |
("config", |
|
264 |
{'short': 'c', 'type' : 'choice', 'metavar': '<install type>', |
|
265 |
'choices': ('all-in-one', 'repository', 'twisted'), |
|
266 |
'default': 'all-in-one', |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
267 |
'help': 'installation type, telling which part of an instance \ |
0 | 268 |
should be installed. You can list available configurations using the "list" \ |
269 |
command. Default to "all-in-one", e.g. an installation embedding both the RQL \ |
|
270 |
repository and the web server.', |
|
271 |
} |
|
272 |
), |
|
273 |
) |
|
1446 | 274 |
|
0 | 275 |
def run(self, args): |
276 |
"""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
|
277 |
from logilab.common.textutils import splitstrip |
0 | 278 |
configname = self.config.config |
2633
bc9386c3b2c9
get_csv is being renamed to splitstrip
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2615
diff
changeset
|
279 |
cubes = splitstrip(pop_arg(args, 1)) |
0 | 280 |
appid = pop_arg(args) |
281 |
# get the configuration and helper |
|
1132 | 282 |
cwcfg.creating = True |
283 |
config = cwcfg.config_for(appid, configname) |
|
0 | 284 |
config.set_language = False |
2104
b4ffcea3275b
change cubes into expanded cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2032
diff
changeset
|
285 |
cubes = config.expand_cubes(cubes) |
b4ffcea3275b
change cubes into expanded cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2032
diff
changeset
|
286 |
config.init_cubes(cubes) |
0 | 287 |
helper = self.config_helper(config) |
288 |
# check the cube exists |
|
289 |
try: |
|
1132 | 290 |
templdirs = [cwcfg.cube_dir(cube) |
0 | 291 |
for cube in cubes] |
292 |
except ConfigurationError, ex: |
|
293 |
print ex |
|
294 |
print '\navailable cubes:', |
|
1132 | 295 |
print ', '.join(cwcfg.available_cubes()) |
0 | 296 |
return |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
297 |
# 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
|
298 |
print '\n'+underline_title('Creating the instance %s' % appid) |
0 | 299 |
create_dir(config.apphome) |
300 |
# load site_cubicweb from the cubes dir (if any) |
|
301 |
config.load_site_cubicweb() |
|
302 |
# cubicweb-ctl configuration |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
303 |
print '\n'+underline_title('Configuring the instance (%s.conf)' % configname) |
0 | 304 |
config.input_config('main', self.config.config_level) |
305 |
# configuration'specific stuff |
|
306 |
print |
|
307 |
helper.bootstrap(cubes, self.config.config_level) |
|
308 |
# write down configuration |
|
309 |
config.save() |
|
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2318
diff
changeset
|
310 |
print '-> generated %s' % config.main_config_file() |
0 | 311 |
# handle i18n files structure |
312 |
# in the first cube given |
|
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2318
diff
changeset
|
313 |
print '-> preparing i18n catalogs' |
0 | 314 |
from cubicweb.common import i18n |
315 |
langs = [lang for lang, _ in i18n.available_catalogs(join(templdirs[0], 'i18n'))] |
|
316 |
errors = config.i18ncompile(langs) |
|
317 |
if errors: |
|
318 |
print '\n'.join(errors) |
|
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
319 |
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
|
320 |
'continue anyway ?'): |
0 | 321 |
print 'creation not completed' |
322 |
return |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
323 |
# create the additional data directory for this instance |
0 | 324 |
if config.appdatahome != config.apphome: # true in dev mode |
325 |
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
|
326 |
create_dir(join(config.appdatahome, 'backup')) |
0 | 327 |
if config['uid']: |
328 |
from logilab.common.shellutils import chown |
|
329 |
# this directory should be owned by the uid of the server process |
|
330 |
print 'set %s as owner of the data directory' % config['uid'] |
|
331 |
chown(config.appdatahome, config['uid']) |
|
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2318
diff
changeset
|
332 |
print '\n-> creation done for %r.\n' % config.apphome |
0 | 333 |
helper.postcreate() |
334 |
||
1446 | 335 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
336 |
class DeleteInstanceCommand(Command): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
337 |
"""Delete an instance. Will remove instance's files and |
0 | 338 |
unregister it. |
339 |
""" |
|
340 |
name = 'delete' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
341 |
arguments = '<instance>' |
1446 | 342 |
|
0 | 343 |
options = () |
344 |
||
345 |
def run(self, args): |
|
346 |
"""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
|
347 |
appid = pop_arg(args, msg="No instance specified !") |
1132 | 348 |
configs = [cwcfg.config_for(appid, configname) |
349 |
for configname in cwcfg.possible_configurations(appid)] |
|
0 | 350 |
if not configs: |
351 |
raise ExecutionError('unable to guess configuration for %s' % appid) |
|
352 |
for config in configs: |
|
353 |
helper = self.config_helper(config, required=False) |
|
354 |
if helper: |
|
355 |
helper.cleanup() |
|
356 |
# remove home |
|
357 |
rm(config.apphome) |
|
358 |
# remove instance data directory |
|
359 |
try: |
|
360 |
rm(config.appdatahome) |
|
361 |
except OSError, ex: |
|
362 |
import errno |
|
363 |
if ex.errno != errno.ENOENT: |
|
364 |
raise |
|
365 |
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
|
366 |
print '-> instance %s (%s) deleted.' % (appid, confignames) |
0 | 367 |
|
368 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
369 |
# instance commands ######################################################## |
0 | 370 |
|
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
371 |
class StartInstanceCommand(InstanceCommandFork): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
372 |
"""Start the given instances. If no instance is given, start them all. |
1446 | 373 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
374 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
375 |
identifiers of the instances to start. If no instance is |
0 | 376 |
given, start them all. |
377 |
""" |
|
378 |
name = 'start' |
|
379 |
actionverb = 'started' |
|
380 |
options = ( |
|
381 |
("debug", |
|
382 |
{'short': 'D', 'action' : 'store_true', |
|
383 |
'help': 'start server in debug mode.'}), |
|
384 |
("force", |
|
385 |
{'short': 'f', 'action' : 'store_true', |
|
386 |
'default': False, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
387 |
'help': 'start the instance even if it seems to be already \ |
0 | 388 |
running.'}), |
389 |
('profile', |
|
390 |
{'short': 'P', 'type' : 'string', 'metavar': '<stat file>', |
|
391 |
'default': None, |
|
392 |
'help': 'profile code and use the specified file to store stats', |
|
393 |
}), |
|
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
|
394 |
('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
|
395 |
{'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
|
396 |
'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
|
397 |
'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
|
398 |
}), |
0 | 399 |
) |
400 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
401 |
def start_instance(self, appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
402 |
"""start the instance's server""" |
3182 | 403 |
debug = self['debug'] |
404 |
force = self['force'] |
|
405 |
loglevel = self['loglevel'] |
|
1132 | 406 |
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
|
407 |
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
|
408 |
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
|
409 |
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
|
410 |
config.init_log(loglevel, debug=debug, force=True) |
3182 | 411 |
if self['profile']: |
0 | 412 |
config.global_set_option('profile', self.config.profile) |
413 |
helper = self.config_helper(config, cmdname='start') |
|
414 |
pidf = config['pid-file'] |
|
415 |
if exists(pidf) and not force: |
|
416 |
msg = "%s seems to be running. Remove %s by hand if necessary or use \ |
|
417 |
the --force option." |
|
418 |
raise ExecutionError(msg % (appid, pidf)) |
|
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
419 |
helper.start_server(config, debug) |
0 | 420 |
|
421 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
422 |
class StopInstanceCommand(InstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
423 |
"""Stop the given instances. |
1446 | 424 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
425 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
426 |
identifiers of the instances to stop. If no instance is |
0 | 427 |
given, stop them all. |
428 |
""" |
|
429 |
name = 'stop' |
|
430 |
actionverb = 'stopped' |
|
1446 | 431 |
|
0 | 432 |
def ordered_instances(self): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
433 |
instances = super(StopInstanceCommand, self).ordered_instances() |
0 | 434 |
instances.reverse() |
435 |
return instances |
|
1446 | 436 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
437 |
def stop_instance(self, appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
438 |
"""stop the instance's server""" |
1132 | 439 |
config = cwcfg.config_for(appid) |
0 | 440 |
helper = self.config_helper(config, cmdname='stop') |
441 |
helper.poststop() # do this anyway |
|
442 |
pidf = config['pid-file'] |
|
443 |
if not exists(pidf): |
|
444 |
print >> sys.stderr, "%s doesn't exist." % pidf |
|
445 |
return |
|
446 |
import signal |
|
447 |
pid = int(open(pidf).read().strip()) |
|
448 |
try: |
|
449 |
kill(pid, signal.SIGTERM) |
|
450 |
except: |
|
451 |
print >> sys.stderr, "process %s seems already dead." % pid |
|
452 |
else: |
|
453 |
try: |
|
454 |
wait_process_end(pid) |
|
455 |
except ExecutionError, ex: |
|
456 |
print >> sys.stderr, ex |
|
457 |
print >> sys.stderr, 'trying SIGKILL' |
|
458 |
try: |
|
459 |
kill(pid, signal.SIGKILL) |
|
460 |
except: |
|
461 |
# probably dead now |
|
462 |
pass |
|
463 |
wait_process_end(pid) |
|
464 |
try: |
|
465 |
remove(pidf) |
|
466 |
except OSError: |
|
467 |
# already removed by twistd |
|
468 |
pass |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
469 |
print 'instance %s stopped' % appid |
1446 | 470 |
|
0 | 471 |
|
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
472 |
class RestartInstanceCommand(StartInstanceCommand): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
473 |
"""Restart the given instances. |
1446 | 474 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
475 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
476 |
identifiers of the instances to restart. If no instance is |
0 | 477 |
given, restart them all. |
478 |
""" |
|
479 |
name = 'restart' |
|
480 |
actionverb = 'restarted' |
|
481 |
||
482 |
def run_args(self, args, askconfirm): |
|
1132 | 483 |
regdir = cwcfg.registry_dir() |
0 | 484 |
if not isfile(join(regdir, 'startorder')) or len(args) <= 1: |
485 |
# no specific startorder |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
486 |
super(RestartInstanceCommand, self).run_args(args, askconfirm) |
0 | 487 |
return |
488 |
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
|
489 |
'instances then restart them.') |
0 | 490 |
# get instances in startorder |
491 |
for appid in args: |
|
492 |
if askconfirm: |
|
493 |
print '*'*72 |
|
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
494 |
if not ASK.confirm('%s instance %r ?' % (self.name, appid)): |
0 | 495 |
continue |
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
496 |
StopInstanceCommand().stop_instance(appid) |
0 | 497 |
forkcmd = [w for w in sys.argv if not w in args] |
498 |
forkcmd[1] = 'start' |
|
499 |
forkcmd = ' '.join(forkcmd) |
|
500 |
for appid in reversed(args): |
|
501 |
status = system('%s %s' % (forkcmd, appid)) |
|
502 |
if status: |
|
503 |
sys.exit(status) |
|
1446 | 504 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
505 |
def restart_instance(self, appid): |
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
506 |
StopInstanceCommand().stop_instance(appid) |
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
507 |
self.start_instance(appid) |
0 | 508 |
|
1446 | 509 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
510 |
class ReloadConfigurationCommand(RestartInstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
511 |
"""Reload the given instances. This command is equivalent to a |
0 | 512 |
restart for now. |
1446 | 513 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
514 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
515 |
identifiers of the instances to reload. If no instance is |
0 | 516 |
given, reload them all. |
517 |
""" |
|
518 |
name = 'reload' |
|
1446 | 519 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
520 |
def reload_instance(self, appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
521 |
self.restart_instance(appid) |
1446 | 522 |
|
0 | 523 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
524 |
class StatusCommand(InstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
525 |
"""Display status information about the given instances. |
1446 | 526 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
527 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
528 |
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
|
529 |
given, get status information about all registered instances. |
0 | 530 |
""" |
531 |
name = 'status' |
|
532 |
options = () |
|
533 |
||
1132 | 534 |
@staticmethod |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
535 |
def status_instance(appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
536 |
"""print running status information for an instance""" |
1132 | 537 |
for mode in cwcfg.possible_configurations(appid): |
538 |
config = cwcfg.config_for(appid, mode) |
|
0 | 539 |
print '[%s-%s]' % (appid, mode), |
540 |
try: |
|
541 |
pidf = config['pid-file'] |
|
542 |
except KeyError: |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
543 |
print 'buggy instance, pid file not specified' |
0 | 544 |
continue |
545 |
if not exists(pidf): |
|
546 |
print "doesn't seem to be running" |
|
547 |
continue |
|
548 |
pid = int(open(pidf).read().strip()) |
|
549 |
# trick to guess whether or not the process is running |
|
550 |
try: |
|
551 |
getpgid(pid) |
|
552 |
except OSError: |
|
553 |
print "should be running with pid %s but the process can not be found" % pid |
|
554 |
continue |
|
555 |
print "running with pid %s" % (pid) |
|
556 |
||
557 |
||
3180
6bab5746ebf5
[c-c] fix start/restart commands
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2905
diff
changeset
|
558 |
class UpgradeInstanceCommand(InstanceCommandFork): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
559 |
"""Upgrade an instance after cubicweb and/or component(s) upgrade. |
0 | 560 |
|
561 |
For repository update, you will be prompted for a login / password to use |
|
562 |
to connect to the system database. For some upgrades, the given user |
|
563 |
should have create or alter table permissions. |
|
564 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
565 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
566 |
identifiers of the instances to upgrade. If no instance is |
0 | 567 |
given, upgrade them all. |
568 |
""" |
|
569 |
name = 'upgrade' |
|
570 |
actionverb = 'upgraded' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
571 |
options = InstanceCommand.options + ( |
0 | 572 |
('force-componant-version', |
573 |
{'short': 't', 'type' : 'csv', 'metavar': 'cube1=X.Y.Z,cube2=X.Y.Z', |
|
574 |
'default': None, |
|
575 |
'help': 'force migration from the indicated version for the specified cube.'}), |
|
576 |
('force-cubicweb-version', |
|
577 |
{'short': 'e', 'type' : 'string', 'metavar': 'X.Y.Z', |
|
578 |
'default': None, |
|
579 |
'help': 'force migration from the indicated cubicweb version.'}), |
|
1446 | 580 |
|
0 | 581 |
('fs-only', |
582 |
{'short': 's', 'action' : 'store_true', |
|
583 |
'default': False, |
|
584 |
'help': 'only upgrade files on the file system, not the database.'}), |
|
585 |
||
586 |
('nostartstop', |
|
587 |
{'short': 'n', 'action' : 'store_true', |
|
588 |
'default': False, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
589 |
'help': 'don\'t try to stop instance before migration and to restart it after.'}), |
1446 | 590 |
|
0 | 591 |
('verbosity', |
592 |
{'short': 'v', 'type' : 'int', 'metavar': '<0..2>', |
|
593 |
'default': 1, |
|
594 |
'help': "0: no confirmation, 1: only main commands confirmed, 2 ask \ |
|
595 |
for everything."}), |
|
1446 | 596 |
|
0 | 597 |
('backup-db', |
598 |
{'short': 'b', 'type' : 'yn', 'metavar': '<y or n>', |
|
599 |
'default': None, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
600 |
'help': "Backup the instance database before upgrade.\n"\ |
0 | 601 |
"If the option is ommitted, confirmation will be ask.", |
602 |
}), |
|
603 |
||
604 |
('ext-sources', |
|
605 |
{'short': 'E', 'type' : 'csv', 'metavar': '<sources>', |
|
606 |
'default': None, |
|
607 |
'help': "For multisources instances, specify to which sources the \ |
|
608 |
repository should connect to for upgrading. When unspecified or 'migration' is \ |
|
609 |
given, appropriate sources for migration will be automatically selected \ |
|
610 |
(recommended). If 'all' is given, will connect to all defined sources.", |
|
611 |
}), |
|
612 |
) |
|
613 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
614 |
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
|
615 |
print '\n' + underline_title('Upgrading the instance %s' % appid) |
0 | 616 |
from logilab.common.changelog import Version |
1132 | 617 |
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
|
618 |
config.repairing = True # notice we're not starting the server |
0 | 619 |
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
|
620 |
try: |
054bb575c013
take care, self.config may not be a server config
sylvain.thenault@logilab.fr
parents:
1015
diff
changeset
|
621 |
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
|
622 |
except AttributeError: |
054bb575c013
take care, self.config may not be a server config
sylvain.thenault@logilab.fr
parents:
1015
diff
changeset
|
623 |
# not a server config |
054bb575c013
take care, self.config may not be a server config
sylvain.thenault@logilab.fr
parents:
1015
diff
changeset
|
624 |
pass |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
625 |
# get instance and installed versions for the server and the componants |
0 | 626 |
mih = config.migration_handler() |
627 |
repo = mih.repo_connect() |
|
628 |
vcconf = repo.get_versions() |
|
629 |
if self.config.force_componant_version: |
|
630 |
packversions = {} |
|
631 |
for vdef in self.config.force_componant_version: |
|
632 |
componant, version = vdef.split('=') |
|
633 |
packversions[componant] = Version(version) |
|
634 |
vcconf.update(packversions) |
|
635 |
toupgrade = [] |
|
636 |
for cube in config.cubes(): |
|
637 |
installedversion = config.cube_version(cube) |
|
638 |
try: |
|
639 |
applversion = vcconf[cube] |
|
640 |
except KeyError: |
|
641 |
config.error('no version information for %s' % cube) |
|
642 |
continue |
|
643 |
if installedversion > applversion: |
|
644 |
toupgrade.append( (cube, applversion, installedversion) ) |
|
1446 | 645 |
cubicwebversion = config.cubicweb_version() |
0 | 646 |
if self.config.force_cubicweb_version: |
647 |
applcubicwebversion = Version(self.config.force_cubicweb_version) |
|
648 |
vcconf['cubicweb'] = applcubicwebversion |
|
649 |
else: |
|
650 |
applcubicwebversion = vcconf.get('cubicweb') |
|
651 |
if cubicwebversion > applcubicwebversion: |
|
2275
bc0bed0616a3
fix #344387, remember upgraded version step by step
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2156
diff
changeset
|
652 |
toupgrade.append(('cubicweb', applcubicwebversion, cubicwebversion)) |
0 | 653 |
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
|
654 |
print '-> no software migration needed for instance %s.' % appid |
0 | 655 |
return |
656 |
for cube, fromversion, toversion in toupgrade: |
|
2532
f7ca29d75183
[cleanup] improve dialog message consistency
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2512
diff
changeset
|
657 |
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
|
658 |
# 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
|
659 |
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
|
660 |
StopInstanceCommand().stop_instance(appid) |
0 | 661 |
# run cubicweb/componants migration scripts |
662 |
mih.migrate(vcconf, reversed(toupgrade), self.config) |
|
663 |
# rewrite main configuration file |
|
664 |
mih.rewrite_configuration() |
|
665 |
# handle i18n upgrade: |
|
666 |
# * install new languages |
|
667 |
# * recompile catalogs |
|
668 |
# in the first componant given |
|
669 |
from cubicweb.common import i18n |
|
1132 | 670 |
templdir = cwcfg.cube_dir(config.cubes()[0]) |
0 | 671 |
langs = [lang for lang, _ in i18n.available_catalogs(join(templdir, 'i18n'))] |
672 |
errors = config.i18ncompile(langs) |
|
673 |
if errors: |
|
674 |
print '\n'.join(errors) |
|
2743
b0e79a77ad67
[c-c] fix confirm
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2654
diff
changeset
|
675 |
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
|
676 |
'continue anyway ?'): |
2512
106b2a05dc88
[cleanup] started to improve cubicweb-ctl dialog messages consistency
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2489
diff
changeset
|
677 |
print '-> migration not completed.' |
0 | 678 |
return |
679 |
mih.shutdown() |
|
680 |
print |
|
2512
106b2a05dc88
[cleanup] started to improve cubicweb-ctl dialog messages consistency
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2489
diff
changeset
|
681 |
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
|
682 |
if not (CWDEV or self.config.nostartstop): |
3190
75cf006babe4
another friend
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3188
diff
changeset
|
683 |
StartInstanceCommand().start_instance(appid) |
0 | 684 |
print |
685 |
||
686 |
||
687 |
class ShellCommand(Command): |
|
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
688 |
"""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
|
689 |
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
|
690 |
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
|
691 |
in batch mode. |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
692 |
|
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
693 |
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
|
694 |
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
|
695 |
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
|
696 |
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
|
697 |
available. |
0 | 698 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
699 |
<instance> |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
700 |
the identifier of the instance to connect. |
0 | 701 |
""" |
702 |
name = 'shell' |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
703 |
arguments = '<instance> [batch command file]' |
0 | 704 |
options = ( |
705 |
('system-only', |
|
706 |
{'short': 'S', 'action' : 'store_true', |
|
707 |
'help': 'only connect to the system source when the instance is ' |
|
708 |
'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
|
709 |
'--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
|
710 |
'group': 'local' |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
711 |
}), |
1446 | 712 |
|
0 | 713 |
('ext-sources', |
714 |
{'short': 'E', 'type' : 'csv', 'metavar': '<sources>', |
|
715 |
'help': "For multisources instances, specify to which sources the \ |
|
716 |
repository should connect to for upgrading. When unspecified or 'all' given, \ |
|
717 |
will connect to all defined sources. If 'migration' is given, appropriate \ |
|
718 |
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
|
719 |
'group': 'local' |
0 | 720 |
}), |
1446 | 721 |
|
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
|
722 |
('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
|
723 |
{'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
|
724 |
'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
|
725 |
'group': 'local' |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
726 |
}), |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
727 |
|
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
728 |
('pyro', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
729 |
{'short': 'P', 'action' : 'store_true', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
730 |
'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
|
731 |
'group': 'remote', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
732 |
}), |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
733 |
('pyro-ns-host', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
734 |
{'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
|
735 |
'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
|
736 |
'using a broadcast query.', |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
737 |
'group': 'remote' |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
738 |
}), |
0 | 739 |
) |
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
|
740 |
|
0 | 741 |
def run(self, args): |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
742 |
appid = pop_arg(args, 99, msg="No instance specified !") |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
743 |
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
|
744 |
from cubicweb import AuthenticationError |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
745 |
from cubicweb.dbapi import connect |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
746 |
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
|
747 |
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
|
748 |
while True: |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
749 |
try: |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
750 |
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
|
751 |
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
|
752 |
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
|
753 |
except AuthenticationError, ex: |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
754 |
print ex |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
755 |
except (KeyboardInterrupt, EOFError): |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
756 |
print |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
757 |
sys.exit(0) |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
758 |
else: |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
759 |
break |
78596919ede3
[c-c] fixes for shell w/ pyro instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3700
diff
changeset
|
760 |
cnx.load_appobjects() |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
761 |
repo = cnx._repo |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
762 |
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
|
763 |
# 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
|
764 |
schema=1) |
0 | 765 |
else: |
3700
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
766 |
config = cwcfg.config_for(appid) |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
767 |
if self.config.ext_sources: |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
768 |
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
|
769 |
sources = self.config.ext_sources |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
770 |
elif self.config.system_only: |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
771 |
sources = ('system',) |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
772 |
else: |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
773 |
sources = ('all',) |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
774 |
config.set_sources_mode(sources) |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
775 |
config.repairing = self.config.force |
fd550e4dc515
#481017: cubicweb-ctl shell on remote instance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
776 |
mih = config.migration_handler() |
3709
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
777 |
try: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
778 |
if args: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
779 |
for arg in args: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
780 |
mih.process_script(arg) |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
781 |
else: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
782 |
mih.interactive_shell() |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
783 |
finally: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
784 |
if not self.config.pyro: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
785 |
mih.shutdown() |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
786 |
else: |
e67ade20bf80
properly close remote connections
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3707
diff
changeset
|
787 |
cnx.close() |
0 | 788 |
|
789 |
||
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
790 |
class RecompileInstanceCatalogsCommand(InstanceCommand): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
791 |
"""Recompile i18n catalogs for instances. |
1446 | 792 |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
793 |
<instance>... |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
794 |
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
|
795 |
given, recompile for all registered instances. |
0 | 796 |
""" |
1898
39b37f90a8a4
[cw-ctl] rename i18n commands (see #342889)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1477
diff
changeset
|
797 |
name = 'i18ninstance' |
1132 | 798 |
|
799 |
@staticmethod |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
800 |
def i18ninstance_instance(appid): |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
801 |
"""recompile instance's messages catalogs""" |
1132 | 802 |
config = cwcfg.config_for(appid) |
0 | 803 |
try: |
804 |
config.bootstrap_cubes() |
|
805 |
except IOError, ex: |
|
806 |
import errno |
|
807 |
if ex.errno != errno.ENOENT: |
|
808 |
raise |
|
809 |
# 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
|
810 |
# 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
|
811 |
config.repairing = True |
0 | 812 |
# create an in-memory repository, will call config.init_cubes() |
813 |
config.repository() |
|
814 |
except AttributeError: |
|
815 |
# web only config |
|
816 |
config.init_cubes(config.repository().get_cubes()) |
|
817 |
errors = config.i18ncompile() |
|
818 |
if errors: |
|
819 |
print '\n'.join(errors) |
|
820 |
||
821 |
||
822 |
class ListInstancesCommand(Command): |
|
823 |
"""list available instances, useful for bash completion.""" |
|
824 |
name = 'listinstances' |
|
825 |
hidden = True |
|
1446 | 826 |
|
0 | 827 |
def run(self, args): |
828 |
"""run the command with its specific arguments""" |
|
1132 | 829 |
regdir = cwcfg.registry_dir() |
0 | 830 |
for appid in sorted(listdir(regdir)): |
831 |
print appid |
|
832 |
||
833 |
||
834 |
class ListCubesCommand(Command): |
|
835 |
"""list available componants, useful for bash completion.""" |
|
836 |
name = 'listcubes' |
|
837 |
hidden = True |
|
1446 | 838 |
|
0 | 839 |
def run(self, args): |
840 |
"""run the command with its specific arguments""" |
|
1132 | 841 |
for cube in cwcfg.available_cubes(): |
0 | 842 |
print cube |
843 |
||
844 |
register_commands((ListCommand, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
845 |
CreateInstanceCommand, |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
846 |
DeleteInstanceCommand, |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
847 |
StartInstanceCommand, |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
848 |
StopInstanceCommand, |
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
849 |
RestartInstanceCommand, |
0 | 850 |
ReloadConfigurationCommand, |
851 |
StatusCommand, |
|
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
852 |
UpgradeInstanceCommand, |
0 | 853 |
ShellCommand, |
2476
1294a6bdf3bf
application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2473
diff
changeset
|
854 |
RecompileInstanceCatalogsCommand, |
0 | 855 |
ListInstancesCommand, ListCubesCommand, |
856 |
)) |
|
857 |
||
1446 | 858 |
|
0 | 859 |
def run(args): |
860 |
"""command line tool""" |
|
1132 | 861 |
cwcfg.load_cwctl_plugins() |
0 | 862 |
main_run(args, __doc__) |
863 |
||
864 |
if __name__ == '__main__': |
|
865 |
run(sys.argv[1:]) |