author | sylvain.thenault@logilab.fr |
Wed, 08 Apr 2009 14:11:34 +0200 | |
branch | tls-sprint |
changeset 1300 | 62d2b890a980 |
parent 1263 | 01152fffd593 |
child 1415 | 98b8e5c627b8 |
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 |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
396
diff
changeset
|
5 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
0 | 6 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
7 |
""" |
|
8 |
__docformat__ = "restructuredtext en" |
|
9 |
||
10 |
import sys |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
396
diff
changeset
|
11 |
from datetime import datetime |
1132 | 12 |
from os import mkdir, chdir, listdir |
0 | 13 |
from os.path import join, exists, abspath, basename, normpath, split, isdir |
14 |
||
15 |
||
16 |
from logilab.common import STD_BLACKLIST |
|
17 |
from logilab.common.modutils import get_module_files |
|
18 |
from logilab.common.textutils import get_csv |
|
1138
22f634977c95
make pylint happy, fix some bugs on the way
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
19 |
from logilab.common.clcommands import register_commands |
0 | 20 |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
396
diff
changeset
|
21 |
from cubicweb import CW_SOFTWARE_ROOT as BASEDIR, BadCommandUsage |
0 | 22 |
from cubicweb.__pkginfo__ import version as cubicwebversion |
1138
22f634977c95
make pylint happy, fix some bugs on the way
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
23 |
from cubicweb.toolsutils import Command, confirm, copy_skeleton |
0 | 24 |
from cubicweb.web.webconfig import WebConfiguration |
25 |
from cubicweb.server.serverconfig import ServerConfiguration |
|
26 |
||
27 |
||
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
28 |
class DevCubeConfiguration(ServerConfiguration, WebConfiguration): |
0 | 29 |
"""dummy config to get full library schema and entities""" |
30 |
creating = True |
|
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
31 |
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
|
32 |
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
|
33 |
|
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
34 |
def __init__(self, cube): |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
35 |
super(DevCubeConfiguration, self).__init__(cube) |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
36 |
if cube is None: |
0 | 37 |
self._cubes = () |
38 |
else: |
|
396 | 39 |
self._cubes = self.expand_cubes(self.my_cubes(cube)) |
40 |
||
41 |
def my_cubes(self, cube): |
|
42 |
return (cube,) + self.cube_dependencies(cube) + self.cube_recommends(cube) |
|
43 |
||
0 | 44 |
@property |
45 |
def apphome(self): |
|
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
46 |
return None |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
47 |
def main_config_file(self): |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
48 |
return None |
0 | 49 |
def init_log(self, debug=None): |
50 |
pass |
|
51 |
def load_configuration(self): |
|
52 |
pass |
|
53 |
||
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
54 |
|
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
55 |
class DevDepConfiguration(DevCubeConfiguration): |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
56 |
"""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
|
57 |
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
|
58 |
""" |
396 | 59 |
|
60 |
def my_cubes(self, cube): |
|
61 |
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
|
62 |
|
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
63 |
def default_log_file(self): |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
64 |
return None |
0 | 65 |
|
66 |
||
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
67 |
def cleanup_sys_modules(config): |
0 | 68 |
# cleanup sys.modules, required when we're updating multiple cubes |
69 |
for name, mod in sys.modules.items(): |
|
70 |
if mod is None: |
|
71 |
# duh ? logilab.common.os for instance |
|
72 |
del sys.modules[name] |
|
73 |
continue |
|
74 |
if not hasattr(mod, '__file__'): |
|
75 |
continue |
|
76 |
for path in config.vregistry_path(): |
|
77 |
if mod.__file__.startswith(path): |
|
78 |
del sys.modules[name] |
|
79 |
break |
|
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
80 |
|
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
81 |
def generate_schema_pot(w, cubedir=None): |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
82 |
"""generate a pot file with schema specific i18n messages |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
83 |
|
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
84 |
notice that relation definitions description and static vocabulary |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
85 |
should be marked using '_' and extracted using xgettext |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
86 |
""" |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
87 |
from cubicweb.cwvreg import CubicWebRegistry |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
88 |
cube = cubedir and split(cubedir)[-1] |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
89 |
config = DevDepConfiguration(cube) |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
90 |
cleanup_sys_modules(config) |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
91 |
if cubedir: |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
92 |
libschema = config.load_schema() |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
93 |
config = DevCubeConfiguration(cube) |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
94 |
schema = config.load_schema() |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
95 |
else: |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
96 |
schema = config.load_schema() |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
97 |
libschema = None |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
98 |
config.cleanup_interface_sobjects = False |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
99 |
vreg = CubicWebRegistry(config) |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
100 |
# set_schema triggers objects registrations |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
101 |
vreg.set_schema(schema) |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
102 |
w(DEFAULT_POT_HEAD) |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
103 |
_generate_schema_pot(w, vreg, schema, libschema=libschema, cube=cube) |
0 | 104 |
|
105 |
def _generate_schema_pot(w, vreg, schema, libschema=None, cube=None): |
|
106 |
from cubicweb.common.i18n import add_msg |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
396
diff
changeset
|
107 |
w('# schema pot file, generated on %s\n' % datetime.now().strftime('%Y-%m-%d %H:%M:%S')) |
0 | 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') |
|
1150
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1138
diff
changeset
|
146 |
actionbox = self.vreg['actions']['edit_box'][0] |
0 | 147 |
for eschema in schema.entities(): |
148 |
if eschema.is_final(): |
|
149 |
continue |
|
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 |
|
1150
2d1b721fded9
remove rtags/methods to handle the action box from Entity, move it to the action box...
sylvain.thenault@logilab.fr
parents:
1138
diff
changeset
|
158 |
if actionbox.relation_mode(rschema.type, teschema.type, x) == 'create': |
0 | 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 |
context = {'cubename' : cubename, |
465 |
'distname' : distname, |
|
466 |
'shortdesc' : shortdesc, |
|
467 |
'longdesc' : longdesc or shortdesc, |
|
468 |
'dependancies' : dependancies, |
|
469 |
'version' : cubicwebversion, |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
396
diff
changeset
|
470 |
'year' : str(datetime.now().year), |
365
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
471 |
'author': self['author'], |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
472 |
'author-email': self['author-email'], |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
473 |
'author-web-site': self['author-web-site'], |
0 | 474 |
} |
475 |
copy_skeleton(skeldir, cubedir, context) |
|
476 |
||
477 |
def _ask_for_dependancies(self): |
|
478 |
includes = [] |
|
479 |
for stdtype in ServerConfiguration.available_cubes(): |
|
480 |
ans = raw_input("Depends on cube %s? (N/y/s(kip)/t(ype)" |
|
481 |
% stdtype).lower().strip() |
|
482 |
if ans == 'y': |
|
483 |
includes.append(stdtype) |
|
484 |
if ans == 't': |
|
485 |
includes = get_csv(raw_input('type dependancies: ')) |
|
486 |
break |
|
487 |
elif ans == 's': |
|
488 |
break |
|
489 |
return includes |
|
490 |
||
374
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 |
class ExamineLogCommand(Command): |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
493 |
"""Examine a rql log file. |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
494 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
495 |
usage: python exlog.py < rql.log |
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 |
will print out the following table |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
498 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
499 |
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
|
500 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
501 |
sorted by descending total execution time |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
502 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
503 |
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
|
504 |
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
|
505 |
""" |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
506 |
name = 'exlog' |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
507 |
options = ( |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
508 |
) |
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 |
def run(self, args): |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
511 |
if args: |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
512 |
raise BadCommandUsage("no argument expected") |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
513 |
import re |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
514 |
requests = {} |
1188
6937dfb242fb
[devtools] ExamineLog command does not fail on strange input and outputs to csv
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1116
diff
changeset
|
515 |
for lineno, line in enumerate(sys.stdin): |
374
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
516 |
if not ' WHERE ' in line: |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
517 |
continue |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
518 |
#sys.stderr.write( line ) |
1188
6937dfb242fb
[devtools] ExamineLog command does not fail on strange input and outputs to csv
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1116
diff
changeset
|
519 |
try: |
6937dfb242fb
[devtools] ExamineLog command does not fail on strange input and outputs to csv
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1116
diff
changeset
|
520 |
rql, time = line.split('--') |
6937dfb242fb
[devtools] ExamineLog command does not fail on strange input and outputs to csv
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1116
diff
changeset
|
521 |
rql = re.sub("(\'\w+': \d*)", '', rql) |
1189
8a075bc94563
[devtools] improve output of exlog command
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1188
diff
changeset
|
522 |
if '{' in rql: |
8a075bc94563
[devtools] improve output of exlog command
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1188
diff
changeset
|
523 |
rql = rql[:rql.index('{')] |
1188
6937dfb242fb
[devtools] ExamineLog command does not fail on strange input and outputs to csv
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1116
diff
changeset
|
524 |
req = requests.setdefault(rql, []) |
6937dfb242fb
[devtools] ExamineLog command does not fail on strange input and outputs to csv
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1116
diff
changeset
|
525 |
time.strip() |
6937dfb242fb
[devtools] ExamineLog command does not fail on strange input and outputs to csv
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1116
diff
changeset
|
526 |
chunks = time.split() |
6937dfb242fb
[devtools] ExamineLog command does not fail on strange input and outputs to csv
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1116
diff
changeset
|
527 |
cputime = float(chunks[-3]) |
6937dfb242fb
[devtools] ExamineLog command does not fail on strange input and outputs to csv
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1116
diff
changeset
|
528 |
req.append( cputime ) |
6937dfb242fb
[devtools] ExamineLog command does not fail on strange input and outputs to csv
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1116
diff
changeset
|
529 |
except Exception, exc: |
1189
8a075bc94563
[devtools] improve output of exlog command
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1188
diff
changeset
|
530 |
sys.stderr.write('Line %s: %s (%s)\n' % (lineno, exc, line)) |
374
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 = [] |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
533 |
for rql, times in requests.items(): |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
534 |
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
|
535 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
536 |
stat.sort() |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
537 |
stat.reverse() |
1189
8a075bc94563
[devtools] improve output of exlog command
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1188
diff
changeset
|
538 |
|
8a075bc94563
[devtools] improve output of exlog command
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1188
diff
changeset
|
539 |
total_time = sum(time for time, occ, rql in stat)*0.01 |
8a075bc94563
[devtools] improve output of exlog command
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1188
diff
changeset
|
540 |
print 'Percentage;Cumulative Time;Occurences;Query' |
374
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
541 |
for time, occ, rql in stat: |
1189
8a075bc94563
[devtools] improve output of exlog command
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1188
diff
changeset
|
542 |
print '%.2f;%.2f;%s;%s' % (time/total_time, time, occ, rql) |
0 | 543 |
|
544 |
register_commands((UpdateCubicWebCatalogCommand, |
|
545 |
UpdateTemplateCatalogCommand, |
|
546 |
LiveServerCommand, |
|
132
561671b87c22
rename NewTemplateCommand class into NewCubeCommand
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
61
diff
changeset
|
547 |
NewCubeCommand, |
374
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
548 |
ExamineLogCommand, |
0 | 549 |
)) |