devtools/devctl.py
changeset 5545 25fd74c23f91
parent 5489 50e2d8e10638
parent 5537 2889091bd1bf
child 5556 9ab2b4c74baf
equal deleted inserted replaced
5527:01a7228ab5a0 5545:25fd74c23f91
    56     def __init__(self, *cubes):
    56     def __init__(self, *cubes):
    57         super(DevConfiguration, self).__init__(cubes and cubes[0] or None)
    57         super(DevConfiguration, self).__init__(cubes and cubes[0] or None)
    58         if cubes:
    58         if cubes:
    59             self._cubes = self.reorder_cubes(
    59             self._cubes = self.reorder_cubes(
    60                 self.expand_cubes(cubes, with_recommends=True))
    60                 self.expand_cubes(cubes, with_recommends=True))
       
    61             self.load_site_cubicweb()
    61         else:
    62         else:
    62             self._cubes = ()
    63             self._cubes = ()
    63 
    64 
    64     @property
    65     @property
    65     def apphome(self):
    66     def apphome(self):
   349         update_cubes_catalogs(cubes)
   350         update_cubes_catalogs(cubes)
   350 
   351 
   351 
   352 
   352 def update_cubes_catalogs(cubes):
   353 def update_cubes_catalogs(cubes):
   353     for cubedir in cubes:
   354     for cubedir in cubes:
   354         toedit = []
       
   355         if not isdir(cubedir):
   355         if not isdir(cubedir):
   356             print '-> ignoring %s that is not a directory.' % cubedir
   356             print '-> ignoring %s that is not a directory.' % cubedir
   357             continue
   357             continue
   358         try:
   358         try:
   359             toedit += update_cube_catalogs(cubedir)
   359             toedit = update_cube_catalogs(cubedir)
   360         except Exception:
   360         except Exception:
   361             import traceback
   361             import traceback
   362             traceback.print_exc()
   362             traceback.print_exc()
   363             print '-> error while updating catalogs for cube', cubedir
   363             print '-> error while updating catalogs for cube', cubedir
   364         else:
   364         else:
   365             # instructions pour la suite
   365             # instructions pour la suite
   366             print '-> regenerated .po catalogs for cube %s.' % cubedir
   366             if toedit:
   367             print '\nYou can now edit the following files:'
   367                 print '-> regenerated .po catalogs for cube %s.' % cubedir
   368             print '* ' + '\n* '.join(toedit)
   368                 print '\nYou can now edit the following files:'
   369             print ('When you are done, run "cubicweb-ctl i18ninstance '
   369                 print '* ' + '\n* '.join(toedit)
   370                    '<yourinstance>" to see changes in your instances.')
   370                 print ('When you are done, run "cubicweb-ctl i18ninstance '
       
   371                        '<yourinstance>" to see changes in your instances.')
   371 
   372 
   372 def update_cube_catalogs(cubedir):
   373 def update_cube_catalogs(cubedir):
   373     import shutil
   374     import shutil
   374     import tempfile
   375     import tempfile
   375     from logilab.common.fileutils import ensure_fs_mode
   376     from logilab.common.fileutils import ensure_fs_mode
   376     from logilab.common.shellutils import find, rm
   377     from logilab.common.shellutils import find, rm
   377     from cubicweb.i18n import extract_from_tal, execute
   378     from cubicweb.i18n import extract_from_tal, execute
   378     toedit = []
       
   379     cube = basename(normpath(cubedir))
   379     cube = basename(normpath(cubedir))
   380     tempdir = tempfile.mkdtemp()
   380     tempdir = tempfile.mkdtemp()
   381     print underline_title('Updating i18n catalogs for cube %s' % cube)
   381     print underline_title('Updating i18n catalogs for cube %s' % cube)
   382     chdir(cubedir)
   382     chdir(cubedir)
   383     if exists(join('i18n', 'entities.pot')):
   383     if exists(join('i18n', 'entities.pot')):
   418         potfiles.append(tmppotfile)
   418         potfiles.append(tmppotfile)
   419     potfile = join(tempdir, 'cube.pot')
   419     potfile = join(tempdir, 'cube.pot')
   420     print '-> merging %i .pot files:' % len(potfiles)
   420     print '-> merging %i .pot files:' % len(potfiles)
   421     execute('msgcat -o %s %s' % (potfile,
   421     execute('msgcat -o %s %s' % (potfile,
   422                                  ' '.join('"%s"' % f for f in potfiles)))
   422                                  ' '.join('"%s"' % f for f in potfiles)))
       
   423     if not exists(potfile):
       
   424         print 'no message catalog for cube', cube, 'nothing to translate'
       
   425         # cleanup
       
   426         rm(tempdir)
       
   427         return ()
   423     print '-> merging main pot file with existing translations:'
   428     print '-> merging main pot file with existing translations:'
   424     chdir('i18n')
   429     chdir('i18n')
       
   430     toedit = []
   425     for lang in LANGS:
   431     for lang in LANGS:
   426         print '-> language', lang
   432         print '-> language', lang
   427         cubepo = '%s.po' % lang
   433         cubepo = '%s.po' % lang
   428         if not exists(cubepo):
   434         if not exists(cubepo):
   429             shutil.copy(potfile, cubepo)
   435             shutil.copy(potfile, cubepo)
   518 # details.
   524 # details.
   519 #
   525 #
   520 # You should have received a copy of the GNU Lesser General Public License along
   526 # You should have received a copy of the GNU Lesser General Public License along
   521 # with this program. If not, see <http://www.gnu.org/licenses/>.
   527 # with this program. If not, see <http://www.gnu.org/licenses/>.
   522 ''',
   528 ''',
       
   529 
   523         'GPL': '''\
   530         'GPL': '''\
   524 # This program is free software: you can redistribute it and/or modify it under
   531 # This program is free software: you can redistribute it and/or modify it under
   525 # the terms of the GNU General Public License as published by the Free Software
   532 # the terms of the GNU General Public License as published by the Free Software
   526 # Foundation, either version 2.1 of the License, or (at your option) any later
   533 # Foundation, either version 2.1 of the License, or (at your option) any later
   527 # version.
   534 # version.