author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Tue, 28 Jul 2009 11:08:11 +0200 | |
changeset 2528 | 6ae5d8082b39 |
parent 2527 | e60db6312aa0 |
child 2534 | cda22bc0e6ef |
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 |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1898
diff
changeset
|
5 |
:copyright: 2001-2009 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 |
1415
98b8e5c627b8
fix actionbox def
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1263
diff
changeset
|
13 |
from os import mkdir, chdir |
0 | 14 |
from os.path import join, exists, abspath, basename, normpath, split, isdir |
15 |
||
16 |
||
17 |
from logilab.common import STD_BLACKLIST |
|
18 |
from logilab.common.modutils import get_module_files |
|
19 |
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
|
20 |
from logilab.common.clcommands import register_commands |
0 | 21 |
|
2396
8bfb99d7bbcc
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2395
diff
changeset
|
22 |
from cubicweb import CW_SOFTWARE_ROOT as BASEDIR, BadCommandUsage, underline_title |
0 | 23 |
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
|
24 |
from cubicweb.toolsutils import Command, confirm, copy_skeleton |
0 | 25 |
from cubicweb.web.webconfig import WebConfiguration |
26 |
from cubicweb.server.serverconfig import ServerConfiguration |
|
27 |
||
28 |
||
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
29 |
class DevCubeConfiguration(ServerConfiguration, WebConfiguration): |
0 | 30 |
"""dummy config to get full library schema and entities""" |
31 |
creating = True |
|
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
32 |
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
|
33 |
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
|
34 |
|
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
35 |
def __init__(self, cube): |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
36 |
super(DevCubeConfiguration, self).__init__(cube) |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
37 |
if cube is None: |
0 | 38 |
self._cubes = () |
39 |
else: |
|
1774
4f4e0c6682e5
fix cubes order while generating catalogs
sylvain.thenault@logilab.fr
parents:
1770
diff
changeset
|
40 |
self._cubes = self.reorder_cubes(self.expand_cubes(self.my_cubes(cube))) |
396 | 41 |
|
42 |
def my_cubes(self, cube): |
|
43 |
return (cube,) + self.cube_dependencies(cube) + self.cube_recommends(cube) |
|
1451 | 44 |
|
0 | 45 |
@property |
46 |
def apphome(self): |
|
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
47 |
return None |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
48 |
def main_config_file(self): |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
49 |
return None |
0 | 50 |
def init_log(self, debug=None): |
51 |
pass |
|
52 |
def load_configuration(self): |
|
53 |
pass |
|
54 |
||
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
55 |
|
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
56 |
class DevDepConfiguration(DevCubeConfiguration): |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
57 |
"""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
|
58 |
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
|
59 |
""" |
396 | 60 |
|
61 |
def my_cubes(self, cube): |
|
62 |
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
|
63 |
|
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
64 |
def default_log_file(self): |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
65 |
return None |
0 | 66 |
|
67 |
||
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
68 |
def cleanup_sys_modules(config): |
0 | 69 |
# cleanup sys.modules, required when we're updating multiple cubes |
70 |
for name, mod in sys.modules.items(): |
|
71 |
if mod is None: |
|
72 |
# duh ? logilab.common.os for instance |
|
73 |
del sys.modules[name] |
|
74 |
continue |
|
75 |
if not hasattr(mod, '__file__'): |
|
76 |
continue |
|
77 |
for path in config.vregistry_path(): |
|
78 |
if mod.__file__.startswith(path): |
|
79 |
del sys.modules[name] |
|
80 |
break |
|
1850
75661f0a691b
should be outside the loop
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1774
diff
changeset
|
81 |
# fresh rtags |
75661f0a691b
should be outside the loop
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1774
diff
changeset
|
82 |
from cubicweb import rtags |
75661f0a691b
should be outside the loop
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1774
diff
changeset
|
83 |
from cubicweb.web import uicfg |
75661f0a691b
should be outside the loop
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1774
diff
changeset
|
84 |
rtags.RTAGS[:] = [] |
75661f0a691b
should be outside the loop
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1774
diff
changeset
|
85 |
reload(uicfg) |
1451 | 86 |
|
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
87 |
def generate_schema_pot(w, cubedir=None): |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
88 |
"""generate a pot file with schema specific i18n messages |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
89 |
|
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
90 |
notice that relation definitions description and static vocabulary |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
91 |
should be marked using '_' and extracted using xgettext |
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 |
from cubicweb.cwvreg import CubicWebRegistry |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
94 |
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
|
95 |
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
|
96 |
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
|
97 |
cleanup_sys_modules(libconfig) |
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
98 |
if cubedir: |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
99 |
config = DevCubeConfiguration(cube) |
1774
4f4e0c6682e5
fix cubes order while generating catalogs
sylvain.thenault@logilab.fr
parents:
1770
diff
changeset
|
100 |
config.cleanup_interface_sobjects = False |
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
101 |
else: |
1502 | 102 |
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
|
103 |
libconfig = None |
1665 | 104 |
schema = config.load_schema(remove_unused_rtypes=False) |
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
105 |
vreg = CubicWebRegistry(config) |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
106 |
# set_schema triggers objects registrations |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
107 |
vreg.set_schema(schema) |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
108 |
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
|
109 |
_generate_schema_pot(w, vreg, schema, libconfig=libconfig, cube=cube) |
1451 | 110 |
|
111 |
||
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 |
def _generate_schema_pot(w, vreg, schema, libconfig=None, cube=None): |
0 | 113 |
from cubicweb.common.i18n import add_msg |
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
396
diff
changeset
|
114 |
w('# schema pot file, generated on %s\n' % datetime.now().strftime('%Y-%m-%d %H:%M:%S')) |
0 | 115 |
w('# \n') |
116 |
w('# singular and plural forms for each entity type\n') |
|
117 |
w('\n') |
|
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
|
118 |
if libconfig is not None: |
1665 | 119 |
libschema = libconfig.load_schema(remove_unused_rtypes=False) |
0 | 120 |
entities = [e for e in schema.entities() if not e in libschema] |
121 |
else: |
|
122 |
entities = schema.entities() |
|
123 |
done = set() |
|
124 |
for eschema in sorted(entities): |
|
125 |
etype = eschema.type |
|
126 |
add_msg(w, etype) |
|
127 |
add_msg(w, '%s_plural' % etype) |
|
128 |
if not eschema.is_final(): |
|
129 |
add_msg(w, 'This %s' % etype) |
|
130 |
add_msg(w, 'New %s' % etype) |
|
131 |
add_msg(w, 'add a %s' % etype) |
|
132 |
add_msg(w, 'remove this %s' % etype) |
|
133 |
if eschema.description and not eschema.description in done: |
|
134 |
done.add(eschema.description) |
|
135 |
add_msg(w, eschema.description) |
|
136 |
w('# subject and object forms for each relation type\n') |
|
137 |
w('# (no object form for final relation types)\n') |
|
138 |
w('\n') |
|
1502 | 139 |
if libconfig is not None: |
0 | 140 |
relations = [r for r in schema.relations() if not r in libschema] |
141 |
else: |
|
142 |
relations = schema.relations() |
|
143 |
for rschema in sorted(set(relations)): |
|
144 |
rtype = rschema.type |
|
145 |
add_msg(w, rtype) |
|
57
3ab952845448
[devctl] fix bug in i18nlibupdate
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
146 |
done.add(rtype) |
0 | 147 |
if not (schema.rschema(rtype).is_final() or rschema.symetric): |
148 |
add_msg(w, '%s_object' % rtype) |
|
149 |
if rschema.description and rschema.description not in done: |
|
150 |
done.add(rschema.description) |
|
151 |
add_msg(w, rschema.description) |
|
152 |
w('# add related box generated message\n') |
|
153 |
w('\n') |
|
1415
98b8e5c627b8
fix actionbox def
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1263
diff
changeset
|
154 |
actionbox = vreg['boxes']['edit_box'][0] |
0 | 155 |
for eschema in schema.entities(): |
156 |
if eschema.is_final(): |
|
157 |
continue |
|
1451 | 158 |
for role, rschemas in (('subject', eschema.subject_relations()), |
0 | 159 |
('object', eschema.object_relations())): |
160 |
for rschema in rschemas: |
|
161 |
if rschema.is_final(): |
|
162 |
continue |
|
1665 | 163 |
if libconfig is not None: |
164 |
librschema = libschema.get(rschema) |
|
1451 | 165 |
for teschema in rschema.targets(eschema, role): |
1665 | 166 |
if libconfig is not None and librschema is not None: |
1502 | 167 |
if role == 'subject': |
1662 | 168 |
subjtype, objtype = eschema, teschema |
1502 | 169 |
else: |
1662 | 170 |
subjtype, objtype = teschema, eschema |
1665 | 171 |
if librschema.has_rdef(subjtype, objtype): |
1502 | 172 |
continue |
1739 | 173 |
if actionbox.appearsin_addmenu.etype_get(eschema, rschema, |
174 |
role, teschema): |
|
1451 | 175 |
if role == 'subject': |
176 |
label = 'add %s %s %s %s' % (eschema, rschema, |
|
177 |
teschema, role) |
|
178 |
label2 = "creating %s (%s %%(linkto)s %s %s)" % ( |
|
179 |
teschema, eschema, rschema, teschema) |
|
0 | 180 |
else: |
1451 | 181 |
label = 'add %s %s %s %s' % (teschema, rschema, |
182 |
eschema, role) |
|
183 |
label2 = "creating %s (%s %s %s %%(linkto)s)" % ( |
|
184 |
teschema, teschema, rschema, eschema) |
|
0 | 185 |
add_msg(w, label) |
186 |
add_msg(w, label2) |
|
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
|
187 |
#cube = (cube and 'cubes.%s.' % cube or 'cubicweb.') |
0 | 188 |
done = 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
|
189 |
if libconfig is not None: |
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
|
190 |
from cubicweb.cwvreg import CubicWebRegistry |
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
|
191 |
libvreg = CubicWebRegistry(libconfig) |
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
|
192 |
libvreg.set_schema(libschema) # trigger objects registration |
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
|
193 |
# prefill done set |
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
|
194 |
list(_iter_vreg_objids(libvreg, done)) |
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
|
195 |
for objid in _iter_vreg_objids(vreg, done): |
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
|
196 |
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
|
197 |
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
|
198 |
|
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
|
199 |
def _iter_vreg_objids(vreg, done, prefix=None): |
0 | 200 |
for reg, objdict in vreg.items(): |
201 |
for objects in objdict.values(): |
|
202 |
for obj in objects: |
|
203 |
objid = '%s_%s' % (reg, obj.id) |
|
204 |
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
|
205 |
break |
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
|
206 |
if obj.property_defs: |
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
|
207 |
yield objid |
0 | 208 |
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
|
209 |
break |
374
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
210 |
|
1451 | 211 |
|
1502 | 212 |
def defined_in_library(etype, rtype, tetype, role): |
1451 | 213 |
"""return true if the given relation definition exists in cubicweb's library |
214 |
""" |
|
0 | 215 |
if libschema is None: |
216 |
return False |
|
1451 | 217 |
if role == 'subject': |
0 | 218 |
subjtype, objtype = etype, tetype |
219 |
else: |
|
220 |
subjtype, objtype = tetype, etype |
|
221 |
try: |
|
222 |
return libschema.rschema(rtype).has_rdef(subjtype, objtype) |
|
223 |
except KeyError: |
|
224 |
return False |
|
225 |
||
226 |
||
155
9ed6db94a087
spanish is now a supported language
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
133
diff
changeset
|
227 |
LANGS = ('en', 'fr', 'es') |
0 | 228 |
I18NDIR = join(BASEDIR, 'i18n') |
229 |
DEFAULT_POT_HEAD = r'''msgid "" |
|
230 |
msgstr "" |
|
231 |
"Project-Id-Version: cubicweb %s\n" |
|
232 |
"PO-Revision-Date: 2008-03-28 18:14+0100\n" |
|
233 |
"Last-Translator: Logilab Team <contact@logilab.fr>\n" |
|
234 |
"Language-Team: fr <contact@logilab.fr>\n" |
|
235 |
"MIME-Version: 1.0\n" |
|
236 |
"Content-Type: text/plain; charset=UTF-8\n" |
|
237 |
"Content-Transfer-Encoding: 8bit\n" |
|
238 |
"Generated-By: cubicweb-devtools\n" |
|
239 |
"Plural-Forms: nplurals=2; plural=(n > 1);\n" |
|
240 |
||
241 |
''' % cubicwebversion |
|
242 |
||
243 |
||
244 |
class UpdateCubicWebCatalogCommand(Command): |
|
245 |
"""Update i18n catalogs for cubicweb library. |
|
1451 | 246 |
|
0 | 247 |
It will regenerate cubicweb/i18n/xx.po files. You'll have then to edit those |
248 |
files to add translations of newly added messages. |
|
249 |
""" |
|
1898
39b37f90a8a4
[cw-ctl] rename i18n commands (see #342889)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1850
diff
changeset
|
250 |
name = 'i18ncubicweb' |
0 | 251 |
|
252 |
def run(self, args): |
|
253 |
"""run the command with its specific arguments""" |
|
254 |
if args: |
|
255 |
raise BadCommandUsage('Too much arguments') |
|
256 |
import shutil |
|
2446
440cb4ea7e5c
[refactor] #342855: replace uses of (deprecated) mktemp
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
257 |
import tempfile |
0 | 258 |
import yams |
259 |
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
|
260 |
from logilab.common.shellutils import globfind, find, rm |
0 | 261 |
from cubicweb.common.i18n import extract_from_tal, execute |
2446
440cb4ea7e5c
[refactor] #342855: replace uses of (deprecated) mktemp
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
262 |
tempdir = tempdir.mkdtemp() |
0 | 263 |
potfiles = [join(I18NDIR, 'entities.pot')] |
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
264 |
print '-> extract schema messages.' |
0 | 265 |
schemapot = join(tempdir, 'schema.pot') |
266 |
potfiles.append(schemapot) |
|
267 |
# explicit close necessary else the file may not be yet flushed when |
|
268 |
# we'll using it below |
|
269 |
schemapotstream = file(schemapot, 'w') |
|
270 |
generate_schema_pot(schemapotstream.write, cubedir=None) |
|
271 |
schemapotstream.close() |
|
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
272 |
print '-> extract TAL messages.' |
0 | 273 |
tali18nfile = join(tempdir, 'tali18n.py') |
274 |
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
|
275 |
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
|
276 |
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
|
277 |
('schemadescr', globfind(join(BASEDIR, 'schemas'), '*.py'), None), |
0 | 278 |
('yams', get_module_files(yams.__path__[0]), None), |
279 |
('tal', [tali18nfile], None), |
|
58
c7c22b210372
only try to internationalize our own js files
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
57
diff
changeset
|
280 |
('js', globfind(join(BASEDIR, 'web'), 'cub*.js'), 'java'), |
0 | 281 |
]: |
60
dc90556488d8
oops, bad changeset review, revert debug changes
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
58
diff
changeset
|
282 |
cmd = 'xgettext --no-location --omit-header -k_ -o %s %s' |
0 | 283 |
if lang is not None: |
284 |
cmd += ' -L %s' % lang |
|
1502 | 285 |
potfile = join(tempdir, '%s.pot' % id) |
286 |
execute(cmd % (potfile, ' '.join(files))) |
|
287 |
if exists(potfile): |
|
288 |
potfiles.append(potfile) |
|
289 |
else: |
|
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
290 |
print '-> WARNING: %s file was not generated' % potfile |
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
291 |
print '-> merging %i .pot files' % len(potfiles) |
0 | 292 |
cubicwebpot = join(tempdir, 'cubicweb.pot') |
293 |
execute('msgcat %s > %s' % (' '.join(potfiles), cubicwebpot)) |
|
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
294 |
print '-> merging main pot file with existing translations.' |
0 | 295 |
chdir(I18NDIR) |
296 |
toedit = [] |
|
297 |
for lang in LANGS: |
|
298 |
target = '%s.po' % lang |
|
299 |
execute('msgmerge -N --sort-output %s %s > %snew' % (target, cubicwebpot, target)) |
|
300 |
ensure_fs_mode(target) |
|
301 |
shutil.move('%snew' % target, target) |
|
302 |
toedit.append(abspath(target)) |
|
303 |
# cleanup |
|
60
dc90556488d8
oops, bad changeset review, revert debug changes
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
58
diff
changeset
|
304 |
rm(tempdir) |
0 | 305 |
# instructions pour la suite |
2396
8bfb99d7bbcc
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2395
diff
changeset
|
306 |
print '-> regenerated CubicWeb\'s .po catalogs.' |
8bfb99d7bbcc
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2395
diff
changeset
|
307 |
print '\nYou can now edit the following files:' |
0 | 308 |
print '* ' + '\n* '.join(toedit) |
2396
8bfb99d7bbcc
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2395
diff
changeset
|
309 |
print 'when you are done, run "cubicweb-ctl i18ncube yourcube".' |
0 | 310 |
|
311 |
||
312 |
class UpdateTemplateCatalogCommand(Command): |
|
313 |
"""Update i18n catalogs for cubes. If no cube is specified, update |
|
314 |
catalogs of all registered cubes. |
|
315 |
""" |
|
1898
39b37f90a8a4
[cw-ctl] rename i18n commands (see #342889)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1850
diff
changeset
|
316 |
name = 'i18ncube' |
0 | 317 |
arguments = '[<cube>...]' |
1451 | 318 |
|
0 | 319 |
def run(self, args): |
320 |
"""run the command with its specific arguments""" |
|
321 |
if args: |
|
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
396
diff
changeset
|
322 |
cubes = [DevCubeConfiguration.cube_dir(cube) for cube in args] |
0 | 323 |
else: |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
396
diff
changeset
|
324 |
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
|
325 |
cubes = [cubepath for cubepath in cubes if exists(join(cubepath, 'i18n'))] |
0 | 326 |
update_cubes_catalogs(cubes) |
327 |
||
1770
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
328 |
|
0 | 329 |
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
|
330 |
for cubedir in cubes: |
2527
e60db6312aa0
per cube message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2458
diff
changeset
|
331 |
toedit = [] |
1770
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
332 |
if not isdir(cubedir): |
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
333 |
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
|
334 |
continue |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
335 |
try: |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
336 |
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
|
337 |
except Exception: |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
338 |
import traceback |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
339 |
traceback.print_exc() |
2527
e60db6312aa0
per cube message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2458
diff
changeset
|
340 |
print '-> error while updating catalogs for cube', cubedir |
e60db6312aa0
per cube message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2458
diff
changeset
|
341 |
else: |
e60db6312aa0
per cube message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2458
diff
changeset
|
342 |
# instructions pour la suite |
e60db6312aa0
per cube message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2458
diff
changeset
|
343 |
print '-> regenerated .po catalogs for cube %s.' % cubedir |
e60db6312aa0
per cube message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2458
diff
changeset
|
344 |
print '\nYou can now edit the following files:' |
e60db6312aa0
per cube message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2458
diff
changeset
|
345 |
print '* ' + '\n* '.join(toedit) |
e60db6312aa0
per cube message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2458
diff
changeset
|
346 |
print ('When you are done, run "cubicweb-ctl i18ninstance ' |
e60db6312aa0
per cube message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2458
diff
changeset
|
347 |
'<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
|
348 |
|
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
349 |
def update_cube_catalogs(cubedir): |
0 | 350 |
import shutil |
2446
440cb4ea7e5c
[refactor] #342855: replace uses of (deprecated) mktemp
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
351 |
import tempfile |
0 | 352 |
from logilab.common.fileutils import ensure_fs_mode |
353 |
from logilab.common.shellutils import find, rm |
|
354 |
from cubicweb.common.i18n import extract_from_tal, execute |
|
355 |
toedit = [] |
|
1770
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
356 |
cube = basename(normpath(cubedir)) |
2446
440cb4ea7e5c
[refactor] #342855: replace uses of (deprecated) mktemp
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
357 |
tempdir = tempfile.mkdtemp() |
2396
8bfb99d7bbcc
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2395
diff
changeset
|
358 |
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
|
359 |
chdir(cubedir) |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
360 |
potfiles = [join('i18n', scfile) for scfile in ('entities.pot',) |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
361 |
if exists(join('i18n', scfile))] |
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
362 |
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
|
363 |
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
|
364 |
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
|
365 |
# 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
|
366 |
# 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
|
367 |
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
|
368 |
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
|
369 |
schemapotstream.close() |
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
370 |
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
|
371 |
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
|
372 |
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
|
373 |
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
|
374 |
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
|
375 |
if jsfiles: |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
376 |
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
|
377 |
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
|
378 |
% (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
|
379 |
# 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
|
380 |
if exists(tmppotfile): |
0 | 381 |
potfiles.append(tmppotfile) |
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
382 |
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
|
383 |
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
|
384 |
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
|
385 |
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
|
386 |
execute('xgettext --no-location --omit-header -k_ -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
|
387 |
% (tmppotfile, ' '.join(cubefiles))) |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
388 |
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
|
389 |
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
|
390 |
potfile = join(tempdir, 'cube.pot') |
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
391 |
print '-> merging %i .pot files:' % len(potfiles) |
1770
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
392 |
execute('msgcat %s > %s' % (' '.join(potfiles), potfile)) |
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
393 |
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
|
394 |
chdir('i18n') |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
395 |
for lang in LANGS: |
2395
e3093fc12a00
[cw-ctl] improve dialog messages
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
396 |
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
|
397 |
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
|
398 |
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
|
399 |
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
|
400 |
else: |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
401 |
execute('msgmerge -N -s %s %s > %snew' % (cubepo, potfile, cubepo)) |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
402 |
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
|
403 |
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
|
404 |
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
|
405 |
# cleanup |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
406 |
rm(tempdir) |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
407 |
return toedit |
0 | 408 |
|
409 |
||
410 |
class LiveServerCommand(Command): |
|
411 |
"""Run a server from within a cube directory. |
|
412 |
""" |
|
413 |
name = 'live-server' |
|
414 |
arguments = '' |
|
415 |
options = () |
|
1451 | 416 |
|
0 | 417 |
def run(self, args): |
418 |
"""run the command with its specific arguments""" |
|
419 |
from cubicweb.devtools.livetest import runserver |
|
420 |
runserver() |
|
421 |
||
422 |
||
132
561671b87c22
rename NewTemplateCommand class into NewCubeCommand
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
61
diff
changeset
|
423 |
class NewCubeCommand(Command): |
0 | 424 |
"""Create a new cube. |
425 |
||
426 |
<cubename> |
|
427 |
the name of the new cube |
|
428 |
""" |
|
429 |
name = 'newcube' |
|
430 |
arguments = '<cubename>' |
|
431 |
||
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
|
432 |
options = ( |
1106
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
433 |
("directory", |
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
434 |
{'short': 'd', 'type' : 'string', 'metavar': '<cubes directory>', |
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
435 |
'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
|
436 |
} |
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
437 |
), |
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
|
438 |
("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
|
439 |
{'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
|
440 |
'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
|
441 |
'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
|
442 |
} |
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
443 |
), |
365
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
444 |
("author", |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
445 |
{'short': 'a', 'type' : 'string', 'metavar': '<author>', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
446 |
'default': 'LOGILAB S.A. (Paris, FRANCE)', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
447 |
'help': 'cube author', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
448 |
} |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
449 |
), |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
450 |
("author-email", |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
451 |
{'short': 'e', 'type' : 'string', 'metavar': '<email>', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
452 |
'default': 'contact@logilab.fr', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
453 |
'help': 'cube author\'s email', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
454 |
} |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
455 |
), |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
456 |
("author-web-site", |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
457 |
{'short': 'w', 'type' : 'string', 'metavar': '<web site>', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
458 |
'default': 'http://www.logilab.fr', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
459 |
'help': 'cube author\'s web site', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
460 |
} |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
461 |
), |
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
|
462 |
) |
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 |
|
1451 | 464 |
|
0 | 465 |
def run(self, args): |
466 |
if len(args) != 1: |
|
467 |
raise BadCommandUsage("exactly one argument (cube name) is expected") |
|
468 |
cubename, = args |
|
264
6eb0725d509d
packaging fix: distribute skeleton
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
155
diff
changeset
|
469 |
#if ServerConfiguration.mode != "dev": |
6eb0725d509d
packaging fix: distribute skeleton
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
155
diff
changeset
|
470 |
# 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
|
471 |
verbose = self.get('verbose') |
1106
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
472 |
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
|
473 |
if not cubesdir: |
163e6a65d488
fix dumb name error, should call cubes_search_path, not cubes_path
sylvain.thenault@logilab.fr
parents:
1106
diff
changeset
|
474 |
cubespath = ServerConfiguration.cubes_search_path() |
1106
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
475 |
if len(cubespath) > 1: |
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
476 |
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
|
477 |
" Please specify it using the --directory option") |
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
478 |
cubesdir = cubespath[0] |
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
479 |
if not isdir(cubesdir): |
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
480 |
print "creating cubes directory", cubesdir |
0 | 481 |
try: |
1106
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
482 |
mkdir(cubesdir) |
0 | 483 |
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
|
484 |
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
|
485 |
cubedir = join(cubesdir, cubename) |
0 | 486 |
if exists(cubedir): |
487 |
self.fail("%s already exists !" % (cubedir)) |
|
488 |
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
|
489 |
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
|
490 |
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
|
491 |
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
|
492 |
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
|
493 |
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
|
494 |
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
|
495 |
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
|
496 |
else: |
0 | 497 |
distname = 'cubicweb-%s' % cubename.lower() |
1451 | 498 |
|
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
|
499 |
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
|
500 |
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
|
501 |
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
|
502 |
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
|
503 |
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
|
504 |
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
|
505 |
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
|
506 |
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
|
507 |
dependancies = ', '.join(repr(cube) for cube in includes) |
0 | 508 |
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
|
509 |
dependancies = '' |
0 | 510 |
context = {'cubename' : cubename, |
511 |
'distname' : distname, |
|
512 |
'shortdesc' : shortdesc, |
|
513 |
'longdesc' : longdesc or shortdesc, |
|
514 |
'dependancies' : dependancies, |
|
515 |
'version' : cubicwebversion, |
|
1016
26387b836099
use datetime instead of mx.DateTime
sylvain.thenault@logilab.fr
parents:
396
diff
changeset
|
516 |
'year' : str(datetime.now().year), |
365
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
517 |
'author': self['author'], |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
518 |
'author-email': self['author-email'], |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
519 |
'author-web-site': self['author-web-site'], |
0 | 520 |
} |
521 |
copy_skeleton(skeldir, cubedir, context) |
|
522 |
||
523 |
def _ask_for_dependancies(self): |
|
524 |
includes = [] |
|
525 |
for stdtype in ServerConfiguration.available_cubes(): |
|
526 |
ans = raw_input("Depends on cube %s? (N/y/s(kip)/t(ype)" |
|
527 |
% stdtype).lower().strip() |
|
528 |
if ans == 'y': |
|
529 |
includes.append(stdtype) |
|
530 |
if ans == 't': |
|
531 |
includes = get_csv(raw_input('type dependancies: ')) |
|
532 |
break |
|
533 |
elif ans == 's': |
|
534 |
break |
|
535 |
return includes |
|
1451 | 536 |
|
374
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
537 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
538 |
class ExamineLogCommand(Command): |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
539 |
"""Examine a rql log file. |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
540 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
541 |
usage: python exlog.py < rql.log |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
542 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
543 |
will print out the following table |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
544 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
545 |
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
|
546 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
547 |
sorted by descending total execution time |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
548 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
549 |
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
|
550 |
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
|
551 |
""" |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
552 |
name = 'exlog' |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
553 |
options = ( |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
554 |
) |
1451 | 555 |
|
374
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
556 |
def run(self, args): |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
557 |
if args: |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
558 |
raise BadCommandUsage("no argument expected") |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
559 |
import re |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
560 |
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
|
561 |
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
|
562 |
if not ' WHERE ' in line: |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
563 |
continue |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
564 |
#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
|
565 |
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
|
566 |
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
|
567 |
rql = re.sub("(\'\w+': \d*)", '', rql) |
1189
8a075bc94563
[devtools] improve output of exlog command
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1188
diff
changeset
|
568 |
if '{' in rql: |
8a075bc94563
[devtools] improve output of exlog command
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1188
diff
changeset
|
569 |
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
|
570 |
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
|
571 |
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
|
572 |
chunks = time.split() |
2092
f5102472243d
[exlog] print clocktime in addition to cputime
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
573 |
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
|
574 |
cputime = float(chunks[-3]) |
2092
f5102472243d
[exlog] print clocktime in addition to cputime
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
575 |
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
|
576 |
except Exception, exc: |
1189
8a075bc94563
[devtools] improve output of exlog command
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1188
diff
changeset
|
577 |
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
|
578 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
579 |
stat = [] |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
580 |
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
|
581 |
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
|
582 |
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
|
583 |
len(times), rql) ) |
374
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
584 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
585 |
stat.sort() |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
586 |
stat.reverse() |
1189
8a075bc94563
[devtools] improve output of exlog command
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1188
diff
changeset
|
587 |
|
2092
f5102472243d
[exlog] print clocktime in addition to cputime
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
588 |
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
|
589 |
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
|
590 |
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
|
591 |
print '%.2f;%.2f;%.2f;%s;%s' % (clocktime/total_time, clocktime, cputime, occ, rql) |
1451 | 592 |
|
0 | 593 |
register_commands((UpdateCubicWebCatalogCommand, |
594 |
UpdateTemplateCatalogCommand, |
|
595 |
LiveServerCommand, |
|
132
561671b87c22
rename NewTemplateCommand class into NewCubeCommand
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
61
diff
changeset
|
596 |
NewCubeCommand, |
374
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
597 |
ExamineLogCommand, |
0 | 598 |
)) |