author | Denis Laxalde <denis.laxalde@logilab.fr> |
Wed, 05 Apr 2017 10:34:04 +0200 | |
branch | 3.25 |
changeset 12132 | be2c14ea2736 |
parent 12080 | b8c4a8bab7b3 |
child 12508 | a8c1ea390400 |
child 12687 | 59c3e639f62c |
permissions | -rw-r--r-- |
9201
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
1 |
# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5375
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5375
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5375
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5375
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5375
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5375
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5375
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5375
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5375
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5375
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5375
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5375
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5375
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5375
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5375
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5545
diff
changeset
|
18 |
"""additional cubicweb-ctl commands and command handlers for cubicweb and |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5545
diff
changeset
|
19 |
cubicweb's cubes development |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5545
diff
changeset
|
20 |
""" |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10474
diff
changeset
|
21 |
from __future__ import print_function |
0 | 22 |
|
4718
3dc3ad02d091
avoid module import in c-c plugins module, and remind it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4708
diff
changeset
|
23 |
# *ctl module should limit the number of import to be imported as quickly as |
3dc3ad02d091
avoid module import in c-c plugins module, and remind it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4708
diff
changeset
|
24 |
# possible (for cubicweb-ctl reactivity, necessary for instance for usable bash |
3dc3ad02d091
avoid module import in c-c plugins module, and remind it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4708
diff
changeset
|
25 |
# completion). So import locally in command helpers. |
11726
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
26 |
|
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
27 |
import shutil |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
28 |
import tempfile |
0 | 29 |
import sys |
10963
9b1c7f337eb3
[devtools] stop using datetime.now() in cwctl newcube and i18ncube
Julien Cristau <julien.cristau@logilab.fr>
parents:
10686
diff
changeset
|
30 |
from datetime import datetime, date |
12080
b8c4a8bab7b3
[devtools] Create "newcube" in current directory by default
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11900
diff
changeset
|
31 |
from os import getcwd, mkdir, chdir, path as osp |
11735
7a170207acbf
[devtools] make i18ncube customizable in a cube
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11728
diff
changeset
|
32 |
import pkg_resources |
2551
91f579b7a1e1
[F bw compat] warn if entities.pot exists but consider it anyway
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2534
diff
changeset
|
33 |
from warnings import warn |
0 | 34 |
|
11716
c7de052ee288
[skeleton] Properly format debian/changelog using current datetime and author information
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11468
diff
changeset
|
35 |
from pytz import UTC |
11735
7a170207acbf
[devtools] make i18ncube customizable in a cube
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11728
diff
changeset
|
36 |
|
10967
3f620fd1ed18
[devtools] Fix 'newcube' on py3k
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10963
diff
changeset
|
37 |
from six.moves import input |
3f620fd1ed18
[devtools] Fix 'newcube' on py3k
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10963
diff
changeset
|
38 |
|
0 | 39 |
from logilab.common import STD_BLACKLIST |
11900
8496135b6dc1
[cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11822
diff
changeset
|
40 |
from logilab.common.modutils import clean_sys_modules |
11726
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
41 |
from logilab.common.fileutils import ensure_fs_mode |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
42 |
from logilab.common.shellutils import find |
4428
03614b377ecd
Add a ``schema`` command to cmd ctrl to generate schema image.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4400
diff
changeset
|
43 |
|
3978
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3858
diff
changeset
|
44 |
from cubicweb.__pkginfo__ import version as cubicwebversion |
8247
65b0d2587fb5
[cubicweb-ctl] i18ncube return 2 (failed command) on failure (closes #2192336)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7990
diff
changeset
|
45 |
from cubicweb import CW_SOFTWARE_ROOT as BASEDIR, BadCommandUsage, ExecutionError |
11726
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
46 |
from cubicweb.i18n import extract_from_tal, execute2 |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5775
diff
changeset
|
47 |
from cubicweb.cwctl import CWCTL |
6749
48f468f33704
[config, i18n] Create default translation mechanism for all supported languages.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6356
diff
changeset
|
48 |
from cubicweb.cwconfig import CubicWebNoAppConfiguration |
6356
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
49 |
from cubicweb.toolsutils import (SKEL_EXCLUDE, Command, copy_skeleton, |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
50 |
underline_title) |
0 | 51 |
from cubicweb.web.webconfig import WebConfiguration |
52 |
from cubicweb.server.serverconfig import ServerConfiguration |
|
53 |
||
2790
968108e16066
move underline_title to toolsutils
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2773
diff
changeset
|
54 |
|
11726
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
55 |
__docformat__ = "restructuredtext en" |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
56 |
|
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
57 |
|
11088
b62b9d78b533
ensure .tox is blacklisted when recursing on the fs to get some files
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10967
diff
changeset
|
58 |
STD_BLACKLIST = set(STD_BLACKLIST) |
b62b9d78b533
ensure .tox is blacklisted when recursing on the fs to get some files
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10967
diff
changeset
|
59 |
STD_BLACKLIST.add('.tox') |
b62b9d78b533
ensure .tox is blacklisted when recursing on the fs to get some files
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10967
diff
changeset
|
60 |
STD_BLACKLIST.add('test') |
11727
2efe0bf90ebb
i18ncube should ignore node_modules directory by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11726
diff
changeset
|
61 |
STD_BLACKLIST.add('node_modules') |
11088
b62b9d78b533
ensure .tox is blacklisted when recursing on the fs to get some files
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10967
diff
changeset
|
62 |
|
b62b9d78b533
ensure .tox is blacklisted when recursing on the fs to get some files
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10967
diff
changeset
|
63 |
|
4479
f25e61a93c42
replace DevCubeConfiguration/DevDepsConfiguration by a single DevConfiguration, fixing recently introduced by w/ i18ncube command on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
64 |
class DevConfiguration(ServerConfiguration, WebConfiguration): |
f25e61a93c42
replace DevCubeConfiguration/DevDepsConfiguration by a single DevConfiguration, fixing recently introduced by w/ i18ncube command on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
65 |
"""dummy config to get full library schema and appobjects for |
f25e61a93c42
replace DevCubeConfiguration/DevDepsConfiguration by a single DevConfiguration, fixing recently introduced by w/ i18ncube command on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
66 |
a cube or for cubicweb (without a home) |
f25e61a93c42
replace DevCubeConfiguration/DevDepsConfiguration by a single DevConfiguration, fixing recently introduced by w/ i18ncube command on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
67 |
""" |
0 | 68 |
creating = True |
9258
4e79f587c6ab
Rename cleanup_interface_sobjects into cleanup_unused_appobjects
Julien Cristau <julien.cristau@logilab.fr>
parents:
9231
diff
changeset
|
69 |
cleanup_unused_appobjects = False |
4479
f25e61a93c42
replace DevCubeConfiguration/DevDepsConfiguration by a single DevConfiguration, fixing recently introduced by w/ i18ncube command on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
70 |
|
f25e61a93c42
replace DevCubeConfiguration/DevDepsConfiguration by a single DevConfiguration, fixing recently introduced by w/ i18ncube command on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
71 |
cubicweb_appobject_path = (ServerConfiguration.cubicweb_appobject_path |
f25e61a93c42
replace DevCubeConfiguration/DevDepsConfiguration by a single DevConfiguration, fixing recently introduced by w/ i18ncube command on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
72 |
| WebConfiguration.cubicweb_appobject_path) |
f25e61a93c42
replace DevCubeConfiguration/DevDepsConfiguration by a single DevConfiguration, fixing recently introduced by w/ i18ncube command on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
73 |
cube_appobject_path = (ServerConfiguration.cube_appobject_path |
f25e61a93c42
replace DevCubeConfiguration/DevDepsConfiguration by a single DevConfiguration, fixing recently introduced by w/ i18ncube command on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
74 |
| WebConfiguration.cube_appobject_path) |
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
75 |
|
4428
03614b377ecd
Add a ``schema`` command to cmd ctrl to generate schema image.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4400
diff
changeset
|
76 |
def __init__(self, *cubes): |
4479
f25e61a93c42
replace DevCubeConfiguration/DevDepsConfiguration by a single DevConfiguration, fixing recently introduced by w/ i18ncube command on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
77 |
super(DevConfiguration, self).__init__(cubes and cubes[0] or None) |
f25e61a93c42
replace DevCubeConfiguration/DevDepsConfiguration by a single DevConfiguration, fixing recently introduced by w/ i18ncube command on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
78 |
if cubes: |
f25e61a93c42
replace DevCubeConfiguration/DevDepsConfiguration by a single DevConfiguration, fixing recently introduced by w/ i18ncube command on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
79 |
self._cubes = self.reorder_cubes( |
f25e61a93c42
replace DevCubeConfiguration/DevDepsConfiguration by a single DevConfiguration, fixing recently introduced by w/ i18ncube command on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
80 |
self.expand_cubes(cubes, with_recommends=True)) |
5534
b75aa6ce0c04
[i18ncube] we must load site_cubicweb file before calling set_schema, else we may miss some options or other initialization stuff necessary to appobject loading
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5456
diff
changeset
|
81 |
self.load_site_cubicweb() |
4479
f25e61a93c42
replace DevCubeConfiguration/DevDepsConfiguration by a single DevConfiguration, fixing recently introduced by w/ i18ncube command on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
82 |
else: |
f25e61a93c42
replace DevCubeConfiguration/DevDepsConfiguration by a single DevConfiguration, fixing recently introduced by w/ i18ncube command on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
83 |
self._cubes = () |
1451 | 84 |
|
0 | 85 |
@property |
86 |
def apphome(self): |
|
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
87 |
return None |
6749
48f468f33704
[config, i18n] Create default translation mechanism for all supported languages.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6356
diff
changeset
|
88 |
|
48f468f33704
[config, i18n] Create default translation mechanism for all supported languages.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6356
diff
changeset
|
89 |
def available_languages(self): |
48f468f33704
[config, i18n] Create default translation mechanism for all supported languages.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6356
diff
changeset
|
90 |
return self.cw_languages() |
48f468f33704
[config, i18n] Create default translation mechanism for all supported languages.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6356
diff
changeset
|
91 |
|
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
92 |
def main_config_file(self): |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
93 |
return None |
5442
3ed8afbbdf70
[webconfig] refactor/cleanup debug mode management on startup: simply use config.debugmode instead of debug argument everywhere...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
94 |
def init_log(self): |
0 | 95 |
pass |
10474
1dcc52f5e340
[cwctl] allow overriding config settings from the command line (closes #5557656)
David Douard <david.douard@logilab.fr>
parents:
10413
diff
changeset
|
96 |
def load_configuration(self, **kw): |
0 | 97 |
pass |
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
98 |
def default_log_file(self): |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
99 |
return None |
10308
3f94034cc972
[hooks] add a looping task that dumps the stats regularly in a file
David Douard <david.douard@logilab.fr>
parents:
10301
diff
changeset
|
100 |
def default_stats_file(self): |
3f94034cc972
[hooks] add a looping task that dumps the stats regularly in a file
David Douard <david.douard@logilab.fr>
parents:
10301
diff
changeset
|
101 |
return None |
0 | 102 |
|
103 |
||
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
104 |
def generate_schema_pot(w, cubedir=None): |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
105 |
"""generate a pot file with schema specific i18n messages |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
106 |
|
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
107 |
notice that relation definitions description and static vocabulary |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
108 |
should be marked using '_' and extracted using xgettext |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
109 |
""" |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
110 |
from cubicweb.cwvreg import CWRegistryStore |
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
111 |
if cubedir: |
6356
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
112 |
cube = osp.split(cubedir)[-1] |
11460
5be729810695
[devtools] Handle i18ncube command for "cubes as packages"
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11454
diff
changeset
|
113 |
if cube.startswith('cubicweb_'): |
5be729810695
[devtools] Handle i18ncube command for "cubes as packages"
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11454
diff
changeset
|
114 |
cube = cube[len('cubicweb_'):] |
4479
f25e61a93c42
replace DevCubeConfiguration/DevDepsConfiguration by a single DevConfiguration, fixing recently introduced by w/ i18ncube command on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
115 |
config = DevConfiguration(cube) |
f25e61a93c42
replace DevCubeConfiguration/DevDepsConfiguration by a single DevConfiguration, fixing recently introduced by w/ i18ncube command on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
116 |
depcubes = list(config._cubes) |
f25e61a93c42
replace DevCubeConfiguration/DevDepsConfiguration by a single DevConfiguration, fixing recently introduced by w/ i18ncube command on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
117 |
depcubes.remove(cube) |
f25e61a93c42
replace DevCubeConfiguration/DevDepsConfiguration by a single DevConfiguration, fixing recently introduced by w/ i18ncube command on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
118 |
libconfig = DevConfiguration(*depcubes) |
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
119 |
else: |
4479
f25e61a93c42
replace DevCubeConfiguration/DevDepsConfiguration by a single DevConfiguration, fixing recently introduced by w/ i18ncube command on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
120 |
config = DevConfiguration() |
f25e61a93c42
replace DevCubeConfiguration/DevDepsConfiguration by a single DevConfiguration, fixing recently introduced by w/ i18ncube command on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
121 |
cube = libconfig = None |
11900
8496135b6dc1
[cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11822
diff
changeset
|
122 |
clean_sys_modules(config.appobjects_modnames()) |
1665 | 123 |
schema = config.load_schema(remove_unused_rtypes=False) |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
124 |
vreg = CWRegistryStore(config) |
373
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
125 |
# set_schema triggers objects registrations |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
126 |
vreg.set_schema(schema) |
0c931b2e2a68
fix i18n catalog generation
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
365
diff
changeset
|
127 |
w(DEFAULT_POT_HEAD) |
4722
9c13d5db03d9
pylint suggested refactorings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
128 |
_generate_schema_pot(w, vreg, schema, libconfig=libconfig) |
1451 | 129 |
|
130 |
||
4718
3dc3ad02d091
avoid module import in c-c plugins module, and remind it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4708
diff
changeset
|
131 |
def _generate_schema_pot(w, vreg, schema, libconfig=None): |
4021
280c910c8710
move i18n / migration modules from cw.common to cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3998
diff
changeset
|
132 |
from cubicweb.i18n import add_msg |
6481
103774c8c215
[schema categorization] new NO_I18NCONTEXT set usable to somewhat control c-c i18n
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6460
diff
changeset
|
133 |
from cubicweb.schema import NO_I18NCONTEXT, CONSTRAINTS |
6356
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
134 |
w('# schema pot file, generated on %s\n' |
10963
9b1c7f337eb3
[devtools] stop using datetime.now() in cwctl newcube and i18ncube
Julien Cristau <julien.cristau@logilab.fr>
parents:
10686
diff
changeset
|
135 |
% datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')) |
0 | 136 |
w('# \n') |
137 |
w('# singular and plural forms for each entity type\n') |
|
138 |
w('\n') |
|
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
139 |
vregdone = set() |
9154
e713c47a993d
[devctl] properly generate i18n messsages for cubes that uses uicfg instances (closes #2811282)
David Douard <david.douard@logilab.fr>
parents:
8866
diff
changeset
|
140 |
afss = vreg['uicfg']['autoform_section'] |
9201
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
141 |
aiams = vreg['uicfg']['actionbox_appearsin_addmenu'] |
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
|
142 |
if libconfig is not None: |
9201
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
143 |
# processing a cube, libconfig being a config with all its dependencies |
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
144 |
# (cubicweb incl.) |
8666
1dd655788ece
make ui configurations selectable (closes #2406609)
Florent Cayré <florent.cayre@logilab.fr>
parents:
8665
diff
changeset
|
145 |
from cubicweb.cwvreg import CWRegistryStore |
1665 | 146 |
libschema = libconfig.load_schema(remove_unused_rtypes=False) |
11900
8496135b6dc1
[cwvreg] load registry using modules names instead of directories
Philippe Pepiot <philippe.pepiot@logilab.fr>
parents:
11822
diff
changeset
|
147 |
clean_sys_modules(libconfig.appobjects_modnames()) |
8190
2a3c1b787688
[vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7990
diff
changeset
|
148 |
libvreg = CWRegistryStore(libconfig) |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
149 |
libvreg.set_schema(libschema) # trigger objects registration |
9154
e713c47a993d
[devctl] properly generate i18n messsages for cubes that uses uicfg instances (closes #2811282)
David Douard <david.douard@logilab.fr>
parents:
8866
diff
changeset
|
150 |
libafss = libvreg['uicfg']['autoform_section'] |
9201
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
151 |
libaiams = libvreg['uicfg']['actionbox_appearsin_addmenu'] |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
152 |
# prefill vregdone set |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
153 |
list(_iter_vreg_objids(libvreg, vregdone)) |
9201
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
154 |
|
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
155 |
def is_in_lib(rtags, eschema, rschema, role, tschema, predicate=bool): |
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
156 |
return any(predicate(rtag.etype_get(eschema, rschema, role, tschema)) |
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
157 |
for rtag in rtags) |
0 | 158 |
else: |
9201
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
159 |
# processing cubicweb itself |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
160 |
libschema = {} |
3978
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3858
diff
changeset
|
161 |
for cstrtype in CONSTRAINTS: |
2c95e3033f64
finish yesterday work on rql constraints:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3858
diff
changeset
|
162 |
add_msg(w, cstrtype) |
9231
d2edd8ac5f33
[c-c i18ncubicweb] fix crash, closes #3096647
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9203
diff
changeset
|
163 |
libafss = libaiams = None |
d2edd8ac5f33
[c-c i18ncubicweb] fix crash, closes #3096647
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9203
diff
changeset
|
164 |
is_in_lib = lambda *args: False |
0 | 165 |
done = set() |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
166 |
for eschema in sorted(schema.entities()): |
7745
1013c31bfbee
[.po generation] closes #1902315: c i18ncube doesn't consider relation definition description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6750
diff
changeset
|
167 |
if eschema.type in libschema: |
1013c31bfbee
[.po generation] closes #1902315: c i18ncube doesn't consider relation definition description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6750
diff
changeset
|
168 |
done.add(eschema.description) |
1013c31bfbee
[.po generation] closes #1902315: c i18ncube doesn't consider relation definition description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6750
diff
changeset
|
169 |
for eschema in sorted(schema.entities()): |
0 | 170 |
etype = eschema.type |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
171 |
if etype not in libschema: |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
172 |
add_msg(w, etype) |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
173 |
add_msg(w, '%s_plural' % etype) |
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
174 |
if not eschema.final: |
10163
4001cfe2f44d
[web/views] Stop mishandling the fieldset name in the default form renderer
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9543
diff
changeset
|
175 |
add_msg(w, 'This %s:' % etype) |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
176 |
add_msg(w, 'New %s' % etype) |
10217
75cd7df5c32e
[i18n generation] add missing 'add a EntityType' message to generated catalogs. Closes #5012581
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9543
diff
changeset
|
177 |
add_msg(w, 'add a %s' % etype) # AddNewAction |
10174
7e1c8fb9c407
[devtools] restore i18n of string removed in 4001cfe2f44d
Julien Cristau <julien.cristau@logilab.fr>
parents:
10163
diff
changeset
|
178 |
if libconfig is not None: # processing a cube |
7e1c8fb9c407
[devtools] restore i18n of string removed in 4001cfe2f44d
Julien Cristau <julien.cristau@logilab.fr>
parents:
10163
diff
changeset
|
179 |
# As of 3.20.3 we no longer use it, but keeping this string |
7e1c8fb9c407
[devtools] restore i18n of string removed in 4001cfe2f44d
Julien Cristau <julien.cristau@logilab.fr>
parents:
10163
diff
changeset
|
180 |
# allows developers to run i18ncube with new cubicweb and still |
7e1c8fb9c407
[devtools] restore i18n of string removed in 4001cfe2f44d
Julien Cristau <julien.cristau@logilab.fr>
parents:
10163
diff
changeset
|
181 |
# have the right translations at runtime for older versions |
7e1c8fb9c407
[devtools] restore i18n of string removed in 4001cfe2f44d
Julien Cristau <julien.cristau@logilab.fr>
parents:
10163
diff
changeset
|
182 |
add_msg(w, 'This %s' % etype) |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
183 |
if eschema.description and not eschema.description in done: |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
184 |
done.add(eschema.description) |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
185 |
add_msg(w, eschema.description) |
3689
deb13e88e037
follow yams 0.25 api changes to improve performance
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3638
diff
changeset
|
186 |
if eschema.final: |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
187 |
continue |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
188 |
for rschema, targetschemas, role in eschema.relation_definitions(True): |
4399
bc8d7ac70347
skip final relations at this point
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
189 |
if rschema.final: |
bc8d7ac70347
skip final relations at this point
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4380
diff
changeset
|
190 |
continue |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
191 |
for tschema in targetschemas: |
9154
e713c47a993d
[devctl] properly generate i18n messsages for cubes that uses uicfg instances (closes #2811282)
David Douard <david.douard@logilab.fr>
parents:
8866
diff
changeset
|
192 |
|
9201
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
193 |
for afs in afss: |
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
194 |
fsections = afs.etype_get(eschema, rschema, role, tschema) |
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
195 |
if 'main_inlined' in fsections and not \ |
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
196 |
is_in_lib(libafss, eschema, rschema, role, tschema, |
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
197 |
lambda x: 'main_inlined' in x): |
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
198 |
add_msg(w, 'add a %s' % tschema, |
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
199 |
'inlined:%s.%s.%s' % (etype, rschema, role)) |
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
200 |
add_msg(w, str(tschema), |
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
201 |
'inlined:%s.%s.%s' % (etype, rschema, role)) |
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
202 |
break |
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
203 |
|
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
204 |
for aiam in aiams: |
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
205 |
if aiam.etype_get(eschema, rschema, role, tschema) and not \ |
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
206 |
is_in_lib(libaiams, eschema, rschema, role, tschema): |
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
207 |
if role == 'subject': |
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
208 |
label = 'add %s %s %s %s' % (eschema, rschema, |
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
209 |
tschema, role) |
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
210 |
label2 = "creating %s (%s %%(linkto)s %s %s)" % ( |
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
211 |
tschema, eschema, rschema, tschema) |
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
212 |
else: |
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
213 |
label = 'add %s %s %s %s' % (tschema, rschema, |
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
214 |
eschema, role) |
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
215 |
label2 = "creating %s (%s %s %s %%(linkto)s)" % ( |
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
216 |
tschema, tschema, rschema, eschema) |
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
217 |
add_msg(w, label) |
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
218 |
add_msg(w, label2) |
b0f6e8c14e7f
[i18ncube] fix crash due to duplicated messages in generated schema.pot
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9157
diff
changeset
|
219 |
break |
3858
ba96e4607e67
add XX reminder
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
220 |
# XXX also generate "creating ...' messages for actions in the |
ba96e4607e67
add XX reminder
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3689
diff
changeset
|
221 |
# addrelated submenu |
0 | 222 |
w('# subject and object forms for each relation type\n') |
4467
0e73d299730a
fix long-waiting symetric typo: should be spelled symmetric. Add auto database migration on schema deserialization
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4439
diff
changeset
|
223 |
w('# (no object form for final or symmetric relation types)\n') |
0 | 224 |
w('\n') |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
225 |
for rschema in sorted(schema.relations()): |
7745
1013c31bfbee
[.po generation] closes #1902315: c i18ncube doesn't consider relation definition description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6750
diff
changeset
|
226 |
if rschema.type in libschema: |
1013c31bfbee
[.po generation] closes #1902315: c i18ncube doesn't consider relation definition description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6750
diff
changeset
|
227 |
done.add(rschema.type) |
1013c31bfbee
[.po generation] closes #1902315: c i18ncube doesn't consider relation definition description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6750
diff
changeset
|
228 |
done.add(rschema.description) |
1013c31bfbee
[.po generation] closes #1902315: c i18ncube doesn't consider relation definition description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6750
diff
changeset
|
229 |
for rschema in sorted(schema.relations()): |
0 | 230 |
rtype = rschema.type |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
231 |
if rtype not in libschema: |
6356
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
232 |
# bw compat, necessary until all translation of relation are done |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
233 |
# properly... |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
234 |
add_msg(w, rtype) |
7745
1013c31bfbee
[.po generation] closes #1902315: c i18ncube doesn't consider relation definition description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6750
diff
changeset
|
235 |
done.add(rtype) |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
236 |
if rschema.description and rschema.description not in done: |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
237 |
add_msg(w, rschema.description) |
7745
1013c31bfbee
[.po generation] closes #1902315: c i18ncube doesn't consider relation definition description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6750
diff
changeset
|
238 |
done.add(rschema.description) |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
239 |
librschema = None |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
240 |
else: |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
241 |
librschema = libschema.rschema(rtype) |
3281
bea1bde00fbc
[i18n] do not add context information for metadata relations
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3280
diff
changeset
|
242 |
# add context information only for non-metadata rtypes |
6481
103774c8c215
[schema categorization] new NO_I18NCONTEXT set usable to somewhat control c-c i18n
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6460
diff
changeset
|
243 |
if rschema not in NO_I18NCONTEXT: |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
244 |
libsubjects = librschema and librschema.subjects() or () |
3281
bea1bde00fbc
[i18n] do not add context information for metadata relations
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3280
diff
changeset
|
245 |
for subjschema in rschema.subjects(): |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
246 |
if not subjschema in libsubjects: |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
247 |
add_msg(w, rtype, subjschema.type) |
7745
1013c31bfbee
[.po generation] closes #1902315: c i18ncube doesn't consider relation definition description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6750
diff
changeset
|
248 |
if not (rschema.final or rschema.symmetric): |
6481
103774c8c215
[schema categorization] new NO_I18NCONTEXT set usable to somewhat control c-c i18n
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6460
diff
changeset
|
249 |
if rschema not in NO_I18NCONTEXT: |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
250 |
libobjects = librschema and librschema.objects() or () |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
251 |
for objschema in rschema.objects(): |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
252 |
if not objschema in libobjects: |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
253 |
add_msg(w, '%s_object' % rtype, objschema.type) |
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
254 |
if rtype not in libschema: |
6356
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
255 |
# bw compat, necessary until all translation of relation are |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
256 |
# done properly... |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
257 |
add_msg(w, '%s_object' % rtype) |
10663
54b8a1f249fb
[py3k] dict.itervalues → dict.values
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10662
diff
changeset
|
258 |
for rdef in rschema.rdefs.values(): |
7745
1013c31bfbee
[.po generation] closes #1902315: c i18ncube doesn't consider relation definition description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6750
diff
changeset
|
259 |
if not rdef.description or rdef.description in done: |
1013c31bfbee
[.po generation] closes #1902315: c i18ncube doesn't consider relation definition description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6750
diff
changeset
|
260 |
continue |
1013c31bfbee
[.po generation] closes #1902315: c i18ncube doesn't consider relation definition description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6750
diff
changeset
|
261 |
if (librschema is None or |
1013c31bfbee
[.po generation] closes #1902315: c i18ncube doesn't consider relation definition description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6750
diff
changeset
|
262 |
(rdef.subject, rdef.object) not in librschema.rdefs or |
1013c31bfbee
[.po generation] closes #1902315: c i18ncube doesn't consider relation definition description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6750
diff
changeset
|
263 |
librschema.rdefs[(rdef.subject, rdef.object)].description != rdef.description): |
1013c31bfbee
[.po generation] closes #1902315: c i18ncube doesn't consider relation definition description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6750
diff
changeset
|
264 |
add_msg(w, rdef.description) |
1013c31bfbee
[.po generation] closes #1902315: c i18ncube doesn't consider relation definition description
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6750
diff
changeset
|
265 |
done.add(rdef.description) |
3285
fa3dc35b564f
fix .po generation: ensure we get all msgids when building a cube catalog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3281
diff
changeset
|
266 |
for objid in _iter_vreg_objids(vreg, vregdone): |
1470
fbdf66a08fbb
don't add to cube i18n catalog msg id for components redefined from cw or from a depending cube
sylvain.thenault@logilab.fr
parents:
1451
diff
changeset
|
267 |
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
|
268 |
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
|
269 |
|
3293 | 270 |
|
4722
9c13d5db03d9
pylint suggested refactorings
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
271 |
def _iter_vreg_objids(vreg, done): |
0 | 272 |
for reg, objdict in vreg.items(): |
6443
a5bed0cd3956
[i18n cube] skip bw compat registries boxes and contentnavigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6356
diff
changeset
|
273 |
if reg in ('boxes', 'contentnavigation'): |
a5bed0cd3956
[i18n cube] skip bw compat registries boxes and contentnavigation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6356
diff
changeset
|
274 |
continue |
10663
54b8a1f249fb
[py3k] dict.itervalues → dict.values
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10662
diff
changeset
|
275 |
for objects in objdict.values(): |
0 | 276 |
for obj in objects: |
3677
acdba524bb8f
fix i18ncube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3674
diff
changeset
|
277 |
objid = '%s_%s' % (reg, obj.__regid__) |
0 | 278 |
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
|
279 |
break |
7990
a673d1d9a738
[diet]Â drop pre 3.6 API compatibility (but attempt to keep data cmopatibility). Closes #2017916
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7752
diff
changeset
|
280 |
pdefs = getattr(obj, 'cw_property_defs', {}) |
3677
acdba524bb8f
fix i18ncube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3674
diff
changeset
|
281 |
if pdefs: |
1470
fbdf66a08fbb
don't add to cube i18n catalog msg id for components redefined from cw or from a depending cube
sylvain.thenault@logilab.fr
parents:
1451
diff
changeset
|
282 |
yield objid |
0 | 283 |
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
|
284 |
break |
374
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
285 |
|
1451 | 286 |
|
0 | 287 |
DEFAULT_POT_HEAD = r'''msgid "" |
288 |
msgstr "" |
|
289 |
"Project-Id-Version: cubicweb %s\n" |
|
290 |
"PO-Revision-Date: 2008-03-28 18:14+0100\n" |
|
291 |
"Last-Translator: Logilab Team <contact@logilab.fr>\n" |
|
292 |
"Language-Team: fr <contact@logilab.fr>\n" |
|
293 |
"MIME-Version: 1.0\n" |
|
294 |
"Content-Type: text/plain; charset=UTF-8\n" |
|
295 |
"Content-Transfer-Encoding: 8bit\n" |
|
296 |
"Generated-By: cubicweb-devtools\n" |
|
297 |
"Plural-Forms: nplurals=2; plural=(n > 1);\n" |
|
298 |
||
299 |
''' % cubicwebversion |
|
300 |
||
301 |
||
302 |
class UpdateCubicWebCatalogCommand(Command): |
|
303 |
"""Update i18n catalogs for cubicweb library. |
|
1451 | 304 |
|
0 | 305 |
It will regenerate cubicweb/i18n/xx.po files. You'll have then to edit those |
306 |
files to add translations of newly added messages. |
|
307 |
""" |
|
1898
39b37f90a8a4
[cw-ctl] rename i18n commands (see #342889)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1850
diff
changeset
|
308 |
name = 'i18ncubicweb' |
6356
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
309 |
min_args = max_args = 0 |
0 | 310 |
|
311 |
def run(self, args): |
|
312 |
"""run the command with its specific arguments""" |
|
313 |
import shutil |
|
2446
440cb4ea7e5c
[refactor] #342855: replace uses of (deprecated) mktemp
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2092
diff
changeset
|
314 |
import tempfile |
0 | 315 |
import yams |
316 |
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
|
317 |
from logilab.common.shellutils import globfind, find, rm |
4718
3dc3ad02d091
avoid module import in c-c plugins module, and remind it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4708
diff
changeset
|
318 |
from logilab.common.modutils import get_module_files |
8620
61c4bdd70dd8
[cw-ctl] silence msgcat and msgfmt (closes #2527594)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8544
diff
changeset
|
319 |
from cubicweb.i18n import extract_from_tal, execute2 |
8257
d54fc706d623
[test] create temporary directory with meaningfull prefix
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8247
diff
changeset
|
320 |
tempdir = tempfile.mkdtemp(prefix='cw-') |
6356
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
321 |
cwi18ndir = WebConfiguration.i18n_lib_dir() |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10474
diff
changeset
|
322 |
print('-> extract messages:', end=' ') |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10474
diff
changeset
|
323 |
print('schema', end=' ') |
6356
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
324 |
schemapot = osp.join(tempdir, 'schema.pot') |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
325 |
potfiles = [schemapot] |
0 | 326 |
potfiles.append(schemapot) |
327 |
# explicit close necessary else the file may not be yet flushed when |
|
328 |
# we'll using it below |
|
10614
57dfde80df11
[py3k] file → open
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10601
diff
changeset
|
329 |
schemapotstream = open(schemapot, 'w') |
0 | 330 |
generate_schema_pot(schemapotstream.write, cubedir=None) |
331 |
schemapotstream.close() |
|
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10474
diff
changeset
|
332 |
print('TAL', end=' ') |
6356
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
333 |
tali18nfile = osp.join(tempdir, 'tali18n.py') |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
334 |
extract_from_tal(find(osp.join(BASEDIR, 'web'), ('.py', '.pt')), |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
335 |
tali18nfile) |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10474
diff
changeset
|
336 |
print('-> generate .pot files.') |
6356
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
337 |
pyfiles = get_module_files(BASEDIR) |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
338 |
pyfiles += globfind(osp.join(BASEDIR, 'misc', 'migration'), '*.py') |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
339 |
schemafiles = globfind(osp.join(BASEDIR, 'schemas'), '*.py') |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
340 |
jsfiles = globfind(osp.join(BASEDIR, 'web'), 'cub*.js') |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
341 |
for id, files, lang in [('pycubicweb', pyfiles, None), |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
342 |
('schemadescr', schemafiles, None), |
0 | 343 |
('yams', get_module_files(yams.__path__[0]), None), |
344 |
('tal', [tali18nfile], None), |
|
6356
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
345 |
('js', jsfiles, 'java'), |
0 | 346 |
]: |
8620
61c4bdd70dd8
[cw-ctl] silence msgcat and msgfmt (closes #2527594)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8544
diff
changeset
|
347 |
potfile = osp.join(tempdir, '%s.pot' % id) |
61c4bdd70dd8
[cw-ctl] silence msgcat and msgfmt (closes #2527594)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8544
diff
changeset
|
348 |
cmd = ['xgettext', '--no-location', '--omit-header', '-k_'] |
0 | 349 |
if lang is not None: |
8620
61c4bdd70dd8
[cw-ctl] silence msgcat and msgfmt (closes #2527594)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8544
diff
changeset
|
350 |
cmd.extend(['-L', lang]) |
61c4bdd70dd8
[cw-ctl] silence msgcat and msgfmt (closes #2527594)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8544
diff
changeset
|
351 |
cmd.extend(['-o', potfile]) |
61c4bdd70dd8
[cw-ctl] silence msgcat and msgfmt (closes #2527594)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8544
diff
changeset
|
352 |
cmd.extend(files) |
61c4bdd70dd8
[cw-ctl] silence msgcat and msgfmt (closes #2527594)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8544
diff
changeset
|
353 |
execute2(cmd) |
6356
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
354 |
if osp.exists(potfile): |
1502 | 355 |
potfiles.append(potfile) |
356 |
else: |
|
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10474
diff
changeset
|
357 |
print('-> WARNING: %s file was not generated' % potfile) |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10474
diff
changeset
|
358 |
print('-> merging %i .pot files' % len(potfiles)) |
6356
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
359 |
cubicwebpot = osp.join(tempdir, 'cubicweb.pot') |
8620
61c4bdd70dd8
[cw-ctl] silence msgcat and msgfmt (closes #2527594)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8544
diff
changeset
|
360 |
cmd = ['msgcat', '-o', cubicwebpot] + potfiles |
61c4bdd70dd8
[cw-ctl] silence msgcat and msgfmt (closes #2527594)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8544
diff
changeset
|
361 |
execute2(cmd) |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10474
diff
changeset
|
362 |
print('-> merging main pot file with existing translations.') |
6356
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
363 |
chdir(cwi18ndir) |
0 | 364 |
toedit = [] |
6749
48f468f33704
[config, i18n] Create default translation mechanism for all supported languages.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
6356
diff
changeset
|
365 |
for lang in CubicWebNoAppConfiguration.cw_languages(): |
0 | 366 |
target = '%s.po' % lang |
8620
61c4bdd70dd8
[cw-ctl] silence msgcat and msgfmt (closes #2527594)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8544
diff
changeset
|
367 |
cmd = ['msgmerge', '-N', '--sort-output', '-o', |
61c4bdd70dd8
[cw-ctl] silence msgcat and msgfmt (closes #2527594)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8544
diff
changeset
|
368 |
target+'new', target, cubicwebpot] |
61c4bdd70dd8
[cw-ctl] silence msgcat and msgfmt (closes #2527594)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8544
diff
changeset
|
369 |
execute2(cmd) |
0 | 370 |
ensure_fs_mode(target) |
371 |
shutil.move('%snew' % target, target) |
|
6356
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
372 |
toedit.append(osp.abspath(target)) |
0 | 373 |
# cleanup |
60
dc90556488d8
oops, bad changeset review, revert debug changes
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
58
diff
changeset
|
374 |
rm(tempdir) |
0 | 375 |
# instructions pour la suite |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10474
diff
changeset
|
376 |
print('-> regenerated CubicWeb\'s .po catalogs.') |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10474
diff
changeset
|
377 |
print('\nYou can now edit the following files:') |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10474
diff
changeset
|
378 |
print('* ' + '\n* '.join(toedit)) |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10474
diff
changeset
|
379 |
print('when you are done, run "cubicweb-ctl i18ncube yourcube".') |
0 | 380 |
|
381 |
||
6444
cc091175d3da
[c-c i18ncube] proper command class name
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6443
diff
changeset
|
382 |
class UpdateCubeCatalogCommand(Command): |
0 | 383 |
"""Update i18n catalogs for cubes. If no cube is specified, update |
384 |
catalogs of all registered cubes. |
|
385 |
""" |
|
1898
39b37f90a8a4
[cw-ctl] rename i18n commands (see #342889)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1850
diff
changeset
|
386 |
name = 'i18ncube' |
0 | 387 |
arguments = '[<cube>...]' |
1451 | 388 |
|
0 | 389 |
def run(self, args): |
390 |
"""run the command with its specific arguments""" |
|
391 |
if args: |
|
4479
f25e61a93c42
replace DevCubeConfiguration/DevDepsConfiguration by a single DevConfiguration, fixing recently introduced by w/ i18ncube command on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
392 |
cubes = [DevConfiguration.cube_dir(cube) for cube in args] |
0 | 393 |
else: |
4479
f25e61a93c42
replace DevCubeConfiguration/DevDepsConfiguration by a single DevConfiguration, fixing recently introduced by w/ i18ncube command on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
394 |
cubes = [DevConfiguration.cube_dir(cube) |
f25e61a93c42
replace DevCubeConfiguration/DevDepsConfiguration by a single DevConfiguration, fixing recently introduced by w/ i18ncube command on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
395 |
for cube in DevConfiguration.available_cubes()] |
6356
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
396 |
cubes = [cubepath for cubepath in cubes |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
397 |
if osp.exists(osp.join(cubepath, 'i18n'))] |
8247
65b0d2587fb5
[cubicweb-ctl] i18ncube return 2 (failed command) on failure (closes #2192336)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7990
diff
changeset
|
398 |
if not update_cubes_catalogs(cubes): |
65b0d2587fb5
[cubicweb-ctl] i18ncube return 2 (failed command) on failure (closes #2192336)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7990
diff
changeset
|
399 |
raise ExecutionError("update cubes i18n catalog failed") |
0 | 400 |
|
1770
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
401 |
|
0 | 402 |
def update_cubes_catalogs(cubes): |
8620
61c4bdd70dd8
[cw-ctl] silence msgcat and msgfmt (closes #2527594)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8544
diff
changeset
|
403 |
from subprocess import CalledProcessError |
1770
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
404 |
for cubedir in cubes: |
6356
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
405 |
if not osp.isdir(cubedir): |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10474
diff
changeset
|
406 |
print('-> ignoring %s that is not a directory.' % cubedir) |
1770
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
407 |
continue |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
408 |
try: |
5537
2889091bd1bf
[i18ncube] do not crash if cube has nothing to translate
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5534
diff
changeset
|
409 |
toedit = update_cube_catalogs(cubedir) |
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8666
diff
changeset
|
410 |
except CalledProcessError as exc: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10474
diff
changeset
|
411 |
print('\n*** error while updating catalogs for cube', cubedir) |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10474
diff
changeset
|
412 |
print('cmd:\n%s' % exc.cmd) |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10474
diff
changeset
|
413 |
print('stdout:\n%s\nstderr:\n%s' % exc.data) |
1770
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
414 |
except Exception: |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
415 |
import traceback |
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
416 |
traceback.print_exc() |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10474
diff
changeset
|
417 |
print('*** error while updating catalogs for cube', cubedir) |
8247
65b0d2587fb5
[cubicweb-ctl] i18ncube return 2 (failed command) on failure (closes #2192336)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7990
diff
changeset
|
418 |
return False |
2527
e60db6312aa0
per cube message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2458
diff
changeset
|
419 |
else: |
e60db6312aa0
per cube message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2458
diff
changeset
|
420 |
# instructions pour la suite |
5537
2889091bd1bf
[i18ncube] do not crash if cube has nothing to translate
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5534
diff
changeset
|
421 |
if toedit: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10474
diff
changeset
|
422 |
print('-> regenerated .po catalogs for cube %s.' % cubedir) |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10474
diff
changeset
|
423 |
print('\nYou can now edit the following files:') |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10474
diff
changeset
|
424 |
print('* ' + '\n* '.join(toedit)) |
5537
2889091bd1bf
[i18ncube] do not crash if cube has nothing to translate
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5534
diff
changeset
|
425 |
print ('When you are done, run "cubicweb-ctl i18ninstance ' |
2889091bd1bf
[i18ncube] do not crash if cube has nothing to translate
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5534
diff
changeset
|
426 |
'<yourinstance>" to see changes in your instances.') |
8247
65b0d2587fb5
[cubicweb-ctl] i18ncube return 2 (failed command) on failure (closes #2192336)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
7990
diff
changeset
|
427 |
return True |
1770
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
428 |
|
11726
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
429 |
|
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
430 |
class I18nCubeMessageExtractor(object): |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
431 |
"""This class encapsulates all the xgettext extraction logic |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
432 |
|
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
433 |
``generate_pot_file`` is the main entry point called by the ``i18ncube`` |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
434 |
command. A cube might decide to customize extractors to ignore a given |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
435 |
directory or to extract messages from a new file type (e.g. .jinja2 files) |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
436 |
|
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
437 |
For each file type, the class must define two methods: |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
438 |
|
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
439 |
- ``collect_{filetype}()`` that must return the list of files |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
440 |
xgettext should inspect, |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
441 |
|
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
442 |
- ``extract_{filetype}(files)`` that calls xgettext and returns the |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
443 |
path to the generated ``pot`` file |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
444 |
""" |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
445 |
blacklist = STD_BLACKLIST |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
446 |
formats = ['tal', 'js', 'py'] |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
447 |
|
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
448 |
def __init__(self, workdir, cubedir): |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
449 |
self.workdir = workdir |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
450 |
self.cubedir = cubedir |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
451 |
|
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
452 |
def generate_pot_file(self): |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
453 |
"""main entry point: return the generated ``cube.pot`` file |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
454 |
|
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
455 |
This function first generates all the pot files (schema, tal, |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
456 |
py, js) and then merges them in a single ``cube.pot`` that will |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
457 |
be used to eventually update the ``i18n/*.po`` files. |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
458 |
""" |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
459 |
potfiles = self.generate_pot_files() |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
460 |
potfile = osp.join(self.workdir, 'cube.pot') |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
461 |
print('-> merging %i .pot files' % len(potfiles)) |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
462 |
cmd = ['msgcat', '-o', potfile] |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
463 |
cmd.extend(potfiles) |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
464 |
execute2(cmd) |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
465 |
return potfile if osp.exists(potfile) else None |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
466 |
|
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
467 |
def find(self, exts, blacklist=None): |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
468 |
"""collect files with extensions ``exts`` in the cube directory |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
469 |
""" |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
470 |
if blacklist is None: |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
471 |
blacklist = self.blacklist |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
472 |
return find(self.cubedir, exts, blacklist=blacklist) |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
473 |
|
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
474 |
def generate_pot_files(self): |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
475 |
"""generate and return the list of all ``pot`` files for the cube |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
476 |
|
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
477 |
- static-messages.pot, |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
478 |
- schema.pot, |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
479 |
- one ``pot`` file for each inspected format (.py, .js, etc.) |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
480 |
""" |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
481 |
print('-> extracting messages:', end=' ') |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
482 |
potfiles = [] |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
483 |
# static messages |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
484 |
if osp.exists(osp.join('i18n', 'entities.pot')): |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
485 |
warn('entities.pot is deprecated, rename file ' |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
486 |
'to static-messages.pot (%s)' |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
487 |
% osp.join('i18n', 'entities.pot'), DeprecationWarning) |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
488 |
potfiles.append(osp.join('i18n', 'entities.pot')) |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
489 |
elif osp.exists(osp.join('i18n', 'static-messages.pot')): |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
490 |
potfiles.append(osp.join('i18n', 'static-messages.pot')) |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
491 |
# messages from schema |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
492 |
potfiles.append(self.schemapot()) |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
493 |
# messages from sourcecode |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
494 |
for fmt in self.formats: |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
495 |
collector = getattr(self, 'collect_{0}'.format(fmt)) |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
496 |
extractor = getattr(self, 'extract_{0}'.format(fmt)) |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
497 |
files = collector() |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
498 |
if files: |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
499 |
potfile = extractor(files) |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
500 |
if potfile: |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
501 |
potfiles.append(potfile) |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
502 |
return potfiles |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
503 |
|
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
504 |
def schemapot(self): |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
505 |
"""generate the ``schema.pot`` file""" |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
506 |
schemapot = osp.join(self.workdir, 'schema.pot') |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
507 |
print('schema', end=' ') |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
508 |
# explicit close necessary else the file may not be yet flushed when |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
509 |
# we'll using it below |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
510 |
schemapotstream = open(schemapot, 'w') |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
511 |
generate_schema_pot(schemapotstream.write, self.cubedir) |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
512 |
schemapotstream.close() |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
513 |
return schemapot |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
514 |
|
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
515 |
def _xgettext(self, files, output, k='_', extraopts=''): |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
516 |
"""shortcut to execute the xgettext command and return output file |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
517 |
""" |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
518 |
tmppotfile = osp.join(self.workdir, output) |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
519 |
cmd = ['xgettext', '--no-location', '--omit-header', '-k' + k, |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
520 |
'-o', tmppotfile] + extraopts.split() + files |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
521 |
execute2(cmd) |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
522 |
if osp.exists(tmppotfile): |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
523 |
return tmppotfile |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
524 |
|
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
525 |
def collect_tal(self): |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
526 |
print('TAL', end=' ') |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
527 |
return self.find(('.py', '.pt')) |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
528 |
|
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
529 |
def extract_tal(self, files): |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
530 |
tali18nfile = osp.join(self.workdir, 'tali18n.py') |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
531 |
extract_from_tal(files, tali18nfile) |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
532 |
return self._xgettext(files, output='tal.pot') |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
533 |
|
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
534 |
def collect_js(self): |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
535 |
print('Javascript') |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
536 |
return [jsfile for jsfile in self.find('.js') |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
537 |
if osp.basename(jsfile).startswith('cub')] |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
538 |
|
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
539 |
def extract_js(self, files): |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
540 |
return self._xgettext(files, output='js.pot', |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
541 |
extraopts='-L java --from-code=utf-8') |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
542 |
|
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
543 |
def collect_py(self): |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
544 |
print('-> creating cube-specific catalog') |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
545 |
return self.find('.py') |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
546 |
|
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
547 |
def extract_py(self, files): |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
548 |
return self._xgettext(files, output='py.pot') |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
549 |
|
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
550 |
|
1770
8bd788149f85
refactor and don't crash on error while generating a cube's catalogs
sylvain.thenault@logilab.fr
parents:
1769
diff
changeset
|
551 |
def update_cube_catalogs(cubedir): |
11726
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
552 |
cubedir = osp.abspath(osp.normpath(cubedir)) |
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
553 |
workdir = tempfile.mkdtemp() |
11728
b96bed36765d
[devctl] make sure i18ncube always delete its tempdir
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11727
diff
changeset
|
554 |
try: |
11822
adf0212d1dcc
[devctl] make i18n custom message extractors work with legacy layouts
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11818
diff
changeset
|
555 |
cubename = osp.basename(cubedir) |
adf0212d1dcc
[devctl] make i18n custom message extractors work with legacy layouts
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11818
diff
changeset
|
556 |
if cubename.startswith('cubicweb_'): # new layout |
adf0212d1dcc
[devctl] make i18n custom message extractors work with legacy layouts
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11818
diff
changeset
|
557 |
distname = cubename |
adf0212d1dcc
[devctl] make i18n custom message extractors work with legacy layouts
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11818
diff
changeset
|
558 |
cubename = cubename[len('cubicweb_'):] |
adf0212d1dcc
[devctl] make i18n custom message extractors work with legacy layouts
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11818
diff
changeset
|
559 |
else: |
adf0212d1dcc
[devctl] make i18n custom message extractors work with legacy layouts
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11818
diff
changeset
|
560 |
distname = 'cubicweb_' + cubename |
11728
b96bed36765d
[devctl] make sure i18ncube always delete its tempdir
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11727
diff
changeset
|
561 |
print('cubedir', cubedir) |
11735
7a170207acbf
[devtools] make i18ncube customizable in a cube
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11728
diff
changeset
|
562 |
extract_cls = I18nCubeMessageExtractor |
7a170207acbf
[devtools] make i18ncube customizable in a cube
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11728
diff
changeset
|
563 |
try: |
7a170207acbf
[devtools] make i18ncube customizable in a cube
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11728
diff
changeset
|
564 |
extract_cls = pkg_resources.load_entry_point( |
7a170207acbf
[devtools] make i18ncube customizable in a cube
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11728
diff
changeset
|
565 |
distname, 'cubicweb.i18ncube', cubename) |
7a170207acbf
[devtools] make i18ncube customizable in a cube
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11728
diff
changeset
|
566 |
except (pkg_resources.DistributionNotFound, ImportError): |
7a170207acbf
[devtools] make i18ncube customizable in a cube
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11728
diff
changeset
|
567 |
pass # no customization found |
7a170207acbf
[devtools] make i18ncube customizable in a cube
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11728
diff
changeset
|
568 |
print(underline_title('Updating i18n catalogs for cube %s' % cubename)) |
11728
b96bed36765d
[devctl] make sure i18ncube always delete its tempdir
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11727
diff
changeset
|
569 |
chdir(cubedir) |
11735
7a170207acbf
[devtools] make i18ncube customizable in a cube
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11728
diff
changeset
|
570 |
extractor = extract_cls(workdir, cubedir) |
11728
b96bed36765d
[devctl] make sure i18ncube always delete its tempdir
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11727
diff
changeset
|
571 |
potfile = extractor.generate_pot_file() |
b96bed36765d
[devctl] make sure i18ncube always delete its tempdir
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11727
diff
changeset
|
572 |
if potfile is None: |
11735
7a170207acbf
[devtools] make i18ncube customizable in a cube
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11728
diff
changeset
|
573 |
print('no message catalog for cube', cubename, 'nothing to translate') |
11728
b96bed36765d
[devctl] make sure i18ncube always delete its tempdir
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11727
diff
changeset
|
574 |
return () |
b96bed36765d
[devctl] make sure i18ncube always delete its tempdir
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11727
diff
changeset
|
575 |
print('-> merging main pot file with existing translations:', end=' ') |
b96bed36765d
[devctl] make sure i18ncube always delete its tempdir
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11727
diff
changeset
|
576 |
chdir('i18n') |
b96bed36765d
[devctl] make sure i18ncube always delete its tempdir
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11727
diff
changeset
|
577 |
toedit = [] |
b96bed36765d
[devctl] make sure i18ncube always delete its tempdir
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11727
diff
changeset
|
578 |
for lang in CubicWebNoAppConfiguration.cw_languages(): |
b96bed36765d
[devctl] make sure i18ncube always delete its tempdir
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11727
diff
changeset
|
579 |
print(lang, end=' ') |
b96bed36765d
[devctl] make sure i18ncube always delete its tempdir
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11727
diff
changeset
|
580 |
cubepo = '%s.po' % lang |
b96bed36765d
[devctl] make sure i18ncube always delete its tempdir
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11727
diff
changeset
|
581 |
if not osp.exists(cubepo): |
b96bed36765d
[devctl] make sure i18ncube always delete its tempdir
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11727
diff
changeset
|
582 |
shutil.copy(potfile, cubepo) |
b96bed36765d
[devctl] make sure i18ncube always delete its tempdir
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11727
diff
changeset
|
583 |
else: |
b96bed36765d
[devctl] make sure i18ncube always delete its tempdir
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11727
diff
changeset
|
584 |
cmd = ['msgmerge', '-N', '-s', '-o', cubepo + 'new', |
b96bed36765d
[devctl] make sure i18ncube always delete its tempdir
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11727
diff
changeset
|
585 |
cubepo, potfile] |
b96bed36765d
[devctl] make sure i18ncube always delete its tempdir
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11727
diff
changeset
|
586 |
execute2(cmd) |
b96bed36765d
[devctl] make sure i18ncube always delete its tempdir
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11727
diff
changeset
|
587 |
ensure_fs_mode(cubepo) |
b96bed36765d
[devctl] make sure i18ncube always delete its tempdir
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11727
diff
changeset
|
588 |
shutil.move('%snew' % cubepo, cubepo) |
b96bed36765d
[devctl] make sure i18ncube always delete its tempdir
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11727
diff
changeset
|
589 |
toedit.append(osp.abspath(cubepo)) |
b96bed36765d
[devctl] make sure i18ncube always delete its tempdir
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11727
diff
changeset
|
590 |
print() |
b96bed36765d
[devctl] make sure i18ncube always delete its tempdir
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11727
diff
changeset
|
591 |
return toedit |
b96bed36765d
[devctl] make sure i18ncube always delete its tempdir
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11727
diff
changeset
|
592 |
finally: |
b96bed36765d
[devctl] make sure i18ncube always delete its tempdir
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11727
diff
changeset
|
593 |
# cleanup |
11726
a599e23c5712
refactor i18n messages extraction
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
11716
diff
changeset
|
594 |
shutil.rmtree(workdir) |
0 | 595 |
|
596 |
||
132
561671b87c22
rename NewTemplateCommand class into NewCubeCommand
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
61
diff
changeset
|
597 |
class NewCubeCommand(Command): |
0 | 598 |
"""Create a new cube. |
599 |
||
600 |
<cubename> |
|
5184
955ee1b24756
[c-c newcube] #1192: simpler cubicweb-ctl newcube, and more
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4722
diff
changeset
|
601 |
the name of the new cube. It should be a valid python module name. |
0 | 602 |
""" |
603 |
name = 'newcube' |
|
604 |
arguments = '<cubename>' |
|
6356
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
605 |
min_args = max_args = 1 |
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
|
606 |
options = ( |
5184
955ee1b24756
[c-c newcube] #1192: simpler cubicweb-ctl newcube, and more
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4722
diff
changeset
|
607 |
("layout", |
955ee1b24756
[c-c newcube] #1192: simpler cubicweb-ctl newcube, and more
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4722
diff
changeset
|
608 |
{'short': 'L', 'type' : 'choice', 'metavar': '<cube layout>', |
955ee1b24756
[c-c newcube] #1192: simpler cubicweb-ctl newcube, and more
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4722
diff
changeset
|
609 |
'default': 'simple', 'choices': ('simple', 'full'), |
955ee1b24756
[c-c newcube] #1192: simpler cubicweb-ctl newcube, and more
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4722
diff
changeset
|
610 |
'help': 'cube layout. You\'ll get a minimal cube with the "simple" \ |
955ee1b24756
[c-c newcube] #1192: simpler cubicweb-ctl newcube, and more
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4722
diff
changeset
|
611 |
layout, and a full featured cube with "full" layout.', |
955ee1b24756
[c-c newcube] #1192: simpler cubicweb-ctl newcube, and more
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4722
diff
changeset
|
612 |
} |
955ee1b24756
[c-c newcube] #1192: simpler cubicweb-ctl newcube, and more
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4722
diff
changeset
|
613 |
), |
1106
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
614 |
("directory", |
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
615 |
{'short': 'd', 'type' : 'string', 'metavar': '<cubes directory>', |
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
616 |
'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
|
617 |
} |
de873146183a
fix newcube command to deal with cubes path
sylvain.thenault@logilab.fr
parents:
1105
diff
changeset
|
618 |
), |
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
|
619 |
("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
|
620 |
{'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
|
621 |
'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
|
622 |
'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
|
623 |
} |
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
|
624 |
), |
365
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
625 |
("author", |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
626 |
{'short': 'a', 'type' : 'string', 'metavar': '<author>', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
627 |
'default': 'LOGILAB S.A. (Paris, FRANCE)', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
628 |
'help': 'cube author', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
629 |
} |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
630 |
), |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
631 |
("author-email", |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
632 |
{'short': 'e', 'type' : 'string', 'metavar': '<email>', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
633 |
'default': 'contact@logilab.fr', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
634 |
'help': 'cube author\'s email', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
635 |
} |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
636 |
), |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
637 |
("author-web-site", |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
638 |
{'short': 'w', 'type' : 'string', 'metavar': '<web site>', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
639 |
'default': 'http://www.logilab.fr', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
640 |
'help': 'cube author\'s web site', |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
641 |
} |
5d8336b70aa7
make author information configurable
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
264
diff
changeset
|
642 |
), |
5184
955ee1b24756
[c-c newcube] #1192: simpler cubicweb-ctl newcube, and more
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4722
diff
changeset
|
643 |
("license", |
955ee1b24756
[c-c newcube] #1192: simpler cubicweb-ctl newcube, and more
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4722
diff
changeset
|
644 |
{'short': 'l', 'type' : 'choice', 'metavar': '<license>', |
955ee1b24756
[c-c newcube] #1192: simpler cubicweb-ctl newcube, and more
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4722
diff
changeset
|
645 |
'default': 'LGPL', 'choices': ('GPL', 'LGPL', ''), |
955ee1b24756
[c-c newcube] #1192: simpler cubicweb-ctl newcube, and more
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4722
diff
changeset
|
646 |
'help': 'cube license', |
955ee1b24756
[c-c newcube] #1192: simpler cubicweb-ctl newcube, and more
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4722
diff
changeset
|
647 |
} |
955ee1b24756
[c-c newcube] #1192: simpler cubicweb-ctl newcube, and more
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4722
diff
changeset
|
648 |
), |
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
|
649 |
) |
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
|
650 |
|
5184
955ee1b24756
[c-c newcube] #1192: simpler cubicweb-ctl newcube, and more
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4722
diff
changeset
|
651 |
LICENSES = { |
5423
e15abfdcce38
backport default into stable: stable is now cw 3.8
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
652 |
'LGPL': '''\ |
e15abfdcce38
backport default into stable: stable is now cw 3.8
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
653 |
# This program is free software: you can redistribute it and/or modify it under |
e15abfdcce38
backport default into stable: stable is now cw 3.8
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
654 |
# the terms of the GNU Lesser General Public License as published by the Free |
e15abfdcce38
backport default into stable: stable is now cw 3.8
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
655 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
e15abfdcce38
backport default into stable: stable is now cw 3.8
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
656 |
# any later version. |
e15abfdcce38
backport default into stable: stable is now cw 3.8
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
657 |
# |
e15abfdcce38
backport default into stable: stable is now cw 3.8
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
658 |
# This program is distributed in the hope that it will be useful, but WITHOUT |
e15abfdcce38
backport default into stable: stable is now cw 3.8
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
659 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
e15abfdcce38
backport default into stable: stable is now cw 3.8
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
660 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
e15abfdcce38
backport default into stable: stable is now cw 3.8
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
661 |
# details. |
e15abfdcce38
backport default into stable: stable is now cw 3.8
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
662 |
# |
10214
88f60d4b9952
[newcube] Make the generated code PEP-8 compliant
Christophe de Vienne <christophe@unlish.com>
parents:
10174
diff
changeset
|
663 |
# You should have received a copy of the GNU Lesser General Public License |
88f60d4b9952
[newcube] Make the generated code PEP-8 compliant
Christophe de Vienne <christophe@unlish.com>
parents:
10174
diff
changeset
|
664 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
5423
e15abfdcce38
backport default into stable: stable is now cw 3.8
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
665 |
''', |
5537
2889091bd1bf
[i18ncube] do not crash if cube has nothing to translate
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5534
diff
changeset
|
666 |
|
5423
e15abfdcce38
backport default into stable: stable is now cw 3.8
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
667 |
'GPL': '''\ |
e15abfdcce38
backport default into stable: stable is now cw 3.8
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
668 |
# This program is free software: you can redistribute it and/or modify it under |
e15abfdcce38
backport default into stable: stable is now cw 3.8
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
669 |
# the terms of the GNU General Public License as published by the Free Software |
e15abfdcce38
backport default into stable: stable is now cw 3.8
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
670 |
# Foundation, either version 2.1 of the License, or (at your option) any later |
e15abfdcce38
backport default into stable: stable is now cw 3.8
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
671 |
# version. |
e15abfdcce38
backport default into stable: stable is now cw 3.8
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
672 |
# |
e15abfdcce38
backport default into stable: stable is now cw 3.8
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
673 |
# This program is distributed in the hope that it will be useful, but WITHOUT |
e15abfdcce38
backport default into stable: stable is now cw 3.8
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
674 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
10214
88f60d4b9952
[newcube] Make the generated code PEP-8 compliant
Christophe de Vienne <christophe@unlish.com>
parents:
10174
diff
changeset
|
675 |
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
88f60d4b9952
[newcube] Make the generated code PEP-8 compliant
Christophe de Vienne <christophe@unlish.com>
parents:
10174
diff
changeset
|
676 |
# details. |
5423
e15abfdcce38
backport default into stable: stable is now cw 3.8
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
677 |
# |
e15abfdcce38
backport default into stable: stable is now cw 3.8
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
678 |
# You should have received a copy of the GNU General Public License along with |
e15abfdcce38
backport default into stable: stable is now cw 3.8
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
679 |
# this program. If not, see <http://www.gnu.org/licenses/>. |
e15abfdcce38
backport default into stable: stable is now cw 3.8
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
680 |
''', |
e15abfdcce38
backport default into stable: stable is now cw 3.8
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
681 |
'': '# INSERT LICENSE HERE' |
5184
955ee1b24756
[c-c newcube] #1192: simpler cubicweb-ctl newcube, and more
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4722
diff
changeset
|
682 |
} |
1451 | 683 |
|
0 | 684 |
def run(self, args): |
5184
955ee1b24756
[c-c newcube] #1192: simpler cubicweb-ctl newcube, and more
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4722
diff
changeset
|
685 |
import re |
4718
3dc3ad02d091
avoid module import in c-c plugins module, and remind it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4708
diff
changeset
|
686 |
from logilab.common.shellutils import ASK |
5184
955ee1b24756
[c-c newcube] #1192: simpler cubicweb-ctl newcube, and more
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4722
diff
changeset
|
687 |
cubename = args[0] |
955ee1b24756
[c-c newcube] #1192: simpler cubicweb-ctl newcube, and more
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4722
diff
changeset
|
688 |
if not re.match('[_A-Za-z][_A-Za-z0-9]*$', cubename): |
6356
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
689 |
raise BadCommandUsage( |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
690 |
'cube name must be a valid python module name') |
133
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
691 |
verbose = self.get('verbose') |
11454
7770559e3945
[devtools] Update skeleton and newcube command to cube as package layout
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11129
diff
changeset
|
692 |
destdir = self.get('directory') |
7770559e3945
[devtools] Update skeleton and newcube command to cube as package layout
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11129
diff
changeset
|
693 |
if not destdir: |
12080
b8c4a8bab7b3
[devtools] Create "newcube" in current directory by default
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11900
diff
changeset
|
694 |
destdir = getcwd() |
b8c4a8bab7b3
[devtools] Create "newcube" in current directory by default
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11900
diff
changeset
|
695 |
elif not osp.isdir(destdir): |
11454
7770559e3945
[devtools] Update skeleton and newcube command to cube as package layout
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11129
diff
changeset
|
696 |
print("-> creating cubes directory", destdir) |
0 | 697 |
try: |
11454
7770559e3945
[devtools] Update skeleton and newcube command to cube as package layout
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11129
diff
changeset
|
698 |
mkdir(destdir) |
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8666
diff
changeset
|
699 |
except OSError as err: |
6356
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
700 |
self.fail("failed to create directory %r\n(%s)" |
11454
7770559e3945
[devtools] Update skeleton and newcube command to cube as package layout
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11129
diff
changeset
|
701 |
% (destdir, err)) |
5297
cc747dcef851
[c-c newcube] finish #676915: cubicweb-ctl newcube must be aware of python modules and debian package convention (python part already implemented)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5184
diff
changeset
|
702 |
default_name = 'cubicweb-%s' % cubename.lower().replace('_', '-') |
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
|
703 |
if verbose: |
10967
3f620fd1ed18
[devtools] Fix 'newcube' on py3k
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10963
diff
changeset
|
704 |
distname = input('Debian name for your cube ? [%s]): ' |
11454
7770559e3945
[devtools] Update skeleton and newcube command to cube as package layout
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11129
diff
changeset
|
705 |
% default_name).strip() |
133
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
706 |
if not distname: |
2615
1ea41b7c0836
F [dialog] offer to create backup. refactor to use l.c.shellutils.ASK
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2551
diff
changeset
|
707 |
distname = default_name |
133
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
708 |
elif not distname.startswith('cubicweb-'): |
2615
1ea41b7c0836
F [dialog] offer to create backup. refactor to use l.c.shellutils.ASK
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2551
diff
changeset
|
709 |
if ASK.confirm('Do you mean cubicweb-%s ?' % distname): |
133
6ad5e7eb06ff
provide a --verbose option to the newcube command and only ask for a short description by default
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
132
diff
changeset
|
710 |
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
|
711 |
else: |
2615
1ea41b7c0836
F [dialog] offer to create backup. refactor to use l.c.shellutils.ASK
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2551
diff
changeset
|
712 |
distname = default_name |
5297
cc747dcef851
[c-c newcube] finish #676915: cubicweb-ctl newcube must be aware of python modules and debian package convention (python part already implemented)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5184
diff
changeset
|
713 |
if not re.match('[a-z][-a-z0-9]*$', distname): |
6356
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
714 |
raise BadCommandUsage( |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
715 |
'cube distname should be a valid debian package name') |
11454
7770559e3945
[devtools] Update skeleton and newcube command to cube as package layout
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11129
diff
changeset
|
716 |
cubedir = osp.join(destdir, distname) |
7770559e3945
[devtools] Update skeleton and newcube command to cube as package layout
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11129
diff
changeset
|
717 |
if osp.exists(cubedir): |
7770559e3945
[devtools] Update skeleton and newcube command to cube as package layout
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11129
diff
changeset
|
718 |
self.fail("%s already exists!" % cubedir) |
7770559e3945
[devtools] Update skeleton and newcube command to cube as package layout
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11129
diff
changeset
|
719 |
skeldir = osp.join(BASEDIR, 'skeleton') |
10967
3f620fd1ed18
[devtools] Fix 'newcube' on py3k
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10963
diff
changeset
|
720 |
longdesc = shortdesc = input( |
6356
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
721 |
'Enter a short description for your cube: ') |
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
|
722 |
if verbose: |
10967
3f620fd1ed18
[devtools] Fix 'newcube' on py3k
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10963
diff
changeset
|
723 |
longdesc = input( |
6356
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
724 |
'Enter a long description (leave empty to reuse the short one): ') |
11454
7770559e3945
[devtools] Update skeleton and newcube command to cube as package layout
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11129
diff
changeset
|
725 |
dependencies = { |
7770559e3945
[devtools] Update skeleton and newcube command to cube as package layout
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11129
diff
changeset
|
726 |
'six': '>= 1.4.0', |
7770559e3945
[devtools] Update skeleton and newcube command to cube as package layout
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11129
diff
changeset
|
727 |
'cubicweb': '>= %s' % cubicwebversion, |
7770559e3945
[devtools] Update skeleton and newcube command to cube as package layout
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11129
diff
changeset
|
728 |
} |
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
|
729 |
if verbose: |
5347
8ebed973819b
merge stable, fixing dependencies generation on c-c newcube on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
730 |
dependencies.update(self._ask_for_dependencies()) |
11716
c7de052ee288
[skeleton] Properly format debian/changelog using current datetime and author information
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11468
diff
changeset
|
731 |
context = { |
c7de052ee288
[skeleton] Properly format debian/changelog using current datetime and author information
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11468
diff
changeset
|
732 |
'cubename': cubename, |
c7de052ee288
[skeleton] Properly format debian/changelog using current datetime and author information
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11468
diff
changeset
|
733 |
'distname': distname, |
c7de052ee288
[skeleton] Properly format debian/changelog using current datetime and author information
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11468
diff
changeset
|
734 |
'shortdesc': shortdesc, |
c7de052ee288
[skeleton] Properly format debian/changelog using current datetime and author information
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11468
diff
changeset
|
735 |
'longdesc': longdesc or shortdesc, |
c7de052ee288
[skeleton] Properly format debian/changelog using current datetime and author information
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11468
diff
changeset
|
736 |
'dependencies': dependencies, |
c7de052ee288
[skeleton] Properly format debian/changelog using current datetime and author information
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11468
diff
changeset
|
737 |
'version': cubicwebversion, |
c7de052ee288
[skeleton] Properly format debian/changelog using current datetime and author information
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11468
diff
changeset
|
738 |
'year': str(date.today().year), |
c7de052ee288
[skeleton] Properly format debian/changelog using current datetime and author information
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11468
diff
changeset
|
739 |
'author': self['author'], |
c7de052ee288
[skeleton] Properly format debian/changelog using current datetime and author information
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11468
diff
changeset
|
740 |
'author-email': self['author-email'], |
c7de052ee288
[skeleton] Properly format debian/changelog using current datetime and author information
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11468
diff
changeset
|
741 |
'rfc2822-date': datetime.now(tz=UTC).strftime('%a, %d %b %Y %T %z'), |
c7de052ee288
[skeleton] Properly format debian/changelog using current datetime and author information
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11468
diff
changeset
|
742 |
'author-web-site': self['author-web-site'], |
c7de052ee288
[skeleton] Properly format debian/changelog using current datetime and author information
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11468
diff
changeset
|
743 |
'license': self['license'], |
c7de052ee288
[skeleton] Properly format debian/changelog using current datetime and author information
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11468
diff
changeset
|
744 |
'long-license': self.LICENSES[self['license']], |
c7de052ee288
[skeleton] Properly format debian/changelog using current datetime and author information
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
11468
diff
changeset
|
745 |
} |
5184
955ee1b24756
[c-c newcube] #1192: simpler cubicweb-ctl newcube, and more
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4722
diff
changeset
|
746 |
exclude = SKEL_EXCLUDE |
955ee1b24756
[c-c newcube] #1192: simpler cubicweb-ctl newcube, and more
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4722
diff
changeset
|
747 |
if self['layout'] == 'simple': |
955ee1b24756
[c-c newcube] #1192: simpler cubicweb-ctl newcube, and more
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4722
diff
changeset
|
748 |
exclude += ('sobjects.py*', 'precreate.py*', 'realdb_test*', |
5466
b5af2ac0c43c
[uiprops] test and fix reloading of modified css files; update c-c newcube; deprecates config.has_resource.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5442
diff
changeset
|
749 |
'cubes.*', 'uiprops.py*') |
5184
955ee1b24756
[c-c newcube] #1192: simpler cubicweb-ctl newcube, and more
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4722
diff
changeset
|
750 |
copy_skeleton(skeldir, cubedir, context, exclude=exclude) |
0 | 751 |
|
5344
ed4cd1ca96d6
[skeleton/dependencies] fix typo & new cube generation from template
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4722
diff
changeset
|
752 |
def _ask_for_dependencies(self): |
4718
3dc3ad02d091
avoid module import in c-c plugins module, and remind it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4708
diff
changeset
|
753 |
from logilab.common.shellutils import ASK |
3dc3ad02d091
avoid module import in c-c plugins module, and remind it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4708
diff
changeset
|
754 |
from logilab.common.textutils import splitstrip |
5347
8ebed973819b
merge stable, fixing dependencies generation on c-c newcube on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
755 |
depcubes = [] |
8ebed973819b
merge stable, fixing dependencies generation on c-c newcube on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
756 |
for cube in ServerConfiguration.available_cubes(): |
8ebed973819b
merge stable, fixing dependencies generation on c-c newcube on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
757 |
answer = ASK.ask("Depends on cube %s? " % cube, |
2615
1ea41b7c0836
F [dialog] offer to create backup. refactor to use l.c.shellutils.ASK
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2551
diff
changeset
|
758 |
('N','y','skip','type'), 'N') |
1ea41b7c0836
F [dialog] offer to create backup. refactor to use l.c.shellutils.ASK
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2551
diff
changeset
|
759 |
if answer == 'y': |
5347
8ebed973819b
merge stable, fixing dependencies generation on c-c newcube on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
760 |
depcubes.append(cube) |
2615
1ea41b7c0836
F [dialog] offer to create backup. refactor to use l.c.shellutils.ASK
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2551
diff
changeset
|
761 |
if answer == 'type': |
10967
3f620fd1ed18
[devtools] Fix 'newcube' on py3k
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10963
diff
changeset
|
762 |
depcubes = splitstrip(input('type dependencies: ')) |
0 | 763 |
break |
2615
1ea41b7c0836
F [dialog] offer to create backup. refactor to use l.c.shellutils.ASK
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2551
diff
changeset
|
764 |
elif answer == 'skip': |
0 | 765 |
break |
5347
8ebed973819b
merge stable, fixing dependencies generation on c-c newcube on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
766 |
return dict(('cubicweb-' + cube, ServerConfiguration.cube_version(cube)) |
8ebed973819b
merge stable, fixing dependencies generation on c-c newcube on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
diff
changeset
|
767 |
for cube in depcubes) |
1451 | 768 |
|
374
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
769 |
|
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
770 |
class ExamineLogCommand(Command): |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
771 |
"""Examine a rql log file. |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
772 |
|
8857
5d08086c3e6d
[cmd] fix exlog documentation (closes #2715913)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8454
diff
changeset
|
773 |
Will print out the following table |
374
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
774 |
|
8857
5d08086c3e6d
[cmd] fix exlog documentation (closes #2715913)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8454
diff
changeset
|
775 |
Percentage; Cumulative Time (clock); Cumulative Time (CPU); Occurences; Query |
374
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
776 |
|
8857
5d08086c3e6d
[cmd] fix exlog documentation (closes #2715913)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8454
diff
changeset
|
777 |
sorted by descending cumulative time (clock). Time are expressed in seconds. |
374
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
778 |
|
8857
5d08086c3e6d
[cmd] fix exlog documentation (closes #2715913)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8454
diff
changeset
|
779 |
Chances are the lines at the top are the ones that will bring the higher |
4708
2bd3d03721f3
#687194: cubicweb-ctl exlog : fix help message
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4479
diff
changeset
|
780 |
benefit after optimisation. Start there. |
374
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
781 |
""" |
5375
962e13ab0930
[c-c exlog] #687204: cubicweb-ctl exlog: use a proper file and not stdin for input
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5344
diff
changeset
|
782 |
arguments = 'rql.log' |
374
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
783 |
name = 'exlog' |
6356
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
784 |
options = () |
1451 | 785 |
|
374
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
786 |
def run(self, args): |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
787 |
import re |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
788 |
requests = {} |
5375
962e13ab0930
[c-c exlog] #687204: cubicweb-ctl exlog: use a proper file and not stdin for input
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5344
diff
changeset
|
789 |
for filepath in args: |
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
|
790 |
try: |
10614
57dfde80df11
[py3k] file → open
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10601
diff
changeset
|
791 |
stream = open(filepath) |
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8666
diff
changeset
|
792 |
except OSError as ex: |
5375
962e13ab0930
[c-c exlog] #687204: cubicweb-ctl exlog: use a proper file and not stdin for input
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5344
diff
changeset
|
793 |
raise BadCommandUsage("can't open rql log file %s: %s" |
962e13ab0930
[c-c exlog] #687204: cubicweb-ctl exlog: use a proper file and not stdin for input
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5344
diff
changeset
|
794 |
% (filepath, ex)) |
5755
ca9e1c9123d7
[c-c exlog] fix code and documentation
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents:
5608
diff
changeset
|
795 |
for lineno, line in enumerate(stream): |
5375
962e13ab0930
[c-c exlog] #687204: cubicweb-ctl exlog: use a proper file and not stdin for input
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5344
diff
changeset
|
796 |
if not ' WHERE ' in line: |
962e13ab0930
[c-c exlog] #687204: cubicweb-ctl exlog: use a proper file and not stdin for input
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5344
diff
changeset
|
797 |
continue |
962e13ab0930
[c-c exlog] #687204: cubicweb-ctl exlog: use a proper file and not stdin for input
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5344
diff
changeset
|
798 |
try: |
962e13ab0930
[c-c exlog] #687204: cubicweb-ctl exlog: use a proper file and not stdin for input
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5344
diff
changeset
|
799 |
rql, time = line.split('--') |
962e13ab0930
[c-c exlog] #687204: cubicweb-ctl exlog: use a proper file and not stdin for input
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5344
diff
changeset
|
800 |
rql = re.sub("(\'\w+': \d*)", '', rql) |
962e13ab0930
[c-c exlog] #687204: cubicweb-ctl exlog: use a proper file and not stdin for input
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5344
diff
changeset
|
801 |
if '{' in rql: |
962e13ab0930
[c-c exlog] #687204: cubicweb-ctl exlog: use a proper file and not stdin for input
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5344
diff
changeset
|
802 |
rql = rql[:rql.index('{')] |
962e13ab0930
[c-c exlog] #687204: cubicweb-ctl exlog: use a proper file and not stdin for input
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5344
diff
changeset
|
803 |
req = requests.setdefault(rql, []) |
962e13ab0930
[c-c exlog] #687204: cubicweb-ctl exlog: use a proper file and not stdin for input
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5344
diff
changeset
|
804 |
time.strip() |
962e13ab0930
[c-c exlog] #687204: cubicweb-ctl exlog: use a proper file and not stdin for input
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5344
diff
changeset
|
805 |
chunks = time.split() |
962e13ab0930
[c-c exlog] #687204: cubicweb-ctl exlog: use a proper file and not stdin for input
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5344
diff
changeset
|
806 |
clocktime = float(chunks[0][1:]) |
962e13ab0930
[c-c exlog] #687204: cubicweb-ctl exlog: use a proper file and not stdin for input
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5344
diff
changeset
|
807 |
cputime = float(chunks[-3]) |
962e13ab0930
[c-c exlog] #687204: cubicweb-ctl exlog: use a proper file and not stdin for input
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5344
diff
changeset
|
808 |
req.append( (clocktime, cputime) ) |
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8666
diff
changeset
|
809 |
except Exception as exc: |
5375
962e13ab0930
[c-c exlog] #687204: cubicweb-ctl exlog: use a proper file and not stdin for input
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5344
diff
changeset
|
810 |
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
|
811 |
stat = [] |
10662
10942ed172de
[py3k] dict.iteritems → dict.items
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10614
diff
changeset
|
812 |
for rql, times in requests.items(): |
2092
f5102472243d
[exlog] print clocktime in addition to cputime
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
813 |
stat.append( (sum(time[0] for time in times), |
f5102472243d
[exlog] print clocktime in addition to cputime
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
814 |
sum(time[1] for time in times), |
f5102472243d
[exlog] print clocktime in addition to cputime
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
815 |
len(times), rql) ) |
374
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
816 |
stat.sort() |
89225b187eb8
turn exlog into a cw-ctl command
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
373
diff
changeset
|
817 |
stat.reverse() |
5375
962e13ab0930
[c-c exlog] #687204: cubicweb-ctl exlog: use a proper file and not stdin for input
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5344
diff
changeset
|
818 |
total_time = sum(clocktime for clocktime, cputime, occ, rql in stat) * 0.01 |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10474
diff
changeset
|
819 |
print('Percentage;Cumulative Time (clock);Cumulative Time (CPU);Occurences;Query') |
2092
f5102472243d
[exlog] print clocktime in addition to cputime
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
820 |
for clocktime, cputime, occ, rql in stat: |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10474
diff
changeset
|
821 |
print('%.2f;%.2f;%.2f;%s;%s' % (clocktime/total_time, clocktime, |
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10474
diff
changeset
|
822 |
cputime, occ, rql)) |
1451 | 823 |
|
4479
f25e61a93c42
replace DevCubeConfiguration/DevDepsConfiguration by a single DevConfiguration, fixing recently introduced by w/ i18ncube command on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
824 |
|
4428
03614b377ecd
Add a ``schema`` command to cmd ctrl to generate schema image.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4400
diff
changeset
|
825 |
class GenerateSchema(Command): |
03614b377ecd
Add a ``schema`` command to cmd ctrl to generate schema image.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4400
diff
changeset
|
826 |
"""Generate schema image for the given cube""" |
03614b377ecd
Add a ``schema`` command to cmd ctrl to generate schema image.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4400
diff
changeset
|
827 |
name = "schema" |
03614b377ecd
Add a ``schema`` command to cmd ctrl to generate schema image.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4400
diff
changeset
|
828 |
arguments = '<cube>' |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5775
diff
changeset
|
829 |
min_args = max_args = 1 |
6356
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
830 |
options = [ |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
831 |
('output-file', |
8451
49e965bba1ec
[c-c schema] devtools: the output file for cw-ctl schema is not supposed to exist
Julien Cristau <julien.cristau@logilab.fr>
parents:
8257
diff
changeset
|
832 |
{'type':'string', 'default': None, |
6356
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
833 |
'metavar': '<file>', 'short':'o', 'help':'output image file', |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
834 |
'input':False, |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
835 |
}), |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
836 |
('viewer', |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
837 |
{'type': 'string', 'default':None, |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
838 |
'short': "d", 'metavar':'<cmd>', |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
839 |
'help':'command use to view the generated file (empty for none)', |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
840 |
}), |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
841 |
('show-meta', |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
842 |
{'action': 'store_true', 'default':False, |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
843 |
'short': "m", 'metavar': "<yN>", |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
844 |
'help':'include meta and internal entities in schema', |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
845 |
}), |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
846 |
('show-workflow', |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
847 |
{'action': 'store_true', 'default':False, |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
848 |
'short': "w", 'metavar': "<yN>", |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
849 |
'help':'include workflow entities in schema', |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
850 |
}), |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
851 |
('show-cw-user', |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
852 |
{'action': 'store_true', 'default':False, |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
853 |
'metavar': "<yN>", |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
854 |
'help':'include cubicweb user entities in schema', |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
855 |
}), |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
856 |
('exclude-type', |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
857 |
{'type':'string', 'default':'', |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
858 |
'short': "x", 'metavar': "<types>", |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
859 |
'help':'coma separated list of entity types to remove from view', |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
860 |
}), |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
861 |
('include-type', |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
862 |
{'type':'string', 'default':'', |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
863 |
'short': "i", 'metavar': "<types>", |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
864 |
'help':'coma separated list of entity types to include in view', |
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
865 |
}), |
9470
b1ff6525ece3
[c-c schema] option to show single etype (closes #3404831)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9258
diff
changeset
|
866 |
('show-etype', |
b1ff6525ece3
[c-c schema] option to show single etype (closes #3404831)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9258
diff
changeset
|
867 |
{'type':'string', 'default':'', |
b1ff6525ece3
[c-c schema] option to show single etype (closes #3404831)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9258
diff
changeset
|
868 |
'metavar': '<etype>', |
b1ff6525ece3
[c-c schema] option to show single etype (closes #3404831)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9258
diff
changeset
|
869 |
'help':'show graph of this etype and its neighbours' |
b1ff6525ece3
[c-c schema] option to show single etype (closes #3404831)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9258
diff
changeset
|
870 |
}), |
6356
e89f71a41e20
[c-c i18n] namespace/line wrap cleanup + dynamically compute available language + make it works in installed mode
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6138
diff
changeset
|
871 |
] |
4428
03614b377ecd
Add a ``schema`` command to cmd ctrl to generate schema image.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4400
diff
changeset
|
872 |
|
03614b377ecd
Add a ``schema`` command to cmd ctrl to generate schema image.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4400
diff
changeset
|
873 |
def run(self, args): |
4718
3dc3ad02d091
avoid module import in c-c plugins module, and remind it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4708
diff
changeset
|
874 |
from subprocess import Popen |
3dc3ad02d091
avoid module import in c-c plugins module, and remind it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4708
diff
changeset
|
875 |
from tempfile import NamedTemporaryFile |
4428
03614b377ecd
Add a ``schema`` command to cmd ctrl to generate schema image.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4400
diff
changeset
|
876 |
from logilab.common.textutils import splitstrip |
9470
b1ff6525ece3
[c-c schema] option to show single etype (closes #3404831)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9258
diff
changeset
|
877 |
from logilab.common.graph import GraphGenerator, DotBackend |
b1ff6525ece3
[c-c schema] option to show single etype (closes #3404831)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9258
diff
changeset
|
878 |
from yams import schema2dot as s2d, BASE_TYPES |
4718
3dc3ad02d091
avoid module import in c-c plugins module, and remind it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4708
diff
changeset
|
879 |
from cubicweb.schema import (META_RTYPES, SCHEMA_TYPES, SYSTEM_RTYPES, |
3dc3ad02d091
avoid module import in c-c plugins module, and remind it
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4708
diff
changeset
|
880 |
WORKFLOW_TYPES, INTERNAL_TYPES) |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5775
diff
changeset
|
881 |
cubes = splitstrip(args[0]) |
4479
f25e61a93c42
replace DevCubeConfiguration/DevDepsConfiguration by a single DevConfiguration, fixing recently introduced by w/ i18ncube command on the way
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4467
diff
changeset
|
882 |
dev_conf = DevConfiguration(*cubes) |
4428
03614b377ecd
Add a ``schema`` command to cmd ctrl to generate schema image.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4400
diff
changeset
|
883 |
schema = dev_conf.load_schema() |
03614b377ecd
Add a ``schema`` command to cmd ctrl to generate schema image.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4400
diff
changeset
|
884 |
out, viewer = self['output-file'], self['viewer'] |
03614b377ecd
Add a ``schema`` command to cmd ctrl to generate schema image.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4400
diff
changeset
|
885 |
if out is None: |
03614b377ecd
Add a ``schema`` command to cmd ctrl to generate schema image.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4400
diff
changeset
|
886 |
tmp_file = NamedTemporaryFile(suffix=".svg") |
03614b377ecd
Add a ``schema`` command to cmd ctrl to generate schema image.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4400
diff
changeset
|
887 |
out = tmp_file.name |
4434
101344a6ff9b
Improve the schema command with filtering option.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4428
diff
changeset
|
888 |
skiptypes = BASE_TYPES | SCHEMA_TYPES |
101344a6ff9b
Improve the schema command with filtering option.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4428
diff
changeset
|
889 |
if not self['show-meta']: |
101344a6ff9b
Improve the schema command with filtering option.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4428
diff
changeset
|
890 |
skiptypes |= META_RTYPES | SYSTEM_RTYPES | INTERNAL_TYPES |
101344a6ff9b
Improve the schema command with filtering option.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4428
diff
changeset
|
891 |
if not self['show-workflow']: |
101344a6ff9b
Improve the schema command with filtering option.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4428
diff
changeset
|
892 |
skiptypes |= WORKFLOW_TYPES |
101344a6ff9b
Improve the schema command with filtering option.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4428
diff
changeset
|
893 |
if not self['show-cw-user']: |
101344a6ff9b
Improve the schema command with filtering option.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4428
diff
changeset
|
894 |
skiptypes |= set(('CWUser', 'CWGroup', 'EmailAddress')) |
101344a6ff9b
Improve the schema command with filtering option.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4428
diff
changeset
|
895 |
skiptypes |= set(self['exclude-type'].split(',')) |
101344a6ff9b
Improve the schema command with filtering option.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4428
diff
changeset
|
896 |
skiptypes -= set(self['include-type'].split(',')) |
9470
b1ff6525ece3
[c-c schema] option to show single etype (closes #3404831)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9258
diff
changeset
|
897 |
|
b1ff6525ece3
[c-c schema] option to show single etype (closes #3404831)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9258
diff
changeset
|
898 |
if not self['show-etype']: |
b1ff6525ece3
[c-c schema] option to show single etype (closes #3404831)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9258
diff
changeset
|
899 |
s2d.schema2dot(schema, out, skiptypes=skiptypes) |
b1ff6525ece3
[c-c schema] option to show single etype (closes #3404831)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9258
diff
changeset
|
900 |
else: |
b1ff6525ece3
[c-c schema] option to show single etype (closes #3404831)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9258
diff
changeset
|
901 |
etype = self['show-etype'] |
b1ff6525ece3
[c-c schema] option to show single etype (closes #3404831)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9258
diff
changeset
|
902 |
visitor = s2d.OneHopESchemaVisitor(schema[etype], skiptypes=skiptypes) |
b1ff6525ece3
[c-c schema] option to show single etype (closes #3404831)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9258
diff
changeset
|
903 |
propshdlr = s2d.SchemaDotPropsHandler(visitor) |
b1ff6525ece3
[c-c schema] option to show single etype (closes #3404831)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9258
diff
changeset
|
904 |
backend = DotBackend('schema', 'BT', |
b1ff6525ece3
[c-c schema] option to show single etype (closes #3404831)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9258
diff
changeset
|
905 |
ratio='compress',size=None, |
b1ff6525ece3
[c-c schema] option to show single etype (closes #3404831)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9258
diff
changeset
|
906 |
renderer='dot', |
b1ff6525ece3
[c-c schema] option to show single etype (closes #3404831)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9258
diff
changeset
|
907 |
additionnal_param={'overlap' : 'false', |
b1ff6525ece3
[c-c schema] option to show single etype (closes #3404831)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9258
diff
changeset
|
908 |
'splines' : 'true', |
b1ff6525ece3
[c-c schema] option to show single etype (closes #3404831)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9258
diff
changeset
|
909 |
'sep' : '0.2'}) |
b1ff6525ece3
[c-c schema] option to show single etype (closes #3404831)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9258
diff
changeset
|
910 |
generator = s2d.GraphGenerator(backend) |
b1ff6525ece3
[c-c schema] option to show single etype (closes #3404831)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9258
diff
changeset
|
911 |
generator.generate(visitor, propshdlr, out) |
b1ff6525ece3
[c-c schema] option to show single etype (closes #3404831)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9258
diff
changeset
|
912 |
|
4428
03614b377ecd
Add a ``schema`` command to cmd ctrl to generate schema image.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4400
diff
changeset
|
913 |
if viewer: |
03614b377ecd
Add a ``schema`` command to cmd ctrl to generate schema image.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4400
diff
changeset
|
914 |
p = Popen((viewer, out)) |
03614b377ecd
Add a ``schema`` command to cmd ctrl to generate schema image.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4400
diff
changeset
|
915 |
p.wait() |
03614b377ecd
Add a ``schema`` command to cmd ctrl to generate schema image.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
4400
diff
changeset
|
916 |
|
5775
34195230dc2a
[packaging] more cleanups, handle javascript test files
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5762
diff
changeset
|
917 |
|
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5775
diff
changeset
|
918 |
for cmdcls in (UpdateCubicWebCatalogCommand, |
6444
cc091175d3da
[c-c i18ncube] proper command class name
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6443
diff
changeset
|
919 |
UpdateCubeCatalogCommand, |
6138
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5775
diff
changeset
|
920 |
NewCubeCommand, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5775
diff
changeset
|
921 |
ExamineLogCommand, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5775
diff
changeset
|
922 |
GenerateSchema, |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5775
diff
changeset
|
923 |
): |
65f5e488f983
update to lgc.clcommands 0.51 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5775
diff
changeset
|
924 |
CWCTL.register(cmdcls) |