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