devtools/devctl.py
changeset 3163 edfe43ceaa35
parent 2799 b703639614e7
parent 3118 9e7a155bc4e5
child 3230 1d25e928c299
equal deleted inserted replaced
3090:8184bec7414d 3163:edfe43ceaa35
     8 """
     8 """
     9 __docformat__ = "restructuredtext en"
     9 __docformat__ = "restructuredtext en"
    10 
    10 
    11 import sys
    11 import sys
    12 from datetime import datetime
    12 from datetime import datetime
    13 from os import mkdir, chdir
    13 from os import mkdir, chdir, getcwd
    14 from os.path import join, exists, abspath, basename, normpath, split, isdir
    14 from os.path import join, exists, abspath, basename, normpath, split, isdir
    15 from warnings import warn
    15 from warnings import warn
    16 
    16 
    17 from logilab.common import STD_BLACKLIST
    17 from logilab.common import STD_BLACKLIST
    18 from logilab.common.modutils import get_module_files
    18 from logilab.common.modutils import get_module_files
   283                                 ]:
   283                                 ]:
   284             cmd = 'xgettext --no-location --omit-header -k_ -o %s %s'
   284             cmd = 'xgettext --no-location --omit-header -k_ -o %s %s'
   285             if lang is not None:
   285             if lang is not None:
   286                 cmd += ' -L %s' % lang
   286                 cmd += ' -L %s' % lang
   287             potfile = join(tempdir, '%s.pot' % id)
   287             potfile = join(tempdir, '%s.pot' % id)
   288             execute(cmd % (potfile, ' '.join(files)))
   288             execute(cmd % (potfile, ' '.join('"%s"' % f for f in files)))
   289             if exists(potfile):
   289             if exists(potfile):
   290                 potfiles.append(potfile)
   290                 potfiles.append(potfile)
   291             else:
   291             else:
   292                 print '-> WARNING: %s file was not generated' % potfile
   292                 print '-> WARNING: %s file was not generated' % potfile
   293         print '-> merging %i .pot files' % len(potfiles)
   293         print '-> merging %i .pot files' % len(potfiles)
   294         cubicwebpot = join(tempdir, 'cubicweb.pot')
   294         cubicwebpot = join(tempdir, 'cubicweb.pot')
   295         execute('msgcat %s > %s' % (' '.join(potfiles), cubicwebpot))
   295         execute('msgcat -o %s %s' % (cubicwebpot, ' '.join('"%s"' % f for f in potfiles)))
   296         print '-> merging main pot file with existing translations.'
   296         print '-> merging main pot file with existing translations.'
   297         chdir(I18NDIR)
   297         chdir(I18NDIR)
   298         toedit = []
   298         toedit = []
   299         for lang in LANGS:
   299         for lang in LANGS:
   300             target = '%s.po' % lang
   300             target = '%s.po' % lang
   301             execute('msgmerge -N --sort-output  %s %s > %snew' % (target, cubicwebpot, target))
   301             execute('msgmerge -N --sort-output -o "%snew" "%s" "%s"' % (target, target, cubicwebpot))
   302             ensure_fs_mode(target)
   302             ensure_fs_mode(target)
   303             shutil.move('%snew' % target, target)
   303             shutil.move('%snew' % target, target)
   304             toedit.append(abspath(target))
   304             toedit.append(abspath(target))
   305         # cleanup
   305         # cleanup
   306         rm(tempdir)
   306         rm(tempdir)
   390     print '-> create cube-specific catalog'
   390     print '-> create cube-specific catalog'
   391     tmppotfile = join(tempdir, 'generated.pot')
   391     tmppotfile = join(tempdir, 'generated.pot')
   392     cubefiles = find('.', '.py', blacklist=STD_BLACKLIST+('test',))
   392     cubefiles = find('.', '.py', blacklist=STD_BLACKLIST+('test',))
   393     cubefiles.append(tali18nfile)
   393     cubefiles.append(tali18nfile)
   394     execute('xgettext --no-location --omit-header -k_ -o %s %s'
   394     execute('xgettext --no-location --omit-header -k_ -o %s %s'
   395             % (tmppotfile, ' '.join(cubefiles)))
   395             % (tmppotfile, ' '.join('"%s"' % f for f in cubefiles)))
   396     if exists(tmppotfile): # doesn't exists of no translation string found
   396     if exists(tmppotfile): # doesn't exists of no translation string found
   397         potfiles.append(tmppotfile)
   397         potfiles.append(tmppotfile)
   398     potfile = join(tempdir, 'cube.pot')
   398     potfile = join(tempdir, 'cube.pot')
   399     print '-> merging %i .pot files:' % len(potfiles)
   399     print '-> merging %i .pot files:' % len(potfiles)
   400     execute('msgcat %s > %s' % (' '.join(potfiles), potfile))
   400     execute('msgcat -o %s %s' % (potfile,
       
   401                                  ' '.join('"%s"' % f for f in potfiles)))
   401     print '-> merging main pot file with existing translations:'
   402     print '-> merging main pot file with existing translations:'
   402     chdir('i18n')
   403     chdir('i18n')
   403     for lang in LANGS:
   404     for lang in LANGS:
   404         print '-> language', lang
   405         print '-> language', lang
   405         cubepo = '%s.po' % lang
   406         cubepo = '%s.po' % lang
   406         if not exists(cubepo):
   407         if not exists(cubepo):
   407             shutil.copy(potfile, cubepo)
   408             shutil.copy(potfile, cubepo)
   408         else:
   409         else:
   409             execute('msgmerge -N -s %s %s > %snew' % (cubepo, potfile, cubepo))
   410             execute('msgmerge -N -s -o %snew %s %s' % (cubepo, cubepo, potfile))
   410             ensure_fs_mode(cubepo)
   411             ensure_fs_mode(cubepo)
   411             shutil.move('%snew' % cubepo, cubepo)
   412             shutil.move('%snew' % cubepo, cubepo)
   412         toedit.append(abspath(cubepo))
   413         toedit.append(abspath(cubepo))
   413     # cleanup
   414     # cleanup
   414     rm(tempdir)
   415     rm(tempdir)