author | Emile Anclin <emile.anclin@logilab.fr> |
Thu, 26 Mar 2009 15:13:54 +0100 | |
changeset 1166 | 9c5cc3dc2733 |
parent 1116 | 163e6a65d488 |
child 1188 | 6937dfb242fb |
permissions | -rw-r--r-- |
0 | 1 |
"""additional cubicweb-ctl commands and command handlers for cubicweb and cubicweb's |
2 |
cubes development |
|
3 |
||
4 |
:organization: Logilab |
|
5 |
:copyright: 2001-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
|
6 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
7 |
""" |
|
8 |
__docformat__ = "restructuredtext en" |
|
9 |
||
10 |
import sys |
|
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
11 |
from os import walk, mkdir, chdir, listdir, getcwd |
0 | 12 |
from os.path import join, exists, abspath, basename, normpath, split, isdir |
13 |
||
14 |
||
15 |
from logilab.common import STD_BLACKLIST |
|
16 |
from logilab.common.modutils import get_module_files |
|
17 |
from logilab.common.textutils import get_csv |
|
18 |
||
19 |
from cubicweb import CW_SOFTWARE_ROOT as BASEDIR |
|
20 |
from cubicweb.__pkginfo__ import version as cubicwebversion |
|
21 |
from cubicweb import BadCommandUsage |
|
22 |
from cubicweb.toolsutils import Command, register_commands, confirm, copy_skeleton |
|
23 |
from cubicweb.web.webconfig import WebConfiguration |
|
24 |
from cubicweb.server.serverconfig import ServerConfiguration |
|
25 |
||
26 |
||
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
27 |
class DevCubeConfiguration(ServerConfiguration, WebConfiguration): |
0 | 28 |
"""dummy config to get full library schema and entities""" |
29 |
creating = True |
|
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
30 |
cubicweb_vobject_path = ServerConfiguration.cubicweb_vobject_path | WebConfiguration.cubicweb_vobject_path |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
31 |
cube_vobject_path = ServerConfiguration.cube_vobject_path | WebConfiguration.cube_vobject_path |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
32 |
|
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
33 |
def __init__(self, cube): |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
34 |
super(DevCubeConfiguration, self).__init__(cube) |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
35 |
if cube is None: |
0 | 36 |
self._cubes = () |
37 |
else: |
|
396 | 38 |
self._cubes = self.expand_cubes(self.my_cubes(cube)) |
39 |
||
40 |
def my_cubes(self, cube): |
|
41 |
return (cube,) + self.cube_dependencies(cube) + self.cube_recommends(cube) |
|
42 |
||
0 | 43 |
@property |
44 |
def apphome(self): |
|
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
45 |
return None |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
46 |
def main_config_file(self): |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
47 |
return None |
0 | 48 |
def init_log(self, debug=None): |
49 |
pass |
|
50 |
def load_configuration(self): |
|
51 |
pass |
|
52 |
||
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
53 |
|
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
54 |
class DevDepConfiguration(DevCubeConfiguration): |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
55 |
"""configuration to use to generate cubicweb po files or to use as "library" configuration |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
56 |
to filter out message ids from cubicweb and dependencies of a cube |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
57 |
""" |
396 | 58 |
|
59 |
def my_cubes(self, cube): |
|
60 |
return self.cube_dependencies(cube) + self.cube_recommends(cube) |
|
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
61 |
|
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
62 |
def default_log_file(self): |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
63 |
return None |
0 | 64 |
|
65 |
||
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
66 |
def cleanup_sys_modules(config): |
0 | 67 |
# cleanup sys.modules, required when we're updating multiple cubes |
68 |
for name, mod in sys.modules.items(): |
|
69 |
if mod is None: |
|
70 |
# duh ? logilab.common.os for instance |
|
71 |
del sys.modules[name] |
|
72 |
continue |
|
73 |
if not hasattr(mod, '__file__'): |
|
74 |
continue |
|
75 |
for path in config.vregistry_path(): |
|
76 |
if mod.__file__.startswith(path): |
|
77 |
del sys.modules[name] |
|
78 |
break |
|
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
79 |
|
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
80 |
def generate_schema_pot(w, cubedir=None): |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
81 |
"""generate a pot file with schema specific i18n messages |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
82 |
|
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
83 |
notice that relation definitions description and static vocabulary |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
84 |
should be marked using '_' and extracted using xgettext |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
85 |
""" |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
86 |
from cubicweb.cwvreg import CubicWebRegistry |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
87 |
cube = cubedir and split(cubedir)[-1] |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
88 |
config = DevDepConfiguration(cube) |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
89 |
cleanup_sys_modules(config) |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
90 |
if cubedir: |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
91 |
libschema = config.load_schema() |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
92 |
config = DevCubeConfiguration(cube) |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
93 |
schema = config.load_schema() |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
94 |
else: |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
95 |
schema = config.load_schema() |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
96 |
libschema = None |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
97 |
config.cleanup_interface_sobjects = False |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
98 |
vreg = CubicWebRegistry(config) |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
99 |
# set_schema triggers objects registrations |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
100 |
vreg.set_schema(schema) |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
101 |
w(DEFAULT_POT_HEAD) |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
102 |
_generate_schema_pot(w, vreg, schema, libschema=libschema, cube=cube) |
0 | 103 |
|
104 |
def _generate_schema_pot(w, vreg, schema, libschema=None, cube=None): |
|
105 |
from mx.DateTime import now |
|
106 |
from cubicweb.common.i18n import add_msg |
|
107 |
w('# schema pot file, generated on %s\n' % now().strftime('%Y-%m-%d %H:%M:%S')) |
|
108 |
w('# \n') |
|
109 |
w('# singular and plural forms for each entity type\n') |
|
110 |
w('\n') |
|
111 |
if libschema is not None: |
|
112 |
entities = [e for e in schema.entities() if not e in libschema] |
|
113 |
else: |
|
114 |
entities = schema.entities() |
|
115 |
done = set() |
|
116 |
for eschema in sorted(entities): |
|
117 |
etype = eschema.type |
|
118 |
add_msg(w, etype) |
|
119 |
add_msg(w, '%s_plural' % etype) |
|
120 |
if not eschema.is_final(): |
|
121 |
add_msg(w, 'This %s' % etype) |
|
122 |
add_msg(w, 'New %s' % etype) |
|
123 |
add_msg(w, 'add a %s' % etype) |
|
124 |
add_msg(w, 'remove this %s' % etype) |
|
125 |
if eschema.description and not eschema.description in done: |
|
126 |
done.add(eschema.description) |
|
127 |
add_msg(w, eschema.description) |
|
128 |
w('# subject and object forms for each relation type\n') |
|
129 |
w('# (no object form for final relation types)\n') |
|
130 |
w('\n') |
|
131 |
if libschema is not None: |
|
132 |
relations = [r for r in schema.relations() if not r in libschema] |
|
133 |
else: |
|
134 |
relations = schema.relations() |
|
135 |
for rschema in sorted(set(relations)): |
|
136 |
rtype = rschema.type |
|
137 |
add_msg(w, rtype) |
|
57
3ab952845448
[devctl] fix bug in i18nlibupdate
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
138 |
done.add(rtype) |
0 | 139 |
if not (schema.rschema(rtype).is_final() or rschema.symetric): |
140 |
add_msg(w, '%s_object' % rtype) |
|
141 |
if rschema.description and rschema.description not in done: |
|
142 |
done.add(rschema.description) |
|
143 |
add_msg(w, rschema.description) |
|
144 |
w('# add related box generated message\n') |
|
145 |
w('\n') |
|
146 |
for eschema in schema.entities(): |
|
147 |
if eschema.is_final(): |
|
148 |
continue |
|
149 |
entity = vreg.etype_class(eschema)(None, None) |
|
150 |
for x, rschemas in (('subject', eschema.subject_relations()), |
|
151 |
('object', eschema.object_relations())): |
|
152 |
for rschema in rschemas: |
|
153 |
if rschema.is_final(): |
|
154 |
continue |
|
155 |
for teschema in rschema.targets(eschema, x): |
|
156 |
if defined_in_library(libschema, eschema, rschema, teschema, x): |
|
157 |
continue |
|
158 |
if entity.relation_mode(rschema.type, teschema.type, x) == 'create': |
|
159 |
if x == 'subject': |
|
160 |
label = 'add %s %s %s %s' % (eschema, rschema, teschema, x) |
|
161 |
label2 = "creating %s (%s %%(linkto)s %s %s)" % (teschema, eschema, rschema, teschema) |
|
162 |
else: |
|
163 |
label = 'add %s %s %s %s' % (teschema, rschema, eschema, x) |
|
164 |
label2 = "creating %s (%s %s %s %%(linkto)s)" % (teschema, teschema, rschema, eschema) |
|
165 |
add_msg(w, label) |
|
166 |
add_msg(w, label2) |
|
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
167 |
cube = (cube and 'cubes.%s.' % cube or 'cubicweb.') |
0 | 168 |
done = set() |
169 |
for reg, objdict in vreg.items(): |
|
170 |
for objects in objdict.values(): |
|
171 |
for obj in objects: |
|
172 |
objid = '%s_%s' % (reg, obj.id) |
|
173 |
if objid in done: |
|
174 |
continue |
|
175 |
if obj.__module__.startswith(cube) and obj.property_defs: |
|
176 |
add_msg(w, '%s_description' % objid) |
|
177 |
add_msg(w, objid) |
|
178 |
done.add(objid) |
|
374
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
179 |
|
0 | 180 |
|
181 |
def defined_in_library(libschema, etype, rtype, tetype, x): |
|
182 |
"""return true if the given relation definition exists in cubicweb's library""" |
|
183 |
if libschema is None: |
|
184 |
return False |
|
185 |
if x == 'subject': |
|
186 |
subjtype, objtype = etype, tetype |
|
187 |
else: |
|
188 |
subjtype, objtype = tetype, etype |
|
189 |
try: |
|
190 |
return libschema.rschema(rtype).has_rdef(subjtype, objtype) |
|
191 |
except KeyError: |
|
192 |
return False |
|
193 |
||
194 |
||
155
9ed6db94a087
spanish is now a supported language
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
133
diff
changeset
|
195 |
LANGS = ('en', 'fr', 'es') |
0 | 196 |
I18NDIR = join(BASEDIR, 'i18n') |
197 |
DEFAULT_POT_HEAD = r'''msgid "" |
|
198 |
msgstr "" |
|
199 |
"Project-Id-Version: cubicweb %s\n" |
|
200 |
"PO-Revision-Date: 2008-03-28 18:14+0100\n" |
|
201 |
"Last-Translator: Logilab Team <contact@logilab.fr>\n" |
|
202 |
"Language-Team: fr <contact@logilab.fr>\n" |
|
203 |
"MIME-Version: 1.0\n" |
|
204 |
"Content-Type: text/plain; charset=UTF-8\n" |
|
205 |
"Content-Transfer-Encoding: 8bit\n" |
|
206 |
"Generated-By: cubicweb-devtools\n" |
|
207 |
"Plural-Forms: nplurals=2; plural=(n > 1);\n" |
|
208 |
||
209 |
''' % cubicwebversion |
|
210 |
||
211 |
||
212 |
class UpdateCubicWebCatalogCommand(Command): |
|
213 |
"""Update i18n catalogs for cubicweb library. |
|
214 |
|
|
215 |
It will regenerate cubicweb/i18n/xx.po files. You'll have then to edit those |
|
216 |
files to add translations of newly added messages. |
|
217 |
""" |
|
218 |
name = 'i18nlibupdate' |
|
219 |
||
220 |
def run(self, args): |
|
221 |
"""run the command with its specific arguments""" |
|
222 |
if args: |
|
223 |
raise BadCommandUsage('Too much arguments') |
|
224 |
import shutil |
|
225 |
from tempfile import mktemp |
|
226 |
import yams |
|
227 |
from logilab.common.fileutils import ensure_fs_mode |
|
58
c7c22b210372
only try to internationalize our own js files
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
57
diff
changeset
|
228 |
from logilab.common.shellutils import globfind, find, rm |
0 | 229 |
from cubicweb.common.i18n import extract_from_tal, execute |
230 |
tempdir = mktemp() |
|
231 |
mkdir(tempdir) |
|
232 |
potfiles = [join(I18NDIR, 'entities.pot')] |
|
233 |
print '******** extract schema messages' |
|
234 |
schemapot = join(tempdir, 'schema.pot') |
|
235 |
potfiles.append(schemapot) |
|
236 |
# explicit close necessary else the file may not be yet flushed when |
|
237 |
# we'll using it below |
|
238 |
schemapotstream = file(schemapot, 'w') |
|
239 |
generate_schema_pot(schemapotstream.write, cubedir=None) |
|
240 |
schemapotstream.close() |
|
241 |
print '******** extract TAL messages' |
|
242 |
tali18nfile = join(tempdir, 'tali18n.py') |
|
243 |
extract_from_tal(find(join(BASEDIR, 'web'), ('.py', '.pt')), tali18nfile) |
|
244 |
print '******** .pot files generation' |
|
61
081078d5b422
rename one of the generated pot files (cubicweb pycubicweb.pot) to avoid problems when msgcats overwrites cubicweb.pot
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
60
diff
changeset
|
245 |
for id, files, lang in [('pycubicweb', get_module_files(BASEDIR) + list(globfind(join(BASEDIR, 'misc', 'migration'), '*.py')), None), |
58
c7c22b210372
only try to internationalize our own js files
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
57
diff
changeset
|
246 |
('schemadescr', globfind(join(BASEDIR, 'schemas'), '*.py'), None), |
0 | 247 |
('yams', get_module_files(yams.__path__[0]), None), |
248 |
('tal', [tali18nfile], None), |
|
58
c7c22b210372
only try to internationalize our own js files
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
57
diff
changeset
|
249 |
('js', globfind(join(BASEDIR, 'web'), 'cub*.js'), 'java'), |
0 | 250 |
]: |
60
dc90556488d8
oops, bad changeset review, revert debug changes
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
58
diff
changeset
|
251 |
cmd = 'xgettext --no-location --omit-header -k_ -o %s %s' |
0 | 252 |
if lang is not None: |
253 |
cmd += ' -L %s' % lang |
|
254 |
potfiles.append(join(tempdir, '%s.pot' % id)) |
|
255 |
execute(cmd % (potfiles[-1], ' '.join(files))) |
|
256 |
print '******** merging .pot files' |
|
257 |
cubicwebpot = join(tempdir, 'cubicweb.pot') |
|
258 |
execute('msgcat %s > %s' % (' '.join(potfiles), cubicwebpot)) |
|
259 |
print '******** merging main pot file with existing translations' |
|
260 |
chdir(I18NDIR) |
|
261 |
toedit = [] |
|
262 |
for lang in LANGS: |
|
263 |
target = '%s.po' % lang |
|
264 |
execute('msgmerge -N --sort-output %s %s > %snew' % (target, cubicwebpot, target)) |
|
265 |
ensure_fs_mode(target) |
|
266 |
shutil.move('%snew' % target, target) |
|
267 |
toedit.append(abspath(target)) |
|
268 |
# cleanup |
|
60
dc90556488d8
oops, bad changeset review, revert debug changes
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
58
diff
changeset
|
269 |
rm(tempdir) |
0 | 270 |
# instructions pour la suite |
271 |
print '*' * 72 |
|
272 |
print 'you can now edit the following files:' |
|
273 |
print '* ' + '\n* '.join(toedit) |
|
274 |
print |
|
275 |
print "then you'll have to update cubes catalogs using the i18nupdate command" |
|
276 |
||
277 |
||
278 |
class UpdateTemplateCatalogCommand(Command): |
|
279 |
"""Update i18n catalogs for cubes. If no cube is specified, update |
|
280 |
catalogs of all registered cubes. |
|
281 |
""" |
|
282 |
name = 'i18nupdate' |
|
283 |
arguments = '[<cube>...]' |
|
284 |
||
285 |
def run(self, args): |
|
286 |
"""run the command with its specific arguments""" |
|
287 |
if args: |
|
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
396
diff
changeset
|
288 |
cubes = [DevCubeConfiguration.cube_dir(cube) for cube in args] |
0 | 289 |
else: |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
396
diff
changeset
|
290 |
cubes = [DevCubeConfiguration.cube_dir(cube) for cube in DevCubeConfiguration.available_cubes()] |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
396
diff
changeset
|
291 |
cubes = [cubepath for cubepath in cubes if exists(join(cubepath, 'i18n'))] |
0 | 292 |
update_cubes_catalogs(cubes) |
293 |
||
294 |
def update_cubes_catalogs(cubes): |
|
295 |
import shutil |
|
296 |
from tempfile import mktemp |
|
297 |
from logilab.common.fileutils import ensure_fs_mode |
|
298 |
from logilab.common.shellutils import find, rm |
|
299 |
from cubicweb.common.i18n import extract_from_tal, execute |
|
300 |
toedit = [] |
|
301 |
for cubedir in cubes: |
|
302 |
cube = basename(normpath(cubedir)) |
|
303 |
if not isdir(cubedir): |
|
304 |
print 'unknown cube', cube |
|
305 |
continue |
|
306 |
tempdir = mktemp() |
|
307 |
mkdir(tempdir) |
|
308 |
print '*' * 72 |
|
309 |
print 'updating %s cube...' % cube |
|
310 |
chdir(cubedir) |
|
311 |
potfiles = [join('i18n', scfile) for scfile in ('entities.pot',) |
|
312 |
if exists(join('i18n', scfile))] |
|
313 |
print '******** extract schema messages' |
|
314 |
schemapot = join(tempdir, 'schema.pot') |
|
315 |
potfiles.append(schemapot) |
|
316 |
# explicit close necessary else the file may not be yet flushed when |
|
317 |
# we'll using it below |
|
318 |
schemapotstream = file(schemapot, 'w') |
|
319 |
generate_schema_pot(schemapotstream.write, cubedir) |
|
320 |
schemapotstream.close() |
|
321 |
print '******** extract TAL messages' |
|
322 |
tali18nfile = join(tempdir, 'tali18n.py') |
|
323 |
extract_from_tal(find('.', ('.py', '.pt'), blacklist=STD_BLACKLIST+('test',)), tali18nfile) |
|
324 |
print '******** extract Javascript messages' |
|
58
c7c22b210372
only try to internationalize our own js files
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
57
diff
changeset
|
325 |
jsfiles = [jsfile for jsfile in find('.', '.js') if basename(jsfile).startswith('cub')] |
0 | 326 |
if jsfiles: |
327 |
tmppotfile = join(tempdir, 'js.pot') |
|
328 |
execute('xgettext --no-location --omit-header -k_ -L java --from-code=utf-8 -o %s %s' |
|
329 |
% (tmppotfile, ' '.join(jsfiles))) |
|
330 |
# no pot file created if there are no string to translate |
|
331 |
if exists(tmppotfile): |
|
332 |
potfiles.append(tmppotfile) |
|
333 |
print '******** create cube specific catalog' |
|
334 |
tmppotfile = join(tempdir, 'generated.pot') |
|
335 |
cubefiles = find('.', '.py', blacklist=STD_BLACKLIST+('test',)) |
|
336 |
cubefiles.append(tali18nfile) |
|
337 |
execute('xgettext --no-location --omit-header -k_ -o %s %s' |
|
338 |
% (tmppotfile, ' '.join(cubefiles))) |
|
339 |
if exists(tmppotfile): # doesn't exists of no translation string found |
|
340 |
potfiles.append(tmppotfile) |
|
341 |
potfile = join(tempdir, 'cube.pot') |
|
342 |
print '******** merging .pot files' |
|
343 |
execute('msgcat %s > %s' % (' '.join(potfiles), potfile)) |
|
344 |
print '******** merging main pot file with existing translations' |
|
345 |
chdir('i18n') |
|
346 |
for lang in LANGS: |
|
347 |
print '****', lang |
|
348 |
cubepo = '%s.po' % lang |
|
349 |
if not exists(cubepo): |
|
350 |
shutil.copy(potfile, cubepo) |
|
351 |
else: |
|
352 |
execute('msgmerge -N -s %s %s > %snew' % (cubepo, potfile, cubepo)) |
|
353 |
ensure_fs_mode(cubepo) |
|
354 |
shutil.move('%snew' % cubepo, cubepo) |
|
355 |
toedit.append(abspath(cubepo)) |
|
356 |
# cleanup |
|
357 |
rm(tempdir) |
|
358 |
# instructions pour la suite |
|
359 |
print '*' * 72 |
|
360 |
print 'you can now edit the following files:' |
|
361 |
print '* ' + '\n* '.join(toedit) |
|
362 |
||
363 |
||
364 |
class LiveServerCommand(Command): |
|
365 |
"""Run a server from within a cube directory. |
|
366 |
""" |
|
367 |
name = 'live-server' |
|
368 |
arguments = '' |
|
369 |
options = () |
|
370 |
||
371 |
def run(self, args): |
|
372 |
"""run the command with its specific arguments""" |
|
373 |
from cubicweb.devtools.livetest import runserver |
|
374 |
runserver() |
|
375 |
||
376 |
||
132
561671b87c22
rename NewTemplateCommand class into NewCubeCommand
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
61
diff
changeset
|
377 |
class NewCubeCommand(Command): |
0 | 378 |
"""Create a new cube. |
379 |
||
380 |
<cubename> |
|
381 |
the name of the new cube |
|
382 |
""" |
|
383 |
name = 'newcube' |
|
384 |
arguments = '<cubename>' |
|
385 |
||
133
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
386 |
options = ( |
1106
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
387 |
("directory", |
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
388 |
{'short': 'd', 'type' : 'string', 'metavar': '<cubes directory>', |
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
389 |
'help': 'directory where the new cube should be created', |
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
390 |
} |
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
391 |
), |
133
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
392 |
("verbose", |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
393 |
{'short': 'v', 'type' : 'yn', 'metavar': '<verbose>', |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
394 |
'default': 'n', |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
395 |
'help': 'verbose mode: will ask all possible configuration questions', |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
396 |
} |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
397 |
), |
365
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
398 |
("author", |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
399 |
{'short': 'a', 'type' : 'string', 'metavar': '<author>', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
400 |
'default': 'LOGILAB S.A. (Paris, FRANCE)', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
401 |
'help': 'cube author', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
402 |
} |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
403 |
), |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
404 |
("author-email", |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
405 |
{'short': 'e', 'type' : 'string', 'metavar': '<email>', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
406 |
'default': 'contact@logilab.fr', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
407 |
'help': 'cube author\'s email', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
408 |
} |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
409 |
), |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
410 |
("author-web-site", |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
411 |
{'short': 'w', 'type' : 'string', 'metavar': '<web site>', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
412 |
'default': 'http://www.logilab.fr', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
413 |
'help': 'cube author\'s web site', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
414 |
} |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
415 |
), |
133
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
416 |
) |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
417 |
|
0 | 418 |
|
419 |
def run(self, args): |
|
420 |
if len(args) != 1: |
|
421 |
raise BadCommandUsage("exactly one argument (cube name) is expected") |
|
422 |
cubename, = args |
|
264
6eb0725d509d
packaging fix: distribute skeleton
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
155
diff
changeset
|
423 |
#if ServerConfiguration.mode != "dev": |
6eb0725d509d
packaging fix: distribute skeleton
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
155
diff
changeset
|
424 |
# self.fail("you can only create new cubes in development mode") |
133
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
425 |
verbose = self.get('verbose') |
1106
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
426 |
cubesdir = self.get('directory') |
1116
163e6a65d488
fix dumb name error, should call cubes_search_path, not cubes_path
sylvain.thenault@logilab.fr
parents:
1106
diff
changeset
|
427 |
if not cubesdir: |
163e6a65d488
fix dumb name error, should call cubes_search_path, not cubes_path
sylvain.thenault@logilab.fr
parents:
1106
diff
changeset
|
428 |
cubespath = ServerConfiguration.cubes_search_path() |
1106
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
429 |
if len(cubespath) > 1: |
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
430 |
raise BadCommandUsage("can't guess directory where to put the new cube." |
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
431 |
" Please specify it using the --directory option") |
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
432 |
cubesdir = cubespath[0] |
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
433 |
if not isdir(cubesdir): |
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
434 |
print "creating cubes directory", cubesdir |
0 | 435 |
try: |
1106
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
436 |
mkdir(cubesdir) |
0 | 437 |
except OSError, err: |
1116
163e6a65d488
fix dumb name error, should call cubes_search_path, not cubes_path
sylvain.thenault@logilab.fr
parents:
1106
diff
changeset
|
438 |
self.fail("failed to create directory %r\n(%s)" % (cubesdir, err)) |
1106
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
439 |
cubedir = join(cubesdir, cubename) |
0 | 440 |
if exists(cubedir): |
441 |
self.fail("%s already exists !" % (cubedir)) |
|
442 |
skeldir = join(BASEDIR, 'skeleton') |
|
133
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
443 |
if verbose: |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
444 |
distname = raw_input('Debian name for your cube (just type enter to use the cube name): ').strip() |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
445 |
if not distname: |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
446 |
distname = 'cubicweb-%s' % cubename.lower() |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
447 |
elif not distname.startswith('cubicweb-'): |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
448 |
if confirm('do you mean cubicweb-%s ?' % distname): |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
449 |
distname = 'cubicweb-' + distname |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
450 |
else: |
0 | 451 |
distname = 'cubicweb-%s' % cubename.lower() |
133
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
452 |
|
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
453 |
longdesc = shortdesc = raw_input('Enter a short description for your cube: ') |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
454 |
if verbose: |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
455 |
longdesc = raw_input('Enter a long description (or nothing if you want to reuse the short one): ') |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
456 |
if verbose: |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
457 |
includes = self._ask_for_dependancies() |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
458 |
if len(includes) == 1: |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
459 |
dependancies = '%r,' % includes[0] |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
460 |
else: |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
461 |
dependancies = ', '.join(repr(cube) for cube in includes) |
0 | 462 |
else: |
133
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
463 |
dependancies = '' |
0 | 464 |
from mx.DateTime import now |
465 |
context = {'cubename' : cubename, |
|
466 |
'distname' : distname, |
|
467 |
'shortdesc' : shortdesc, |
|
468 |
'longdesc' : longdesc or shortdesc, |
|
469 |
'dependancies' : dependancies, |
|
470 |
'version' : cubicwebversion, |
|
471 |
'year' : str(now().year), |
|
365
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
472 |
'author': self['author'], |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
473 |
'author-email': self['author-email'], |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
474 |
'author-web-site': self['author-web-site'], |
0 | 475 |
} |
476 |
copy_skeleton(skeldir, cubedir, context) |
|
477 |
||
478 |
def _ask_for_dependancies(self): |
|
479 |
includes = [] |
|
480 |
for stdtype in ServerConfiguration.available_cubes(): |
|
481 |
ans = raw_input("Depends on cube %s? (N/y/s(kip)/t(ype)" |
|
482 |
% stdtype).lower().strip() |
|
483 |
if ans == 'y': |
|
484 |
includes.append(stdtype) |
|
485 |
if ans == 't': |
|
486 |
includes = get_csv(raw_input('type dependancies: ')) |
|
487 |
break |
|
488 |
elif ans == 's': |
|
489 |
break |
|
490 |
return includes |
|
491 |
||
374
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
492 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
493 |
class ExamineLogCommand(Command): |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
494 |
"""Examine a rql log file. |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
495 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
496 |
usage: python exlog.py < rql.log |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
497 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
498 |
will print out the following table |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
499 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
500 |
total execution time || number of occurences || rql query |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
501 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
502 |
sorted by descending total execution time |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
503 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
504 |
chances are the lines at the top are the ones that will bring |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
505 |
the higher benefit after optimisation. Start there. |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
506 |
""" |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
507 |
name = 'exlog' |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
508 |
options = ( |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
509 |
) |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
510 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
511 |
def run(self, args): |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
512 |
if args: |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
513 |
raise BadCommandUsage("no argument expected") |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
514 |
import re |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
515 |
requests = {} |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
516 |
for line in sys.stdin: |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
517 |
if not ' WHERE ' in line: |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
518 |
continue |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
519 |
#sys.stderr.write( line ) |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
520 |
rql, time = line.split('--') |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
521 |
rql = re.sub("(\'\w+': \d*)", '', rql) |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
522 |
req = requests.setdefault(rql, []) |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
523 |
time.strip() |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
524 |
chunks = time.split() |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
525 |
cputime = float(chunks[-3]) |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
526 |
req.append( cputime ) |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
527 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
528 |
stat = [] |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
529 |
for rql, times in requests.items(): |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
530 |
stat.append( (sum(times), len(times), rql) ) |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
531 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
532 |
stat.sort() |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
533 |
stat.reverse() |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
534 |
for time, occ, rql in stat: |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
535 |
print time, occ, rql |
0 | 536 |
|
537 |
register_commands((UpdateCubicWebCatalogCommand, |
|
538 |
UpdateTemplateCatalogCommand, |
|
539 |
LiveServerCommand, |
|
132
561671b87c22
rename NewTemplateCommand class into NewCubeCommand
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
61
diff
changeset
|
540 |
NewCubeCommand, |
374
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
541 |
ExamineLogCommand, |
0 | 542 |
)) |