devtools/devctl.py
changeset 58 c7c22b210372
parent 57 3ab952845448
child 60 dc90556488d8
equal deleted inserted replaced
57:3ab952845448 58:c7c22b210372
   210             raise BadCommandUsage('Too much arguments')
   210             raise BadCommandUsage('Too much arguments')
   211         import shutil
   211         import shutil
   212         from tempfile import mktemp
   212         from tempfile import mktemp
   213         import yams
   213         import yams
   214         from logilab.common.fileutils import ensure_fs_mode
   214         from logilab.common.fileutils import ensure_fs_mode
   215         from logilab.common.shellutils import find, rm
   215         from logilab.common.shellutils import globfind, find, rm
   216         from cubicweb.common.i18n import extract_from_tal, execute
   216         from cubicweb.common.i18n import extract_from_tal, execute
   217         tempdir = mktemp()
   217         tempdir = mktemp()
   218         mkdir(tempdir)
   218         mkdir(tempdir)
   219         potfiles = [join(I18NDIR, 'entities.pot')]
   219         potfiles = [join(I18NDIR, 'entities.pot')]
   220         print '******** extract schema messages'
   220         print '******** extract schema messages'
   227         schemapotstream.close()
   227         schemapotstream.close()
   228         print '******** extract TAL messages'
   228         print '******** extract TAL messages'
   229         tali18nfile = join(tempdir, 'tali18n.py')
   229         tali18nfile = join(tempdir, 'tali18n.py')
   230         extract_from_tal(find(join(BASEDIR, 'web'), ('.py', '.pt')), tali18nfile)
   230         extract_from_tal(find(join(BASEDIR, 'web'), ('.py', '.pt')), tali18nfile)
   231         print '******** .pot files generation'
   231         print '******** .pot files generation'
   232         for id, files, lang in [('cubicweb', get_module_files(BASEDIR) + find(join(BASEDIR, 'misc', 'migration'), '.py'), None),
   232         for id, files, lang in [('cubicweb', get_module_files(BASEDIR) + list(globfind(join(BASEDIR, 'misc', 'migration'), '*.py')), None),
   233                                 ('schemadescr', find(join(BASEDIR, 'schemas'), '.py'), None),
   233                                 ('schemadescr', globfind(join(BASEDIR, 'schemas'), '*.py'), None),
   234                                 ('yams', get_module_files(yams.__path__[0]), None),
   234                                 ('yams', get_module_files(yams.__path__[0]), None),
   235                                 ('tal', [tali18nfile], None),
   235                                 ('tal', [tali18nfile], None),
   236                                 ('js', find(join(BASEDIR, 'web'), '.js'), 'java'),
   236                                 ('js', globfind(join(BASEDIR, 'web'), 'cub*.js'), 'java'),
   237                                 ]:
   237                                 ]:
   238             cmd = 'xgettext --no-location --omit-header -k_ -o %s %s'
   238             cmd = 'xgettext --add-location --omit-header -k_ -o %s %s'
   239             if lang is not None:
   239             if lang is not None:
   240                 cmd += ' -L %s' % lang
   240                 cmd += ' -L %s' % lang
   241             potfiles.append(join(tempdir, '%s.pot' % id))
   241             potfiles.append(join(tempdir, '%s.pot' % id))
   242             execute(cmd % (potfiles[-1], ' '.join(files)))
   242             execute(cmd % (potfiles[-1], ' '.join(files)))
   243         print '******** merging .pot files'
   243         print '******** merging .pot files'
   251             execute('msgmerge -N --sort-output  %s %s > %snew' % (target, cubicwebpot, target))
   251             execute('msgmerge -N --sort-output  %s %s > %snew' % (target, cubicwebpot, target))
   252             ensure_fs_mode(target)
   252             ensure_fs_mode(target)
   253             shutil.move('%snew' % target, target)
   253             shutil.move('%snew' % target, target)
   254             toedit.append(abspath(target))
   254             toedit.append(abspath(target))
   255         # cleanup
   255         # cleanup
   256         rm(tempdir)
   256         # rm(tempdir)
   257         # instructions pour la suite
   257         # instructions pour la suite
   258         print '*' * 72
   258         print '*' * 72
   259         print 'you can now edit the following files:'
   259         print 'you can now edit the following files:'
   260         print '* ' + '\n* '.join(toedit)
   260         print '* ' + '\n* '.join(toedit)
   261         print
   261         print
   308         schemapotstream.close()
   308         schemapotstream.close()
   309         print '******** extract TAL messages'
   309         print '******** extract TAL messages'
   310         tali18nfile = join(tempdir, 'tali18n.py')
   310         tali18nfile = join(tempdir, 'tali18n.py')
   311         extract_from_tal(find('.', ('.py', '.pt'), blacklist=STD_BLACKLIST+('test',)), tali18nfile)
   311         extract_from_tal(find('.', ('.py', '.pt'), blacklist=STD_BLACKLIST+('test',)), tali18nfile)
   312         print '******** extract Javascript messages'
   312         print '******** extract Javascript messages'
   313         jsfiles =  find('.', '.js')
   313         jsfiles =  [jsfile for jsfile in find('.', '.js') if basename(jsfile).startswith('cub')]
   314         if jsfiles:
   314         if jsfiles:
   315             tmppotfile = join(tempdir, 'js.pot')
   315             tmppotfile = join(tempdir, 'js.pot')
   316             execute('xgettext --no-location --omit-header -k_ -L java --from-code=utf-8 -o %s %s'
   316             execute('xgettext --no-location --omit-header -k_ -L java --from-code=utf-8 -o %s %s'
   317                     % (tmppotfile, ' '.join(jsfiles)))
   317                     % (tmppotfile, ' '.join(jsfiles)))
   318             # no pot file created if there are no string to translate
   318             # no pot file created if there are no string to translate