devtools/devctl.py
branchstable
changeset 2395 e3093fc12a00
parent 2092 f5102472243d
child 2396 8bfb99d7bbcc
equal deleted inserted replaced
2394:92bba46b853f 2395:e3093fc12a00
   260         from logilab.common.shellutils import globfind, find, rm
   260         from logilab.common.shellutils import globfind, find, rm
   261         from cubicweb.common.i18n import extract_from_tal, execute
   261         from cubicweb.common.i18n import extract_from_tal, execute
   262         tempdir = mktemp()
   262         tempdir = mktemp()
   263         mkdir(tempdir)
   263         mkdir(tempdir)
   264         potfiles = [join(I18NDIR, 'entities.pot')]
   264         potfiles = [join(I18NDIR, 'entities.pot')]
   265         print '******** extract schema messages'
   265         print '-> extract schema messages.'
   266         schemapot = join(tempdir, 'schema.pot')
   266         schemapot = join(tempdir, 'schema.pot')
   267         potfiles.append(schemapot)
   267         potfiles.append(schemapot)
   268         # explicit close necessary else the file may not be yet flushed when
   268         # explicit close necessary else the file may not be yet flushed when
   269         # we'll using it below
   269         # we'll using it below
   270         schemapotstream = file(schemapot, 'w')
   270         schemapotstream = file(schemapot, 'w')
   271         generate_schema_pot(schemapotstream.write, cubedir=None)
   271         generate_schema_pot(schemapotstream.write, cubedir=None)
   272         schemapotstream.close()
   272         schemapotstream.close()
   273         print '******** extract TAL messages'
   273         print '-> extract TAL messages.'
   274         tali18nfile = join(tempdir, 'tali18n.py')
   274         tali18nfile = join(tempdir, 'tali18n.py')
   275         extract_from_tal(find(join(BASEDIR, 'web'), ('.py', '.pt')), tali18nfile)
   275         extract_from_tal(find(join(BASEDIR, 'web'), ('.py', '.pt')), tali18nfile)
   276         print '******** .pot files generation'
   276         print '-> generate .pot files.'
   277         for id, files, lang in [('pycubicweb', get_module_files(BASEDIR) + list(globfind(join(BASEDIR, 'misc', 'migration'), '*.py')), None),
   277         for id, files, lang in [('pycubicweb', get_module_files(BASEDIR) + list(globfind(join(BASEDIR, 'misc', 'migration'), '*.py')), None),
   278                                 ('schemadescr', globfind(join(BASEDIR, 'schemas'), '*.py'), None),
   278                                 ('schemadescr', globfind(join(BASEDIR, 'schemas'), '*.py'), None),
   279                                 ('yams', get_module_files(yams.__path__[0]), None),
   279                                 ('yams', get_module_files(yams.__path__[0]), None),
   280                                 ('tal', [tali18nfile], None),
   280                                 ('tal', [tali18nfile], None),
   281                                 ('js', globfind(join(BASEDIR, 'web'), 'cub*.js'), 'java'),
   281                                 ('js', globfind(join(BASEDIR, 'web'), 'cub*.js'), 'java'),
   286             potfile = join(tempdir, '%s.pot' % id)
   286             potfile = join(tempdir, '%s.pot' % id)
   287             execute(cmd % (potfile, ' '.join(files)))
   287             execute(cmd % (potfile, ' '.join(files)))
   288             if exists(potfile):
   288             if exists(potfile):
   289                 potfiles.append(potfile)
   289                 potfiles.append(potfile)
   290             else:
   290             else:
   291                 print 'WARNING: %s file not generated' % potfile
   291                 print '-> WARNING: %s file was not generated' % potfile
   292         print '******** merging .pot files'
   292         print '-> merging %i .pot files' % len(potfiles)
   293         cubicwebpot = join(tempdir, 'cubicweb.pot')
   293         cubicwebpot = join(tempdir, 'cubicweb.pot')
   294         execute('msgcat %s > %s' % (' '.join(potfiles), cubicwebpot))
   294         execute('msgcat %s > %s' % (' '.join(potfiles), cubicwebpot))
   295         print '******** merging main pot file with existing translations'
   295         print '-> merging main pot file with existing translations.'
   296         chdir(I18NDIR)
   296         chdir(I18NDIR)
   297         toedit = []
   297         toedit = []
   298         for lang in LANGS:
   298         for lang in LANGS:
   299             target = '%s.po' % lang
   299             target = '%s.po' % lang
   300             execute('msgmerge -N --sort-output  %s %s > %snew' % (target, cubicwebpot, target))
   300             execute('msgmerge -N --sort-output  %s %s > %snew' % (target, cubicwebpot, target))
   330 
   330 
   331 def update_cubes_catalogs(cubes):
   331 def update_cubes_catalogs(cubes):
   332     toedit = []
   332     toedit = []
   333     for cubedir in cubes:
   333     for cubedir in cubes:
   334         if not isdir(cubedir):
   334         if not isdir(cubedir):
   335             print 'not a directory', cubedir
   335             print '-> ignoring %s that is not a directory.' % cubedir
   336             continue
   336             continue
   337         try:
   337         try:
   338             toedit += update_cube_catalogs(cubedir)
   338             toedit += update_cube_catalogs(cubedir)
   339         except Exception:
   339         except Exception:
   340             import traceback
   340             import traceback
   341             traceback.print_exc()
   341             traceback.print_exc()
   342             print 'error while updating catalogs for', cubedir
   342             print '-> Error while updating catalogs for cube', cubedir
   343     # instructions pour la suite
   343     # instructions pour la suite
   344     print '*' * 72
   344     print '*' * 72
   345     print 'you can now edit the following files:'
   345     print 'you can now edit the following files:'
   346     print '* ' + '\n* '.join(toedit)
   346     print '* ' + '\n* '.join(toedit)
   347 
   347 
   355     toedit = []
   355     toedit = []
   356     cube = basename(normpath(cubedir))
   356     cube = basename(normpath(cubedir))
   357     tempdir = mktemp()
   357     tempdir = mktemp()
   358     mkdir(tempdir)
   358     mkdir(tempdir)
   359     print '*' * 72
   359     print '*' * 72
   360     print 'updating %s cube...' % cube
   360     print '-> updating cube %s' % cube
   361     chdir(cubedir)
   361     chdir(cubedir)
   362     potfiles = [join('i18n', scfile) for scfile in ('entities.pot',)
   362     potfiles = [join('i18n', scfile) for scfile in ('entities.pot',)
   363                 if exists(join('i18n', scfile))]
   363                 if exists(join('i18n', scfile))]
   364     print '******** extract schema messages'
   364     print '-> extract schema messages'
   365     schemapot = join(tempdir, 'schema.pot')
   365     schemapot = join(tempdir, 'schema.pot')
   366     potfiles.append(schemapot)
   366     potfiles.append(schemapot)
   367     # explicit close necessary else the file may not be yet flushed when
   367     # explicit close necessary else the file may not be yet flushed when
   368     # we'll using it below
   368     # we'll using it below
   369     schemapotstream = file(schemapot, 'w')
   369     schemapotstream = file(schemapot, 'w')
   370     generate_schema_pot(schemapotstream.write, cubedir)
   370     generate_schema_pot(schemapotstream.write, cubedir)
   371     schemapotstream.close()
   371     schemapotstream.close()
   372     print '******** extract TAL messages'
   372     print '-> extract TAL messages'
   373     tali18nfile = join(tempdir, 'tali18n.py')
   373     tali18nfile = join(tempdir, 'tali18n.py')
   374     extract_from_tal(find('.', ('.py', '.pt'), blacklist=STD_BLACKLIST+('test',)), tali18nfile)
   374     extract_from_tal(find('.', ('.py', '.pt'), blacklist=STD_BLACKLIST+('test',)), tali18nfile)
   375     print '******** extract Javascript messages'
   375     print '-> extract Javascript messages'
   376     jsfiles =  [jsfile for jsfile in find('.', '.js') if basename(jsfile).startswith('cub')]
   376     jsfiles =  [jsfile for jsfile in find('.', '.js') if basename(jsfile).startswith('cub')]
   377     if jsfiles:
   377     if jsfiles:
   378         tmppotfile = join(tempdir, 'js.pot')
   378         tmppotfile = join(tempdir, 'js.pot')
   379         execute('xgettext --no-location --omit-header -k_ -L java --from-code=utf-8 -o %s %s'
   379         execute('xgettext --no-location --omit-header -k_ -L java --from-code=utf-8 -o %s %s'
   380                 % (tmppotfile, ' '.join(jsfiles)))
   380                 % (tmppotfile, ' '.join(jsfiles)))
   381         # no pot file created if there are no string to translate
   381         # no pot file created if there are no string to translate
   382         if exists(tmppotfile):
   382         if exists(tmppotfile):
   383             potfiles.append(tmppotfile)
   383             potfiles.append(tmppotfile)
   384     print '******** create cube specific catalog'
   384     print '-> create cube-specific catalog'
   385     tmppotfile = join(tempdir, 'generated.pot')
   385     tmppotfile = join(tempdir, 'generated.pot')
   386     cubefiles = find('.', '.py', blacklist=STD_BLACKLIST+('test',))
   386     cubefiles = find('.', '.py', blacklist=STD_BLACKLIST+('test',))
   387     cubefiles.append(tali18nfile)
   387     cubefiles.append(tali18nfile)
   388     execute('xgettext --no-location --omit-header -k_ -o %s %s'
   388     execute('xgettext --no-location --omit-header -k_ -o %s %s'
   389             % (tmppotfile, ' '.join(cubefiles)))
   389             % (tmppotfile, ' '.join(cubefiles)))
   390     if exists(tmppotfile): # doesn't exists of no translation string found
   390     if exists(tmppotfile): # doesn't exists of no translation string found
   391         potfiles.append(tmppotfile)
   391         potfiles.append(tmppotfile)
   392     potfile = join(tempdir, 'cube.pot')
   392     potfile = join(tempdir, 'cube.pot')
   393     print '******** merging .pot files'
   393     print '-> merging %i .pot files:' % len(potfiles)
   394     execute('msgcat %s > %s' % (' '.join(potfiles), potfile))
   394     execute('msgcat %s > %s' % (' '.join(potfiles), potfile))
   395     print '******** merging main pot file with existing translations'
   395     print '-> merging main pot file with existing translations:'
   396     chdir('i18n')
   396     chdir('i18n')
   397     for lang in LANGS:
   397     for lang in LANGS:
   398         print '****', lang
   398         print '-> language', lang
   399         cubepo = '%s.po' % lang
   399         cubepo = '%s.po' % lang
   400         if not exists(cubepo):
   400         if not exists(cubepo):
   401             shutil.copy(potfile, cubepo)
   401             shutil.copy(potfile, cubepo)
   402         else:
   402         else:
   403             execute('msgmerge -N -s %s %s > %snew' % (cubepo, potfile, cubepo))
   403             execute('msgmerge -N -s %s %s > %snew' % (cubepo, potfile, cubepo))