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