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