コード例 #1
0
 def test_globfind(self):
     files = set(globfind(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(globfind(DATA_DIR, 'mo*.py'))
     self.assertSetEqual(files,
                         set([join(DATA_DIR, f) for f in ['module.py', 'module2.py',
                                                          join('sub', 'momo.py')]]))
     files = set(globfind(DATA_DIR, 'mo*.py', blacklist=('sub',)))
     self.assertSetEqual(files,
                         set([join(DATA_DIR, f) for f in ['module.py', 'module2.py']]))
コード例 #2
0
ファイル: sphinxutils.py プロジェクト: steverecio/.emacs.d
 def find_modules(self, exclude_dirs):
     basepath = osp.dirname(self.code_dir)
     basedir = osp.basename(basepath) + osp.sep
     if basedir not in sys.path:
         sys.path.insert(1, basedir)
     for filepath in globfind(self.code_dir, '*.py', exclude_dirs):
         if osp.basename(filepath) in ('setup.py', '__pkginfo__.py'):
             continue
         try:
             module = load_module_from_file(filepath)
         except: # module might be broken or magic
             dotted_path = modpath_from_file(filepath)
             module = type('.'.join(dotted_path), (), {}) # mock it
         yield module
コード例 #3
0
 def find_modules(self, exclude_dirs):
     basepath = osp.dirname(self.code_dir)
     basedir = osp.basename(basepath) + osp.sep
     if basedir not in sys.path:
         sys.path.insert(1, basedir)
     for filepath in globfind(self.code_dir, '*.py', exclude_dirs):
         if osp.basename(filepath) in ('setup.py', '__pkginfo__.py'):
             continue
         try:
             module = load_module_from_file(filepath)
         except: # module might be broken or magic
             dotted_path = modpath_from_file(filepath)
             module = type('.'.join(dotted_path), (), {}) # mock it
         yield module
コード例 #4
0
 def test_globfind(self):
     files = set(globfind(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(globfind(DATA_DIR, "mo*.py"))
     self.assertSetEqual(
         files, set([join(DATA_DIR, f) for f in ["module.py", "module2.py", join("sub", "momo.py")]])
     )
     files = set(globfind(DATA_DIR, "mo*.py", blacklist=("sub",)))
     self.assertSetEqual(files, set([join(DATA_DIR, f) for f in ["module.py", "module2.py"]]))
コード例 #5
0
 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".')