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