author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Tue, 17 Feb 2009 23:46:48 +0100 | |
branch | tls-sprint |
changeset 727 | 30fe8f5afbd8 |
parent 396 | 76d593bd4221 |
child 1015 | b5fdad9208f8 |
child 1016 | 26387b836099 |
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""" |
|
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
287 |
CUBEDIR = DevCubeConfiguration.cubes_dir() |
0 | 288 |
if args: |
289 |
cubes = [join(CUBEDIR, app) for app in args] |
|
290 |
else: |
|
291 |
cubes = [join(CUBEDIR, app) for app in listdir(CUBEDIR) |
|
292 |
if exists(join(CUBEDIR, app, 'i18n'))] |
|
293 |
update_cubes_catalogs(cubes) |
|
294 |
||
295 |
def update_cubes_catalogs(cubes): |
|
296 |
import shutil |
|
297 |
from tempfile import mktemp |
|
298 |
from logilab.common.fileutils import ensure_fs_mode |
|
299 |
from logilab.common.shellutils import find, rm |
|
300 |
from cubicweb.common.i18n import extract_from_tal, execute |
|
301 |
toedit = [] |
|
302 |
for cubedir in cubes: |
|
303 |
cube = basename(normpath(cubedir)) |
|
304 |
if not isdir(cubedir): |
|
305 |
print 'unknown cube', cube |
|
306 |
continue |
|
307 |
tempdir = mktemp() |
|
308 |
mkdir(tempdir) |
|
309 |
print '*' * 72 |
|
310 |
print 'updating %s cube...' % cube |
|
311 |
chdir(cubedir) |
|
312 |
potfiles = [join('i18n', scfile) for scfile in ('entities.pot',) |
|
313 |
if exists(join('i18n', scfile))] |
|
314 |
print '******** extract schema messages' |
|
315 |
schemapot = join(tempdir, 'schema.pot') |
|
316 |
potfiles.append(schemapot) |
|
317 |
# explicit close necessary else the file may not be yet flushed when |
|
318 |
# we'll using it below |
|
319 |
schemapotstream = file(schemapot, 'w') |
|
320 |
generate_schema_pot(schemapotstream.write, cubedir) |
|
321 |
schemapotstream.close() |
|
322 |
print '******** extract TAL messages' |
|
323 |
tali18nfile = join(tempdir, 'tali18n.py') |
|
324 |
extract_from_tal(find('.', ('.py', '.pt'), blacklist=STD_BLACKLIST+('test',)), tali18nfile) |
|
325 |
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
|
326 |
jsfiles = [jsfile for jsfile in find('.', '.js') if basename(jsfile).startswith('cub')] |
0 | 327 |
if jsfiles: |
328 |
tmppotfile = join(tempdir, 'js.pot') |
|
329 |
execute('xgettext --no-location --omit-header -k_ -L java --from-code=utf-8 -o %s %s' |
|
330 |
% (tmppotfile, ' '.join(jsfiles))) |
|
331 |
# no pot file created if there are no string to translate |
|
332 |
if exists(tmppotfile): |
|
333 |
potfiles.append(tmppotfile) |
|
334 |
print '******** create cube specific catalog' |
|
335 |
tmppotfile = join(tempdir, 'generated.pot') |
|
336 |
cubefiles = find('.', '.py', blacklist=STD_BLACKLIST+('test',)) |
|
337 |
cubefiles.append(tali18nfile) |
|
338 |
execute('xgettext --no-location --omit-header -k_ -o %s %s' |
|
339 |
% (tmppotfile, ' '.join(cubefiles))) |
|
340 |
if exists(tmppotfile): # doesn't exists of no translation string found |
|
341 |
potfiles.append(tmppotfile) |
|
342 |
potfile = join(tempdir, 'cube.pot') |
|
343 |
print '******** merging .pot files' |
|
344 |
execute('msgcat %s > %s' % (' '.join(potfiles), potfile)) |
|
345 |
print '******** merging main pot file with existing translations' |
|
346 |
chdir('i18n') |
|
347 |
for lang in LANGS: |
|
348 |
print '****', lang |
|
349 |
cubepo = '%s.po' % lang |
|
350 |
if not exists(cubepo): |
|
351 |
shutil.copy(potfile, cubepo) |
|
352 |
else: |
|
353 |
execute('msgmerge -N -s %s %s > %snew' % (cubepo, potfile, cubepo)) |
|
354 |
ensure_fs_mode(cubepo) |
|
355 |
shutil.move('%snew' % cubepo, cubepo) |
|
356 |
toedit.append(abspath(cubepo)) |
|
357 |
# cleanup |
|
358 |
rm(tempdir) |
|
359 |
# instructions pour la suite |
|
360 |
print '*' * 72 |
|
361 |
print 'you can now edit the following files:' |
|
362 |
print '* ' + '\n* '.join(toedit) |
|
363 |
||
364 |
||
365 |
class LiveServerCommand(Command): |
|
366 |
"""Run a server from within a cube directory. |
|
367 |
""" |
|
368 |
name = 'live-server' |
|
369 |
arguments = '' |
|
370 |
options = () |
|
371 |
||
372 |
def run(self, args): |
|
373 |
"""run the command with its specific arguments""" |
|
374 |
from cubicweb.devtools.livetest import runserver |
|
375 |
runserver() |
|
376 |
||
377 |
||
132
561671b87c22
rename NewTemplateCommand class into NewCubeCommand
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
61
diff
changeset
|
378 |
class NewCubeCommand(Command): |
0 | 379 |
"""Create a new cube. |
380 |
||
381 |
<cubename> |
|
382 |
the name of the new cube |
|
383 |
""" |
|
384 |
name = 'newcube' |
|
385 |
arguments = '<cubename>' |
|
386 |
||
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
|
387 |
options = ( |
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
|
388 |
("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
|
389 |
{'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
|
390 |
'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
|
391 |
'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
|
392 |
} |
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 |
), |
365
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
394 |
("author", |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
395 |
{'short': 'a', 'type' : 'string', 'metavar': '<author>', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
396 |
'default': 'LOGILAB S.A. (Paris, FRANCE)', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
397 |
'help': 'cube author', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
398 |
} |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
399 |
), |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
400 |
("author-email", |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
401 |
{'short': 'e', 'type' : 'string', 'metavar': '<email>', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
402 |
'default': 'contact@logilab.fr', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
403 |
'help': 'cube author\'s email', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
404 |
} |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
405 |
), |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
406 |
("author-web-site", |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
407 |
{'short': 'w', 'type' : 'string', 'metavar': '<web site>', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
408 |
'default': 'http://www.logilab.fr', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
409 |
'help': 'cube author\'s web site', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
410 |
} |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
411 |
), |
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
|
412 |
) |
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
|
413 |
|
0 | 414 |
|
415 |
def run(self, args): |
|
416 |
if len(args) != 1: |
|
417 |
raise BadCommandUsage("exactly one argument (cube name) is expected") |
|
418 |
cubename, = args |
|
264
6eb0725d509d
packaging fix: distribute skeleton
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
155
diff
changeset
|
419 |
#if ServerConfiguration.mode != "dev": |
6eb0725d509d
packaging fix: distribute skeleton
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
155
diff
changeset
|
420 |
# 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
|
421 |
verbose = self.get('verbose') |
0 | 422 |
cubedir = ServerConfiguration.CUBES_DIR |
423 |
if not isdir(cubedir): |
|
424 |
print "creating apps directory", cubedir |
|
425 |
try: |
|
426 |
mkdir(cubedir) |
|
427 |
except OSError, err: |
|
428 |
self.fail("failed to create directory %r\n(%s)" % (cubedir, err)) |
|
429 |
cubedir = join(cubedir, cubename) |
|
430 |
if exists(cubedir): |
|
431 |
self.fail("%s already exists !" % (cubedir)) |
|
432 |
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
|
433 |
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
|
434 |
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
|
435 |
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
|
436 |
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
|
437 |
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
|
438 |
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
|
439 |
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
|
440 |
else: |
0 | 441 |
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
|
442 |
|
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 |
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
|
444 |
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
|
445 |
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
|
446 |
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
|
447 |
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
|
448 |
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
|
449 |
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
|
450 |
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
|
451 |
dependancies = ', '.join(repr(cube) for cube in includes) |
0 | 452 |
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
|
453 |
dependancies = '' |
0 | 454 |
from mx.DateTime import now |
455 |
context = {'cubename' : cubename, |
|
456 |
'distname' : distname, |
|
457 |
'shortdesc' : shortdesc, |
|
458 |
'longdesc' : longdesc or shortdesc, |
|
459 |
'dependancies' : dependancies, |
|
460 |
'version' : cubicwebversion, |
|
461 |
'year' : str(now().year), |
|
365
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
462 |
'author': self['author'], |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
463 |
'author-email': self['author-email'], |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
464 |
'author-web-site': self['author-web-site'], |
0 | 465 |
} |
466 |
copy_skeleton(skeldir, cubedir, context) |
|
467 |
||
468 |
def _ask_for_dependancies(self): |
|
469 |
includes = [] |
|
470 |
for stdtype in ServerConfiguration.available_cubes(): |
|
471 |
ans = raw_input("Depends on cube %s? (N/y/s(kip)/t(ype)" |
|
472 |
% stdtype).lower().strip() |
|
473 |
if ans == 'y': |
|
474 |
includes.append(stdtype) |
|
475 |
if ans == 't': |
|
476 |
includes = get_csv(raw_input('type dependancies: ')) |
|
477 |
break |
|
478 |
elif ans == 's': |
|
479 |
break |
|
480 |
return includes |
|
481 |
||
374
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
482 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
483 |
class ExamineLogCommand(Command): |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
484 |
"""Examine a rql log file. |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
485 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
486 |
usage: python exlog.py < rql.log |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
487 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
488 |
will print out the following table |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
489 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
490 |
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
|
491 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
492 |
sorted by descending total execution time |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
493 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
494 |
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
|
495 |
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
|
496 |
""" |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
497 |
name = 'exlog' |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
498 |
options = ( |
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 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
501 |
def run(self, args): |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
502 |
if args: |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
503 |
raise BadCommandUsage("no argument expected") |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
504 |
import re |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
505 |
requests = {} |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
506 |
for line in sys.stdin: |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
507 |
if not ' WHERE ' in line: |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
508 |
continue |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
509 |
#sys.stderr.write( line ) |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
510 |
rql, time = line.split('--') |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
511 |
rql = re.sub("(\'\w+': \d*)", '', rql) |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
512 |
req = requests.setdefault(rql, []) |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
513 |
time.strip() |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
514 |
chunks = time.split() |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
515 |
cputime = float(chunks[-3]) |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
516 |
req.append( cputime ) |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
517 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
518 |
stat = [] |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
519 |
for rql, times in requests.items(): |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
520 |
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
|
521 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
522 |
stat.sort() |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
523 |
stat.reverse() |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
524 |
for time, occ, rql in stat: |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
525 |
print time, occ, rql |
0 | 526 |
|
527 |
register_commands((UpdateCubicWebCatalogCommand, |
|
528 |
UpdateTemplateCatalogCommand, |
|
529 |
LiveServerCommand, |
|
132
561671b87c22
rename NewTemplateCommand class into NewCubeCommand
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
61
diff
changeset
|
530 |
NewCubeCommand, |
374
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
531 |
ExamineLogCommand, |
0 | 532 |
)) |