author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 26 Jan 2010 13:26:41 +0100 | |
changeset 4362 | 817851a77e27 |
parent 4252 | 6c4f109c2b03 |
child 4380 | 5613d7c06339 |
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 |
|
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3978
diff
changeset
|
5 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 6 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1898
diff
changeset
|
7 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 8 |
""" |
9 |
__docformat__ = "restructuredtext en" |
|
10 |
||
11 |
import sys |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
396
diff
changeset
|
12 |
from datetime import datetime |
3118 | 13 |
from os import mkdir, chdir, getcwd |
0 | 14 |
from os.path import join, exists, abspath, basename, normpath, split, isdir |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
15 |
from copy import deepcopy |
2551
91f579b7a1e1
[F bw compat] warn if entities.pot exists but consider it anyway
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2534
diff
changeset
|
16 |
from warnings import warn |
0 | 17 |
|
18 |
from logilab.common import STD_BLACKLIST |
|
19 |
from logilab.common.modutils import get_module_files |
|
2633
bc9386c3b2c9
get_csv is being renamed to splitstrip
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2615
diff
changeset
|
20 |
from logilab.common.textutils import splitstrip |
2615
1ea41b7c0836
F [dialog] offer to create backup. refactor to use l.c.shellutils.ASK
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2551
diff
changeset
|
21 |
from logilab.common.shellutils import ASK |
1138
22f634977c95
make pylint happy, fix some bugs on the way
sylvain.thenault@logilab.fr
parents:
1132
diff
changeset
|
22 |
from logilab.common.clcommands import register_commands |
0 | 23 |
|
3978
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3858
diff
changeset
|
24 |
from cubicweb.__pkginfo__ import version as cubicwebversion |
2790
968108e16066
move underline_title to toolsutils
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2773
diff
changeset
|
25 |
from cubicweb import CW_SOFTWARE_ROOT as BASEDIR, BadCommandUsage |
968108e16066
move underline_title to toolsutils
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2773
diff
changeset
|
26 |
from cubicweb.toolsutils import Command, copy_skeleton, underline_title |
3978
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3858
diff
changeset
|
27 |
from cubicweb.schema import CONSTRAINTS |
0 | 28 |
from cubicweb.web.webconfig import WebConfiguration |
29 |
from cubicweb.server.serverconfig import ServerConfiguration |
|
30 |
||
2790
968108e16066
move underline_title to toolsutils
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2773
diff
changeset
|
31 |
|
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
32 |
class DevCubeConfiguration(ServerConfiguration, WebConfiguration): |
0 | 33 |
"""dummy config to get full library schema and entities""" |
34 |
creating = True |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
35 |
cubicweb_appobject_path = ServerConfiguration.cubicweb_appobject_path | WebConfiguration.cubicweb_appobject_path |
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
36 |
cube_appobject_path = ServerConfiguration.cube_appobject_path | WebConfiguration.cube_appobject_path |
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
37 |
|
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
38 |
def __init__(self, cube): |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
39 |
super(DevCubeConfiguration, self).__init__(cube) |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
40 |
if cube is None: |
0 | 41 |
self._cubes = () |
42 |
else: |
|
1774
4f4e0c6682e5
fix cubes order while generating catalogs
sylvain.thenault@logilab.fr
parents:
1770
diff
changeset
|
43 |
self._cubes = self.reorder_cubes(self.expand_cubes(self.my_cubes(cube))) |
396 | 44 |
|
45 |
def my_cubes(self, cube): |
|
46 |
return (cube,) + self.cube_dependencies(cube) + self.cube_recommends(cube) |
|
1451 | 47 |
|
0 | 48 |
@property |
49 |
def apphome(self): |
|
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
50 |
return None |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
51 |
def main_config_file(self): |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
52 |
return None |
0 | 53 |
def init_log(self, debug=None): |
54 |
pass |
|
55 |
def load_configuration(self): |
|
56 |
pass |
|
57 |
||
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
58 |
|
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
59 |
class DevDepConfiguration(DevCubeConfiguration): |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
60 |
"""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
|
61 |
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
|
62 |
""" |
396 | 63 |
|
64 |
def my_cubes(self, cube): |
|
65 |
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
|
66 |
|
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
67 |
def default_log_file(self): |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
68 |
return None |
0 | 69 |
|
70 |
||
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
71 |
def cleanup_sys_modules(config): |
0 | 72 |
# cleanup sys.modules, required when we're updating multiple cubes |
73 |
for name, mod in sys.modules.items(): |
|
74 |
if mod is None: |
|
75 |
# duh ? logilab.common.os for instance |
|
76 |
del sys.modules[name] |
|
77 |
continue |
|
78 |
if not hasattr(mod, '__file__'): |
|
79 |
continue |
|
80 |
for path in config.vregistry_path(): |
|
81 |
if mod.__file__.startswith(path): |
|
82 |
del sys.modules[name] |
|
83 |
break |
|
1850
75661f0a691b
should be outside the loop
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1774
diff
changeset
|
84 |
# fresh rtags |
75661f0a691b
should be outside the loop
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1774
diff
changeset
|
85 |
from cubicweb import rtags |
75661f0a691b
should be outside the loop
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1774
diff
changeset
|
86 |
from cubicweb.web import uicfg |
75661f0a691b
should be outside the loop
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1774
diff
changeset
|
87 |
rtags.RTAGS[:] = [] |
75661f0a691b
should be outside the loop
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1774
diff
changeset
|
88 |
reload(uicfg) |
1451 | 89 |
|
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
90 |
def generate_schema_pot(w, cubedir=None): |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
91 |
"""generate a pot file with schema specific i18n messages |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
92 |
|
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
93 |
notice that relation definitions description and static vocabulary |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
94 |
should be marked using '_' and extracted using xgettext |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
95 |
""" |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2633
diff
changeset
|
96 |
from cubicweb.cwvreg import CubicWebVRegistry |
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
97 |
cube = cubedir and split(cubedir)[-1] |
1470
fbdf66a08fbb
don't add to cube i18n catalog msg id for components redefined from cw or from a depending cube
sylvain.thenault@logilab.fr
parents:
1451
diff
changeset
|
98 |
libconfig = DevDepConfiguration(cube) |
fbdf66a08fbb
don't add to cube i18n catalog msg id for components redefined from cw or from a depending cube
sylvain.thenault@logilab.fr
parents:
1451
diff
changeset
|
99 |
libconfig.cleanup_interface_sobjects = False |
fbdf66a08fbb
don't add to cube i18n catalog msg id for components redefined from cw or from a depending cube
sylvain.thenault@logilab.fr
parents:
1451
diff
changeset
|
100 |
cleanup_sys_modules(libconfig) |
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
101 |
if cubedir: |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
102 |
config = DevCubeConfiguration(cube) |
1774
4f4e0c6682e5
fix cubes order while generating catalogs
sylvain.thenault@logilab.fr
parents:
1770
diff
changeset
|
103 |
config.cleanup_interface_sobjects = False |
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
104 |
else: |
1502 | 105 |
config = libconfig |
1470
fbdf66a08fbb
don't add to cube i18n catalog msg id for components redefined from cw or from a depending cube
sylvain.thenault@logilab.fr
parents:
1451
diff
changeset
|
106 |
libconfig = None |
1665 | 107 |
schema = config.load_schema(remove_unused_rtypes=False) |
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2633
diff
changeset
|
108 |
vreg = CubicWebVRegistry(config) |
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
109 |
# set_schema triggers objects registrations |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
110 |
vreg.set_schema(schema) |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
111 |
w(DEFAULT_POT_HEAD) |
1470
fbdf66a08fbb
don't add to cube i18n catalog msg id for components redefined from cw or from a depending cube
sylvain.thenault@logilab.fr
parents:
1451
diff
changeset
|
112 |
_generate_schema_pot(w, vreg, schema, libconfig=libconfig, cube=cube) |
1451 | 113 |
|
114 |
||
1470
fbdf66a08fbb
don't add to cube i18n catalog msg id for components redefined from cw or from a depending cube
sylvain.thenault@logilab.fr
parents:
1451
diff
changeset
|
115 |
def _generate_schema_pot(w, vreg, schema, libconfig=None, cube=None): |
4021
280c910c8710
move i18n / migration modules from cw.common to cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
116 |
from cubicweb.i18n import add_msg |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
117 |
from cubicweb.web import uicfg |
3287
19c1011736a6
tweak catalog generation by adding a new SYSTEM_RTYPES set to schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3286
diff
changeset
|
118 |
from cubicweb.schema import META_RTYPES, SYSTEM_RTYPES |
19c1011736a6
tweak catalog generation by adding a new SYSTEM_RTYPES set to schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3286
diff
changeset
|
119 |
no_context_rtypes = META_RTYPES | SYSTEM_RTYPES |
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
396
diff
changeset
|
120 |
w('# schema pot file, generated on %s\n' % datetime.now().strftime('%Y-%m-%d %H:%M:%S')) |
0 | 121 |
w('# \n') |
122 |
w('# singular and plural forms for each entity type\n') |
|
123 |
w('\n') |
|
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
124 |
vregdone = set() |
1470
fbdf66a08fbb
don't add to cube i18n catalog msg id for components redefined from cw or from a depending cube
sylvain.thenault@logilab.fr
parents:
1451
diff
changeset
|
125 |
if libconfig is not None: |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
126 |
from cubicweb.cwvreg import CubicWebVRegistry, clear_rtag_objects |
1665 | 127 |
libschema = libconfig.load_schema(remove_unused_rtypes=False) |
3476
6e927b729ae1
[uicfg, autoform] more consistent/powerful autoform_section rtags by using formtype/section; deprecates autoform_is_inlined; refactor automatci form and renderer thanks to this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3369
diff
changeset
|
128 |
afs = deepcopy(uicfg.autoform_section) |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
129 |
appearsin_addmenu = deepcopy(uicfg.actionbox_appearsin_addmenu) |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
130 |
clear_rtag_objects() |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
131 |
cleanup_sys_modules(libconfig) |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
132 |
libvreg = CubicWebVRegistry(libconfig) |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
133 |
libvreg.set_schema(libschema) # trigger objects registration |
3476
6e927b729ae1
[uicfg, autoform] more consistent/powerful autoform_section rtags by using formtype/section; deprecates autoform_is_inlined; refactor automatci form and renderer thanks to this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3369
diff
changeset
|
134 |
libafs = uicfg.autoform_section |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
135 |
libappearsin_addmenu = uicfg.actionbox_appearsin_addmenu |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
136 |
# prefill vregdone set |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
137 |
list(_iter_vreg_objids(libvreg, vregdone)) |
0 | 138 |
else: |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
139 |
libschema = {} |
3476
6e927b729ae1
[uicfg, autoform] more consistent/powerful autoform_section rtags by using formtype/section; deprecates autoform_is_inlined; refactor automatci form and renderer thanks to this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3369
diff
changeset
|
140 |
afs = uicfg.autoform_section |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
141 |
appearsin_addmenu = uicfg.actionbox_appearsin_addmenu |
3978
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3858
diff
changeset
|
142 |
for cstrtype in CONSTRAINTS: |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3858
diff
changeset
|
143 |
add_msg(w, cstrtype) |
0 | 144 |
done = set() |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
145 |
for eschema in sorted(schema.entities()): |
0 | 146 |
etype = eschema.type |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
147 |
if etype not in libschema: |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
148 |
add_msg(w, etype) |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
149 |
add_msg(w, '%s_plural' % etype) |
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
150 |
if not eschema.final: |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
151 |
add_msg(w, 'This %s' % etype) |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
152 |
add_msg(w, 'New %s' % etype) |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
153 |
if eschema.description and not eschema.description in done: |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
154 |
done.add(eschema.description) |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
155 |
add_msg(w, eschema.description) |
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
156 |
if eschema.final: |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
157 |
continue |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
158 |
for rschema, targetschemas, role in eschema.relation_definitions(True): |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
159 |
for tschema in targetschemas: |
3476
6e927b729ae1
[uicfg, autoform] more consistent/powerful autoform_section rtags by using formtype/section; deprecates autoform_is_inlined; refactor automatci form and renderer thanks to this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3369
diff
changeset
|
160 |
fsections = afs.etype_get(eschema, rschema, role, tschema) |
6e927b729ae1
[uicfg, autoform] more consistent/powerful autoform_section rtags by using formtype/section; deprecates autoform_is_inlined; refactor automatci form and renderer thanks to this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3369
diff
changeset
|
161 |
if 'inlined_attributes' in fsections and \ |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
162 |
(libconfig is None or not |
3476
6e927b729ae1
[uicfg, autoform] more consistent/powerful autoform_section rtags by using formtype/section; deprecates autoform_is_inlined; refactor automatci form and renderer thanks to this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3369
diff
changeset
|
163 |
'inlined_attributes' in libafs.etype_get( |
6e927b729ae1
[uicfg, autoform] more consistent/powerful autoform_section rtags by using formtype/section; deprecates autoform_is_inlined; refactor automatci form and renderer thanks to this
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3369
diff
changeset
|
164 |
eschema, rschema, role, tschema)): |
3275
5247789df541
[gettext] provide GNU contexts to avoid translations ambiguities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3221
diff
changeset
|
165 |
add_msg(w, 'add a %s' % tschema, |
5247789df541
[gettext] provide GNU contexts to avoid translations ambiguities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3221
diff
changeset
|
166 |
'inlined:%s.%s.%s' % (etype, rschema, role)) |
5247789df541
[gettext] provide GNU contexts to avoid translations ambiguities
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3221
diff
changeset
|
167 |
add_msg(w, 'remove this %s' % tschema, |
3327
44efba78afac
fix/enhance i18n context usage for inlined forms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3287
diff
changeset
|
168 |
'inlined:%s.%s.%s' % (etype, rschema, role)) |
44efba78afac
fix/enhance i18n context usage for inlined forms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3287
diff
changeset
|
169 |
add_msg(w, 'This %s' % tschema, |
44efba78afac
fix/enhance i18n context usage for inlined forms
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3287
diff
changeset
|
170 |
'inlined:%s.%s.%s' % (etype, rschema, role)) |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
171 |
if appearsin_addmenu.etype_get(eschema, rschema, role, tschema) and \ |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
172 |
(libconfig is None or not |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
173 |
libappearsin_addmenu.etype_get(eschema, rschema, role, tschema)): |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
174 |
if role == 'subject': |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
175 |
label = 'add %s %s %s %s' % (eschema, rschema, |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
176 |
tschema, role) |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
177 |
label2 = "creating %s (%s %%(linkto)s %s %s)" % ( |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
178 |
tschema, eschema, rschema, tschema) |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
179 |
else: |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
180 |
label = 'add %s %s %s %s' % (tschema, rschema, |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
181 |
eschema, role) |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
182 |
label2 = "creating %s (%s %s %s %%(linkto)s)" % ( |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
183 |
tschema, tschema, rschema, eschema) |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
184 |
add_msg(w, label) |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
185 |
add_msg(w, label2) |
3858
ba96e4607e67
add XX reminder
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
186 |
# XXX also generate "creating ...' messages for actions in the |
ba96e4607e67
add XX reminder
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
187 |
# addrelated submenu |
0 | 188 |
w('# subject and object forms for each relation type\n') |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
189 |
w('# (no object form for final or symetric relation types)\n') |
0 | 190 |
w('\n') |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
191 |
for rschema in sorted(schema.relations()): |
0 | 192 |
rtype = rschema.type |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
193 |
if rtype not in libschema: |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
194 |
# bw compat, necessary until all translation of relation are done properly... |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
195 |
add_msg(w, rtype) |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
196 |
if rschema.description and rschema.description not in done: |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
197 |
done.add(rschema.description) |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
198 |
add_msg(w, rschema.description) |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
199 |
done.add(rtype) |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
200 |
librschema = None |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
201 |
else: |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
202 |
librschema = libschema.rschema(rtype) |
3281
bea1bde00fbc
[i18n] do not add context information for metadata relations
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3280
diff
changeset
|
203 |
# add context information only for non-metadata rtypes |
3287
19c1011736a6
tweak catalog generation by adding a new SYSTEM_RTYPES set to schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3286
diff
changeset
|
204 |
if rschema not in no_context_rtypes: |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
205 |
libsubjects = librschema and librschema.subjects() or () |
3281
bea1bde00fbc
[i18n] do not add context information for metadata relations
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3280
diff
changeset
|
206 |
for subjschema in rschema.subjects(): |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
207 |
if not subjschema in libsubjects: |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
208 |
add_msg(w, rtype, subjschema.type) |
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
209 |
if not (schema.rschema(rtype).final or rschema.symetric): |
3287
19c1011736a6
tweak catalog generation by adding a new SYSTEM_RTYPES set to schema
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3286
diff
changeset
|
210 |
if rschema not in no_context_rtypes: |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
211 |
libobjects = librschema and librschema.objects() or () |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
212 |
for objschema in rschema.objects(): |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
213 |
if not objschema in libobjects: |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
214 |
add_msg(w, '%s_object' % rtype, objschema.type) |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
215 |
if rtype not in libschema: |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
216 |
# bw compat, necessary until all translation of relation are done properly... |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
217 |
add_msg(w, '%s_object' % rtype) |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
218 |
for objid in _iter_vreg_objids(vreg, vregdone): |
1470
fbdf66a08fbb
don't add to cube i18n catalog msg id for components redefined from cw or from a depending cube
sylvain.thenault@logilab.fr
parents:
1451
diff
changeset
|
219 |
add_msg(w, '%s_description' % objid) |
fbdf66a08fbb
don't add to cube i18n catalog msg id for components redefined from cw or from a depending cube
sylvain.thenault@logilab.fr
parents:
1451
diff
changeset
|
220 |
add_msg(w, objid) |
fbdf66a08fbb
don't add to cube i18n catalog msg id for components redefined from cw or from a depending cube
sylvain.thenault@logilab.fr
parents:
1451
diff
changeset
|
221 |
|
3293 | 222 |
|
1470
fbdf66a08fbb
don't add to cube i18n catalog msg id for components redefined from cw or from a depending cube
sylvain.thenault@logilab.fr
parents:
1451
diff
changeset
|
223 |
def _iter_vreg_objids(vreg, done, prefix=None): |
0 | 224 |
for reg, objdict in vreg.items(): |
225 |
for objects in objdict.values(): |
|
226 |
for obj in objects: |
|
3677
acdba524bb8f
fix i18ncube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3674
diff
changeset
|
227 |
objid = '%s_%s' % (reg, obj.__regid__) |
0 | 228 |
if objid in done: |
1470
fbdf66a08fbb
don't add to cube i18n catalog msg id for components redefined from cw or from a depending cube
sylvain.thenault@logilab.fr
parents:
1451
diff
changeset
|
229 |
break |
3677
acdba524bb8f
fix i18ncube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3674
diff
changeset
|
230 |
try: # XXX < 3.6 bw compat |
acdba524bb8f
fix i18ncube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3674
diff
changeset
|
231 |
pdefs = obj.property_defs |
acdba524bb8f
fix i18ncube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3674
diff
changeset
|
232 |
except AttributeError: |
acdba524bb8f
fix i18ncube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3674
diff
changeset
|
233 |
pdefs = getattr(obj, 'cw_property_defs', {}) |
acdba524bb8f
fix i18ncube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3674
diff
changeset
|
234 |
if pdefs: |
1470
fbdf66a08fbb
don't add to cube i18n catalog msg id for components redefined from cw or from a depending cube
sylvain.thenault@logilab.fr
parents:
1451
diff
changeset
|
235 |
yield objid |
0 | 236 |
done.add(objid) |
1470
fbdf66a08fbb
don't add to cube i18n catalog msg id for components redefined from cw or from a depending cube
sylvain.thenault@logilab.fr
parents:
1451
diff
changeset
|
237 |
break |
374
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
238 |
|
1451 | 239 |
|
1502 | 240 |
def defined_in_library(etype, rtype, tetype, role): |
1451 | 241 |
"""return true if the given relation definition exists in cubicweb's library |
242 |
""" |
|
0 | 243 |
if libschema is None: |
244 |
return False |
|
1451 | 245 |
if role == 'subject': |
0 | 246 |
subjtype, objtype = etype, tetype |
247 |
else: |
|
248 |
subjtype, objtype = tetype, etype |
|
249 |
try: |
|
250 |
return libschema.rschema(rtype).has_rdef(subjtype, objtype) |
|
251 |
except KeyError: |
|
252 |
return False |
|
253 |
||
254 |
||
155
9ed6db94a087
spanish is now a supported language
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
133
diff
changeset
|
255 |
LANGS = ('en', 'fr', 'es') |
0 | 256 |
I18NDIR = join(BASEDIR, 'i18n') |
257 |
DEFAULT_POT_HEAD = r'''msgid "" |
|
258 |
msgstr "" |
|
259 |
"Project-Id-Version: cubicweb %s\n" |
|
260 |
"PO-Revision-Date: 2008-03-28 18:14+0100\n" |
|
261 |
"Last-Translator: Logilab Team <contact@logilab.fr>\n" |
|
262 |
"Language-Team: fr <contact@logilab.fr>\n" |
|
263 |
"MIME-Version: 1.0\n" |
|
264 |
"Content-Type: text/plain; charset=UTF-8\n" |
|
265 |
"Content-Transfer-Encoding: 8bit\n" |
|
266 |
"Generated-By: cubicweb-devtools\n" |
|
267 |
"Plural-Forms: nplurals=2; plural=(n > 1);\n" |
|
268 |
||
269 |
''' % cubicwebversion |
|
270 |
||
271 |
||
272 |
class UpdateCubicWebCatalogCommand(Command): |
|
273 |
"""Update i18n catalogs for cubicweb library. |
|
1451 | 274 |
|
0 | 275 |
It will regenerate cubicweb/i18n/xx.po files. You'll have then to edit those |
276 |
files to add translations of newly added messages. |
|
277 |
""" |
|
1898
39b37f90a8a4
[cw-ctl] rename i18n commands (see #342889)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1850
diff
changeset
|
278 |
name = 'i18ncubicweb' |
0 | 279 |
|
280 |
def run(self, args): |
|
281 |
"""run the command with its specific arguments""" |
|
282 |
if args: |
|
283 |
raise BadCommandUsage('Too much arguments') |
|
284 |
import shutil |
|
2446
440cb4ea7e5c
[refactor] #342855: replace uses of (deprecated) mktemp
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
285 |
import tempfile |
0 | 286 |
import yams |
287 |
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
|
288 |
from logilab.common.shellutils import globfind, find, rm |
4021
280c910c8710
move i18n / migration modules from cw.common to cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
289 |
from cubicweb.i18n import extract_from_tal, execute |
2692
bffb0e64736c
[i18ncubicweb] fix stupid NameError with mkdtemp
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2657
diff
changeset
|
290 |
tempdir = tempfile.mkdtemp() |
2534
cda22bc0e6ef
[i18n] #344832: rename entities.pot
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2528
diff
changeset
|
291 |
potfiles = [join(I18NDIR, 'static-messages.pot')] |
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
292 |
print '-> extract schema messages.' |
0 | 293 |
schemapot = join(tempdir, 'schema.pot') |
294 |
potfiles.append(schemapot) |
|
295 |
# explicit close necessary else the file may not be yet flushed when |
|
296 |
# we'll using it below |
|
297 |
schemapotstream = file(schemapot, 'w') |
|
298 |
generate_schema_pot(schemapotstream.write, cubedir=None) |
|
299 |
schemapotstream.close() |
|
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
300 |
print '-> extract TAL messages.' |
0 | 301 |
tali18nfile = join(tempdir, 'tali18n.py') |
302 |
extract_from_tal(find(join(BASEDIR, 'web'), ('.py', '.pt')), tali18nfile) |
|
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
303 |
print '-> generate .pot files.' |
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
|
304 |
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
|
305 |
('schemadescr', globfind(join(BASEDIR, 'schemas'), '*.py'), None), |
0 | 306 |
('yams', get_module_files(yams.__path__[0]), None), |
307 |
('tal', [tali18nfile], None), |
|
58
c7c22b210372
only try to internationalize our own js files
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
57
diff
changeset
|
308 |
('js', globfind(join(BASEDIR, 'web'), 'cub*.js'), 'java'), |
0 | 309 |
]: |
60
dc90556488d8
oops, bad changeset review, revert debug changes
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
58
diff
changeset
|
310 |
cmd = 'xgettext --no-location --omit-header -k_ -o %s %s' |
0 | 311 |
if lang is not None: |
312 |
cmd += ' -L %s' % lang |
|
1502 | 313 |
potfile = join(tempdir, '%s.pot' % id) |
3117
32686ae66c75
mostly adapt the i18n subsystem to limitation wrt redirection handinling in windows, using the -o argument of the utilities
Aurélien Campéas
parents:
2692
diff
changeset
|
314 |
execute(cmd % (potfile, ' '.join('"%s"' % f for f in files))) |
1502 | 315 |
if exists(potfile): |
316 |
potfiles.append(potfile) |
|
317 |
else: |
|
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
318 |
print '-> WARNING: %s file was not generated' % potfile |
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
319 |
print '-> merging %i .pot files' % len(potfiles) |
0 | 320 |
cubicwebpot = join(tempdir, 'cubicweb.pot') |
3117
32686ae66c75
mostly adapt the i18n subsystem to limitation wrt redirection handinling in windows, using the -o argument of the utilities
Aurélien Campéas
parents:
2692
diff
changeset
|
321 |
execute('msgcat -o %s %s' % (cubicwebpot, ' '.join('"%s"' % f for f in potfiles))) |
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
322 |
print '-> merging main pot file with existing translations.' |
0 | 323 |
chdir(I18NDIR) |
324 |
toedit = [] |
|
325 |
for lang in LANGS: |
|
326 |
target = '%s.po' % lang |
|
3118 | 327 |
execute('msgmerge -N --sort-output -o "%snew" "%s" "%s"' % (target, target, cubicwebpot)) |
0 | 328 |
ensure_fs_mode(target) |
329 |
shutil.move('%snew' % target, target) |
|
330 |
toedit.append(abspath(target)) |
|
331 |
# cleanup |
|
60
dc90556488d8
oops, bad changeset review, revert debug changes
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
58
diff
changeset
|
332 |
rm(tempdir) |
0 | 333 |
# instructions pour la suite |
2396
8bfb99d7bbcc
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2395
diff
changeset
|
334 |
print '-> regenerated CubicWeb\'s .po catalogs.' |
8bfb99d7bbcc
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2395
diff
changeset
|
335 |
print '\nYou can now edit the following files:' |
0 | 336 |
print '* ' + '\n* '.join(toedit) |
2396
8bfb99d7bbcc
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2395
diff
changeset
|
337 |
print 'when you are done, run "cubicweb-ctl i18ncube yourcube".' |
0 | 338 |
|
339 |
||
340 |
class UpdateTemplateCatalogCommand(Command): |
|
341 |
"""Update i18n catalogs for cubes. If no cube is specified, update |
|
342 |
catalogs of all registered cubes. |
|
343 |
""" |
|
1898
39b37f90a8a4
[cw-ctl] rename i18n commands (see #342889)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1850
diff
changeset
|
344 |
name = 'i18ncube' |
0 | 345 |
arguments = '[<cube>...]' |
1451 | 346 |
|
0 | 347 |
def run(self, args): |
348 |
"""run the command with its specific arguments""" |
|
349 |
if args: |
|
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
396
diff
changeset
|
350 |
cubes = [DevCubeConfiguration.cube_dir(cube) for cube in args] |
0 | 351 |
else: |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
396
diff
changeset
|
352 |
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
|
353 |
cubes = [cubepath for cubepath in cubes if exists(join(cubepath, 'i18n'))] |
0 | 354 |
update_cubes_catalogs(cubes) |
355 |
||
1770
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
356 |
|
0 | 357 |
def update_cubes_catalogs(cubes): |
1770
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
358 |
for cubedir in cubes: |
2527
e60db6312aa0
per cube message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2458
diff
changeset
|
359 |
toedit = [] |
1770
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
360 |
if not isdir(cubedir): |
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
361 |
print '-> ignoring %s that is not a directory.' % cubedir |
1770
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
362 |
continue |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
363 |
try: |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
364 |
toedit += update_cube_catalogs(cubedir) |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
365 |
except Exception: |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
366 |
import traceback |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
367 |
traceback.print_exc() |
2527
e60db6312aa0
per cube message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2458
diff
changeset
|
368 |
print '-> error while updating catalogs for cube', cubedir |
e60db6312aa0
per cube message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2458
diff
changeset
|
369 |
else: |
e60db6312aa0
per cube message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2458
diff
changeset
|
370 |
# instructions pour la suite |
e60db6312aa0
per cube message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2458
diff
changeset
|
371 |
print '-> regenerated .po catalogs for cube %s.' % cubedir |
e60db6312aa0
per cube message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2458
diff
changeset
|
372 |
print '\nYou can now edit the following files:' |
e60db6312aa0
per cube message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2458
diff
changeset
|
373 |
print '* ' + '\n* '.join(toedit) |
e60db6312aa0
per cube message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2458
diff
changeset
|
374 |
print ('When you are done, run "cubicweb-ctl i18ninstance ' |
e60db6312aa0
per cube message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2458
diff
changeset
|
375 |
'<yourinstance>" to see changes in your instances.') |
1770
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
376 |
|
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
377 |
def update_cube_catalogs(cubedir): |
0 | 378 |
import shutil |
2446
440cb4ea7e5c
[refactor] #342855: replace uses of (deprecated) mktemp
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
379 |
import tempfile |
0 | 380 |
from logilab.common.fileutils import ensure_fs_mode |
381 |
from logilab.common.shellutils import find, rm |
|
4021
280c910c8710
move i18n / migration modules from cw.common to cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
382 |
from cubicweb.i18n import extract_from_tal, execute |
0 | 383 |
toedit = [] |
1770
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
384 |
cube = basename(normpath(cubedir)) |
2446
440cb4ea7e5c
[refactor] #342855: replace uses of (deprecated) mktemp
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
385 |
tempdir = tempfile.mkdtemp() |
2396
8bfb99d7bbcc
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2395
diff
changeset
|
386 |
print underline_title('Updating i18n catalogs for cube %s' % cube) |
1770
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
387 |
chdir(cubedir) |
2551
91f579b7a1e1
[F bw compat] warn if entities.pot exists but consider it anyway
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2534
diff
changeset
|
388 |
if exists(join('i18n', 'entities.pot')): |
91f579b7a1e1
[F bw compat] warn if entities.pot exists but consider it anyway
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2534
diff
changeset
|
389 |
warn('entities.pot is deprecated, rename file to static-messages.pot (%s)' |
91f579b7a1e1
[F bw compat] warn if entities.pot exists but consider it anyway
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2534
diff
changeset
|
390 |
% join('i18n', 'entities.pot'), DeprecationWarning) |
91f579b7a1e1
[F bw compat] warn if entities.pot exists but consider it anyway
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2534
diff
changeset
|
391 |
potfiles = [join('i18n', 'entities.pot')] |
91f579b7a1e1
[F bw compat] warn if entities.pot exists but consider it anyway
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2534
diff
changeset
|
392 |
elif exists(join('i18n', 'static-messages.pot')): |
91f579b7a1e1
[F bw compat] warn if entities.pot exists but consider it anyway
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2534
diff
changeset
|
393 |
potfiles = [join('i18n', 'static-messages.pot')] |
91f579b7a1e1
[F bw compat] warn if entities.pot exists but consider it anyway
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2534
diff
changeset
|
394 |
else: |
91f579b7a1e1
[F bw compat] warn if entities.pot exists but consider it anyway
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2534
diff
changeset
|
395 |
potfiles = [] |
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
396 |
print '-> extract schema messages' |
1770
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
397 |
schemapot = join(tempdir, 'schema.pot') |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
398 |
potfiles.append(schemapot) |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
399 |
# explicit close necessary else the file may not be yet flushed when |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
400 |
# we'll using it below |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
401 |
schemapotstream = file(schemapot, 'w') |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
402 |
generate_schema_pot(schemapotstream.write, cubedir) |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
403 |
schemapotstream.close() |
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
404 |
print '-> extract TAL messages' |
1770
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
405 |
tali18nfile = join(tempdir, 'tali18n.py') |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
406 |
extract_from_tal(find('.', ('.py', '.pt'), blacklist=STD_BLACKLIST+('test',)), tali18nfile) |
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
407 |
print '-> extract Javascript messages' |
1770
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
408 |
jsfiles = [jsfile for jsfile in find('.', '.js') if basename(jsfile).startswith('cub')] |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
409 |
if jsfiles: |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
410 |
tmppotfile = join(tempdir, 'js.pot') |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
411 |
execute('xgettext --no-location --omit-header -k_ -L java --from-code=utf-8 -o %s %s' |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
412 |
% (tmppotfile, ' '.join(jsfiles))) |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
413 |
# no pot file created if there are no string to translate |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
414 |
if exists(tmppotfile): |
0 | 415 |
potfiles.append(tmppotfile) |
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
416 |
print '-> create cube-specific catalog' |
1770
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
417 |
tmppotfile = join(tempdir, 'generated.pot') |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
418 |
cubefiles = find('.', '.py', blacklist=STD_BLACKLIST+('test',)) |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
419 |
cubefiles.append(tali18nfile) |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
420 |
execute('xgettext --no-location --omit-header -k_ -o %s %s' |
3118 | 421 |
% (tmppotfile, ' '.join('"%s"' % f for f in cubefiles))) |
1770
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
422 |
if exists(tmppotfile): # doesn't exists of no translation string found |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
423 |
potfiles.append(tmppotfile) |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
424 |
potfile = join(tempdir, 'cube.pot') |
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
425 |
print '-> merging %i .pot files:' % len(potfiles) |
3117
32686ae66c75
mostly adapt the i18n subsystem to limitation wrt redirection handinling in windows, using the -o argument of the utilities
Aurélien Campéas
parents:
2692
diff
changeset
|
426 |
execute('msgcat -o %s %s' % (potfile, |
32686ae66c75
mostly adapt the i18n subsystem to limitation wrt redirection handinling in windows, using the -o argument of the utilities
Aurélien Campéas
parents:
2692
diff
changeset
|
427 |
' '.join('"%s"' % f for f in potfiles))) |
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
428 |
print '-> merging main pot file with existing translations:' |
1770
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
429 |
chdir('i18n') |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
430 |
for lang in LANGS: |
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
431 |
print '-> language', lang |
1770
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
432 |
cubepo = '%s.po' % lang |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
433 |
if not exists(cubepo): |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
434 |
shutil.copy(potfile, cubepo) |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
435 |
else: |
3118 | 436 |
execute('msgmerge -N -s -o %snew %s %s' % (cubepo, cubepo, potfile)) |
1770
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
437 |
ensure_fs_mode(cubepo) |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
438 |
shutil.move('%snew' % cubepo, cubepo) |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
439 |
toedit.append(abspath(cubepo)) |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
440 |
# cleanup |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
441 |
rm(tempdir) |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
442 |
return toedit |
0 | 443 |
|
444 |
||
445 |
class LiveServerCommand(Command): |
|
446 |
"""Run a server from within a cube directory. |
|
447 |
""" |
|
448 |
name = 'live-server' |
|
449 |
arguments = '' |
|
450 |
options = () |
|
1451 | 451 |
|
0 | 452 |
def run(self, args): |
453 |
"""run the command with its specific arguments""" |
|
454 |
from cubicweb.devtools.livetest import runserver |
|
455 |
runserver() |
|
456 |
||
457 |
||
132
561671b87c22
rename NewTemplateCommand class into NewCubeCommand
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
61
diff
changeset
|
458 |
class NewCubeCommand(Command): |
0 | 459 |
"""Create a new cube. |
460 |
||
461 |
<cubename> |
|
462 |
the name of the new cube |
|
463 |
""" |
|
464 |
name = 'newcube' |
|
465 |
arguments = '<cubename>' |
|
466 |
||
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
|
467 |
options = ( |
1106
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
468 |
("directory", |
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
469 |
{'short': 'd', 'type' : 'string', 'metavar': '<cubes directory>', |
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
470 |
'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
|
471 |
} |
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
472 |
), |
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
|
473 |
("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
|
474 |
{'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
|
475 |
'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
|
476 |
'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
|
477 |
} |
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
|
478 |
), |
365
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
479 |
("author", |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
480 |
{'short': 'a', 'type' : 'string', 'metavar': '<author>', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
481 |
'default': 'LOGILAB S.A. (Paris, FRANCE)', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
482 |
'help': 'cube author', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
483 |
} |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
484 |
), |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
485 |
("author-email", |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
486 |
{'short': 'e', 'type' : 'string', 'metavar': '<email>', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
487 |
'default': 'contact@logilab.fr', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
488 |
'help': 'cube author\'s email', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
489 |
} |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
490 |
), |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
491 |
("author-web-site", |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
492 |
{'short': 'w', 'type' : 'string', 'metavar': '<web site>', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
493 |
'default': 'http://www.logilab.fr', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
494 |
'help': 'cube author\'s web site', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
495 |
} |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
496 |
), |
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
|
497 |
) |
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
|
498 |
|
1451 | 499 |
|
0 | 500 |
def run(self, args): |
501 |
if len(args) != 1: |
|
502 |
raise BadCommandUsage("exactly one argument (cube name) is expected") |
|
503 |
cubename, = args |
|
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
|
504 |
verbose = self.get('verbose') |
1106
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
505 |
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
|
506 |
if not cubesdir: |
163e6a65d488
fix dumb name error, should call cubes_search_path, not cubes_path
sylvain.thenault@logilab.fr
parents:
1106
diff
changeset
|
507 |
cubespath = ServerConfiguration.cubes_search_path() |
1106
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
508 |
if len(cubespath) > 1: |
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
509 |
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
|
510 |
" Please specify it using the --directory option") |
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
511 |
cubesdir = cubespath[0] |
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
512 |
if not isdir(cubesdir): |
2615
1ea41b7c0836
F [dialog] offer to create backup. refactor to use l.c.shellutils.ASK
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2551
diff
changeset
|
513 |
print "-> creating cubes directory", cubesdir |
0 | 514 |
try: |
1106
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
515 |
mkdir(cubesdir) |
0 | 516 |
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
|
517 |
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
|
518 |
cubedir = join(cubesdir, cubename) |
0 | 519 |
if exists(cubedir): |
520 |
self.fail("%s already exists !" % (cubedir)) |
|
521 |
skeldir = join(BASEDIR, 'skeleton') |
|
2615
1ea41b7c0836
F [dialog] offer to create backup. refactor to use l.c.shellutils.ASK
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2551
diff
changeset
|
522 |
default_name = '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
|
523 |
if verbose: |
2615
1ea41b7c0836
F [dialog] offer to create backup. refactor to use l.c.shellutils.ASK
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2551
diff
changeset
|
524 |
distname = raw_input('Debian name for your cube ? [%s]): ' % default_name).strip() |
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
|
525 |
if not distname: |
2615
1ea41b7c0836
F [dialog] offer to create backup. refactor to use l.c.shellutils.ASK
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2551
diff
changeset
|
526 |
distname = default_name |
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
|
527 |
elif not distname.startswith('cubicweb-'): |
2615
1ea41b7c0836
F [dialog] offer to create backup. refactor to use l.c.shellutils.ASK
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2551
diff
changeset
|
528 |
if ASK.confirm('Do you mean cubicweb-%s ?' % distname): |
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
|
529 |
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
|
530 |
else: |
2615
1ea41b7c0836
F [dialog] offer to create backup. refactor to use l.c.shellutils.ASK
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2551
diff
changeset
|
531 |
distname = default_name |
1451 | 532 |
|
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
|
533 |
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
|
534 |
if verbose: |
2615
1ea41b7c0836
F [dialog] offer to create backup. refactor to use l.c.shellutils.ASK
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2551
diff
changeset
|
535 |
longdesc = raw_input('Enter a long description (leave empty to reuse the short one): ') |
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
|
536 |
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
|
537 |
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
|
538 |
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
|
539 |
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
|
540 |
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
|
541 |
dependancies = ', '.join(repr(cube) for cube in includes) |
0 | 542 |
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
|
543 |
dependancies = '' |
0 | 544 |
context = {'cubename' : cubename, |
545 |
'distname' : distname, |
|
546 |
'shortdesc' : shortdesc, |
|
547 |
'longdesc' : longdesc or shortdesc, |
|
548 |
'dependancies' : dependancies, |
|
549 |
'version' : cubicwebversion, |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
396
diff
changeset
|
550 |
'year' : str(datetime.now().year), |
365
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
551 |
'author': self['author'], |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
552 |
'author-email': self['author-email'], |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
553 |
'author-web-site': self['author-web-site'], |
0 | 554 |
} |
555 |
copy_skeleton(skeldir, cubedir, context) |
|
556 |
||
557 |
def _ask_for_dependancies(self): |
|
558 |
includes = [] |
|
559 |
for stdtype in ServerConfiguration.available_cubes(): |
|
2615
1ea41b7c0836
F [dialog] offer to create backup. refactor to use l.c.shellutils.ASK
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2551
diff
changeset
|
560 |
answer = ASK.ask("Depends on cube %s? " % stdtype, |
1ea41b7c0836
F [dialog] offer to create backup. refactor to use l.c.shellutils.ASK
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2551
diff
changeset
|
561 |
('N','y','skip','type'), 'N') |
1ea41b7c0836
F [dialog] offer to create backup. refactor to use l.c.shellutils.ASK
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2551
diff
changeset
|
562 |
if answer == 'y': |
0 | 563 |
includes.append(stdtype) |
2615
1ea41b7c0836
F [dialog] offer to create backup. refactor to use l.c.shellutils.ASK
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2551
diff
changeset
|
564 |
if answer == 'type': |
2633
bc9386c3b2c9
get_csv is being renamed to splitstrip
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2615
diff
changeset
|
565 |
includes = splitstrip(raw_input('type dependancies: ')) |
0 | 566 |
break |
2615
1ea41b7c0836
F [dialog] offer to create backup. refactor to use l.c.shellutils.ASK
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2551
diff
changeset
|
567 |
elif answer == 'skip': |
0 | 568 |
break |
569 |
return includes |
|
1451 | 570 |
|
374
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
571 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
572 |
class ExamineLogCommand(Command): |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
573 |
"""Examine a rql log file. |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
574 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
575 |
usage: python exlog.py < rql.log |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
576 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
577 |
will print out the following table |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
578 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
579 |
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
|
580 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
581 |
sorted by descending total execution time |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
582 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
583 |
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
|
584 |
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
|
585 |
""" |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
586 |
name = 'exlog' |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
587 |
options = ( |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
588 |
) |
1451 | 589 |
|
374
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
590 |
def run(self, args): |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
591 |
if args: |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
592 |
raise BadCommandUsage("no argument expected") |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
593 |
import re |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
594 |
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
|
595 |
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
|
596 |
if not ' WHERE ' in line: |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
597 |
continue |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
598 |
#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
|
599 |
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
|
600 |
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
|
601 |
rql = re.sub("(\'\w+': \d*)", '', rql) |
1189
8a075bc94563
[devtools] improve output of exlog command
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1188
diff
changeset
|
602 |
if '{' in rql: |
8a075bc94563
[devtools] improve output of exlog command
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1188
diff
changeset
|
603 |
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
|
604 |
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
|
605 |
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
|
606 |
chunks = time.split() |
2092
f5102472243d
[exlog] print clocktime in addition to cputime
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
607 |
clocktime = float(chunks[0][1:]) |
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
|
608 |
cputime = float(chunks[-3]) |
2092
f5102472243d
[exlog] print clocktime in addition to cputime
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
609 |
req.append( (clocktime, cputime) ) |
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
|
610 |
except Exception, exc: |
1189
8a075bc94563
[devtools] improve output of exlog command
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1188
diff
changeset
|
611 |
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
|
612 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
613 |
stat = [] |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
614 |
for rql, times in requests.items(): |
2092
f5102472243d
[exlog] print clocktime in addition to cputime
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
615 |
stat.append( (sum(time[0] for time in times), |
f5102472243d
[exlog] print clocktime in addition to cputime
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
616 |
sum(time[1] for time in times), |
f5102472243d
[exlog] print clocktime in addition to cputime
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
617 |
len(times), rql) ) |
374
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
618 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
619 |
stat.sort() |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
620 |
stat.reverse() |
1189
8a075bc94563
[devtools] improve output of exlog command
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1188
diff
changeset
|
621 |
|
2092
f5102472243d
[exlog] print clocktime in addition to cputime
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
622 |
total_time = sum(clocktime for clocktime, cputime, occ, rql in stat)*0.01 |
f5102472243d
[exlog] print clocktime in addition to cputime
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
623 |
print 'Percentage;Cumulative Time (clock);Cumulative Time (CPU);Occurences;Query' |
f5102472243d
[exlog] print clocktime in addition to cputime
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
624 |
for clocktime, cputime, occ, rql in stat: |
f5102472243d
[exlog] print clocktime in addition to cputime
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
625 |
print '%.2f;%.2f;%.2f;%s;%s' % (clocktime/total_time, clocktime, cputime, occ, rql) |
1451 | 626 |
|
0 | 627 |
register_commands((UpdateCubicWebCatalogCommand, |
628 |
UpdateTemplateCatalogCommand, |
|
629 |
LiveServerCommand, |
|
132
561671b87c22
rename NewTemplateCommand class into NewCubeCommand
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
61
diff
changeset
|
630 |
NewCubeCommand, |
374
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
631 |
ExamineLogCommand, |
0 | 632 |
)) |