Esempio n. 1
0
    def run(self):
        if polib is None:
            print(red(_('package polib is required.')))
            return 1
        module_names = find_packages()
        dst_rel_path = 'locale' if self.dest is None else self.dest
        # group by top-level packages and compute their directories:
        top_levels_modules = {}
        for module_name in module_names:
            top_level = module_name.partition('.')[0]
            if top_level not in top_levels_modules:
                locale_dir = os.path.join(
                    os.path.dirname(load_module(top_level).__file__),
                    dst_rel_path)
                top_levels_modules[top_level] = locale_dir

        for module_name, locale_dir in top_levels_modules.items():
            po_filename = os.path.join(locale_dir, self.language,
                                       'LC_MESSAGES', '%s.po' % module_name)
            if not os.path.isfile(po_filename):
                print(
                    yellow(
                        _('Missing file: %(filename)s. Please run the makemessages -l xx_XX command first.'
                          ) % {'filename': po_filename}))
                continue
            po_content = polib.pofile(po_filename)
            for entry in po_content:
                entry.msgstr = translate_string(entry.msgid)
            print(
                green(
                    _('Processed file: %(filename)s.') %
                    {'filename': po_filename}))
            po_content.save(po_filename)
Esempio n. 2
0
    def run(self):
        if polib is None:
            print(red(_('package polib is required.')))
            return 1
        module_names = find_packages()
        dst_rel_path = 'locale' if self.dest is None else self.dest
        # group by top-level packages and compute their directories:
        top_levels_modules = {}
        for module_name in module_names:
            top_level = module_name.partition('.')[0]
            if top_level not in top_levels_modules:
                locale_dir = os.path.join(os.path.dirname(load_module(top_level).__file__), dst_rel_path)
                top_levels_modules[top_level] = locale_dir

        for module_name, locale_dir in top_levels_modules.items():
            po_filename = os.path.join(locale_dir, self.language, 'LC_MESSAGES', '%s.po' % module_name)
            if not os.path.isfile(po_filename):
                print(yellow(_('Missing file: %(filename)s. Please run the makemessages -l xx_XX command first.')
                             % {'filename': po_filename}))
                continue
            po_content = polib.pofile(po_filename)
            for entry in po_content:
                entry.msgstr = translate_string(entry.msgid)
            print(green(_('Processed file: %(filename)s.') % {'filename': po_filename}))
            po_content.save(po_filename)
Esempio n. 3
0
 for prefix in STDIN_PREFIXES:
     for min_version in PY_VERSIONS:
         for plugins in PLUGIN_VERSIONS:
             for trans in ('yes', 'no'):
                 data = prefix + "\n" + min_version + "\n" + trans + "\n0.1\n" + plugins + "\n"
                 print(magenta(data))
                 for run_version in AVAILABLE_PYTHONS:
                     print(cyan('Running StarterPyth with ' + run_version))
                     if os.path.isdir(TEST_DIRECTORY):
                         shutil.rmtree(TEST_DIRECTORY)
                     cmd = "python{0} -c 'from starterpyth.core import main; main()'".format(run_version)
                     popen = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
                                              stdin=subprocess.PIPE)
                     stdout, stderr = popen.communicate(data.encode('utf-8'))
                     if popen.returncode:
                         print(red(cmd))
                         print(stdout.decode('utf-8'))
                         print(stderr.decode('utf-8'))
                         sys.exit(1)
                     for test_version in PY_VERSIONS[min_version]:
                         if test_version not in AVAILABLE_PYTHONS:
                             continue
                         print('Testing generated code with ' + test_version)
                         for dist_cmd in ('bdist', 'build', 'build_ext', 'test'):
                             cmd = "python{0} setup.py {1}".format(test_version, dist_cmd)
                             popen = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,
                                                      stderr=subprocess.PIPE,
                                                      cwd=TEST_DIRECTORY)
                             stdout, stderr = popen.communicate()
                             if popen.returncode:
                                 print(red(cmd))