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