def test_include(self): files = set(find(DATA_DIR, ".py")) self.assertSetEqual( files, set( [ join(DATA_DIR, f) for f in [ "__init__.py", "module.py", "module2.py", "noendingnewline.py", "nonregr.py", join("sub", "momo.py"), ] ] ), ) files = set(find(DATA_DIR, (".py",), blacklist=("sub",))) self.assertSetEqual( files, set( [ join(DATA_DIR, f) for f in ["__init__.py", "module.py", "module2.py", "noendingnewline.py", "nonregr.py"] ] ), )
def test_include(self): files = set(find(DATA_DIR, '.py')) self.assertSetEqual(files, set([join(DATA_DIR, f) for f in ['__init__.py', 'module.py', 'module2.py', 'noendingnewline.py', 'nonregr.py', join('sub', 'momo.py')]])) files = set(find(DATA_DIR, ('.py',), blacklist=('sub',))) self.assertSetEqual(files, set([join(DATA_DIR, f) for f in ['__init__.py', 'module.py', 'module2.py', 'noendingnewline.py', 'nonregr.py']]))
def test_exclude(self): files = set(find(DATA_DIR, ('.py', '.pyc'), exclude=True)) self.assertSetEqual(files, set([join(DATA_DIR, f) for f in ['foo.txt', 'newlines.txt', 'normal_file.txt', 'test.ini', 'test1.msg', 'test2.msg', 'spam.txt', join('sub', 'doc.txt'), 'write_protected_file.txt', ]]))
def _get_files(pkginfo, directories, include_exts=(), exclude_exts=None, exclude_dirs=()): """return files matching or excluding a set of extensions, in the first existing directory """ cwd = os.getcwd() os.chdir(pkginfo.base_directory) exclude_dirs += BASE_EXCLUDE try: for directory in directories: if exists(directory): return find(directory, include_exts, exclude_exts, exclude_dirs) return [] finally: os.chdir(cwd)
def test_exclude(self): files = set(find(DATA_DIR, (".py", ".pyc"), exclude=True)) self.assertSetEqual( files, set( [ join(DATA_DIR, f) for f in [ "foo.txt", "newlines.txt", "normal_file.txt", "test.ini", "test1.msg", "test2.msg", "spam.txt", join("sub", "doc.txt"), "write_protected_file.txt", ] ] ), )
def find(self, exts, blacklist=None): """collect files with extensions ``exts`` in the cube directory """ if blacklist is None: blacklist = self.blacklist return find(self.cubedir, exts, blacklist=blacklist)
def run(self, args): """run the command with its specific arguments""" import shutil import tempfile import yams from logilab.common.fileutils import ensure_fs_mode from logilab.common.shellutils import globfind, find, rm from logilab.common.modutils import get_module_files from cubicweb.i18n import extract_from_tal, execute2 tempdir = tempfile.mkdtemp(prefix='cw-') cwi18ndir = WebConfiguration.i18n_lib_dir() print('-> extract messages:', end=' ') print('schema', end=' ') schemapot = osp.join(tempdir, 'schema.pot') potfiles = [schemapot] potfiles.append(schemapot) # explicit close necessary else the file may not be yet flushed when # we'll using it below schemapotstream = open(schemapot, 'w') generate_schema_pot(schemapotstream.write, cubedir=None) schemapotstream.close() print('TAL', end=' ') tali18nfile = osp.join(tempdir, 'tali18n.py') extract_from_tal(find(osp.join(BASEDIR, 'web'), ('.py', '.pt')), tali18nfile) print('-> generate .pot files.') pyfiles = get_module_files(BASEDIR) pyfiles += globfind(osp.join(BASEDIR, 'misc', 'migration'), '*.py') schemafiles = globfind(osp.join(BASEDIR, 'schemas'), '*.py') jsfiles = globfind(osp.join(BASEDIR, 'web'), 'cub*.js') for id, files, lang in [ ('pycubicweb', pyfiles, None), ('schemadescr', schemafiles, None), ('yams', get_module_files(yams.__path__[0]), None), ('tal', [tali18nfile], None), ('js', jsfiles, 'java'), ]: potfile = osp.join(tempdir, '%s.pot' % id) cmd = ['xgettext', '--no-location', '--omit-header', '-k_'] if lang is not None: cmd.extend(['-L', lang]) cmd.extend(['-o', potfile]) cmd.extend(files) execute2(cmd) if osp.exists(potfile): potfiles.append(potfile) else: print('-> WARNING: %s file was not generated' % potfile) print('-> merging %i .pot files' % len(potfiles)) cubicwebpot = osp.join(tempdir, 'cubicweb.pot') cmd = ['msgcat', '-o', cubicwebpot] + potfiles execute2(cmd) print('-> merging main pot file with existing translations.') chdir(cwi18ndir) toedit = [] for lang in CubicWebNoAppConfiguration.cw_languages(): target = '%s.po' % lang cmd = [ 'msgmerge', '-N', '--sort-output', '-o', target + 'new', target, cubicwebpot ] execute2(cmd) ensure_fs_mode(target) shutil.move('%snew' % target, target) toedit.append(osp.abspath(target)) # cleanup rm(tempdir) # instructions pour la suite print('-> regenerated CubicWeb\'s .po catalogs.') print('\nYou can now edit the following files:') print('* ' + '\n* '.join(toedit)) print('when you are done, run "cubicweb-ctl i18ncube yourcube".')