コード例 #1
0
def main(l10n_dst, jar_file_name):
    shutil.copy(DEF_JAR_FILE_NAME, jar_file_name);

    # Note: Use the destination directory here to get en-US as well.
    locale_list = localeUtils.getLocalesList(l10n_dst)

    print("updating locales list in", jar_file_name)
    with io.open(jar_file_name, "r+") as jar_file:
        jar_mn = jar_file.read()

        # Replace multiple locale registrations with new locales.
        # The jar.mn preprocessor can't cope with '-' so we add some defines
        # in so it can handle '_' instead.
        dashLocales = []
        for locale in locale_list:
            if "-" in locale:
                dashLocales.append('#define {0} {1}'.format(locale.replace("-", "_"), locale))

        new_content = re.sub(
            '(#define .+\n)+',
            '\n'.join(dashLocales) + '\n',
            jar_mn)

        # One big if statement to avoid lots of if/endif lines, and the preprocessor
        # can't cope with '\' on the end of the line.
        jar_locales = ['AB_CD == {0}'.format(x.replace("-", "_")) for x in locale_list]

        new_content = re.sub(
            '(#if AB_CD.+\n)',
            '#if ' + ' || '.join(jar_locales) + '\n',
            new_content)

        jar_file.seek(0)
        jar_file.truncate(0)
        jar_file.write(new_content)
コード例 #2
0
ファイル: generateLocaleManifest.py プロジェクト: 1234-/loop
def main(l10n_src, output_file_name):
    locale_list = localeUtils.getLocalesList(l10n_src)

    localeLines = ["locale loop {0} {0}/".format(x) for x in locale_list]

    output_file = io.open(output_file_name, "wb")

    manifest_output = "\n".join(localeLines) + "\n"

    output_file.write(manifest_output)

    output_file.close()
コード例 #3
0
def main(l10n_src, output_file_name):
    locale_list = localeUtils.getLocalesList(l10n_src)

    localeLines = ["locale loop {0} {0}/".format(x) for x in locale_list]

    output_file = io.open(output_file_name, "wb")

    manifest_output = "\n".join(localeLines) + "\n"

    output_file.write(manifest_output)

    output_file.close()
コード例 #4
0
ファイル: locale_update.py プロジェクト: 1234-/loop
def main(l10n_src, l10n_dst, index_file_name, jar_file_name):
    repo = Repo(os.path.abspath(l10n_src))

    print("Updating L10n repo:", l10n_src)

    repo.remotes.origin.pull()

    print("deleting existing l10n content tree:", l10n_dst)

    l10n_src_files_dir = os.path.join(l10n_src, "l10n")

    old_locale_dirs = os.listdir(l10n_dst)

    for dir in old_locale_dirs:
        # Ensure we leave en-US alone.
        if dir != "en-US":
            shutil.rmtree(os.path.join(l10n_dst, dir), ignore_errors=True)

    print("updating l10n tree from", l10n_src_files_dir)

    def create_locale(src_dir):
        # Convert loop-client-l10n repo names to loop repo names.
        dst_dir = localeUtils.convertLocale(src_dir)

        # Don't copy the en-US files. Stick with what's in our tree as that might
        # be a later version.
        if dst_dir != "en-US":
            # Copy the l10n files, but ignore any `.keep`
            shutil.copytree(os.path.join(l10n_src_files_dir, src_dir),
                            os.path.join(l10n_dst, dst_dir),
                            ignore=shutil.ignore_patterns(".keep"))
        return dst_dir

    for x in os.listdir(l10n_src_files_dir):
        if x[0] != ".":
            create_locale(x)

    # Note: Use the destination directory here to get en-US as well.
    locale_list = localeUtils.getLocalesList(l10n_dst)

    print("updating locales list in", index_file_name)
    # We use encoding="UTF-8" so that we have a known consistent encoding format.
    # Sometimes the locale isn't always defined correctly for python, so we try
    # to handle that here.
    with io.open(index_file_name, "r+", encoding="UTF-8") as index_file:
        index_html = index_file.read()

        # Replace the one meta line with new locales.
        new_content = re.sub(
            '<meta name=(["|\'])locales\\1.*? content=(["|\']).*?\\2.*? />',
            '<meta name="locales" content="' + ",".join(locale_list) + '" />',
            index_html, 1, re.M | re.S)

        index_file.seek(0)
        index_file.truncate(0)
        index_file.write(new_content)

    print("updating locales list in", jar_file_name)
    with io.open(jar_file_name, "r+", encoding="UTF-8") as jar_file:
        jar_mn = jar_file.read()

        # Replace multiple locale registrations with new locales.
        # The jar.mn preprocessor can't cope with '-' so we add some defines
        # in so it can handle '_' instead.
        dashLocales = []
        for locale in locale_list:
            if "-" in locale:
                dashLocales.append('#define {0} {1}'.format(locale.replace("-", "_"), locale))

        new_content = re.sub(
            '(#define .+\n)+',
            '\n'.join(dashLocales) + '\n',
            jar_mn)

        # One big if statement to avoid lots of if/endif lines, and the preprocessor
        # can't cope with '\' on the end of the line.
        jar_locales = ['AB_CD == {0}'.format(x.replace("-", "_")) for x in locale_list]

        new_content = re.sub(
            '(#if AB_CD.+\n)',
            '#if ' + ' || '.join(jar_locales) + '\n',
            new_content)

        jar_file.seek(0)
        jar_file.truncate(0)
        jar_file.write(new_content)

    print("Please check the diffs, and then commit the result. Suggested commit message:")
    print("chore(package): Update L10n from changeset", repo.heads.master.commit.hexsha)
コード例 #5
0
def main(l10n_src, l10n_dst, index_file_name, jar_file_name):
    repo = Repo(os.path.abspath(l10n_src))

    print("Updating L10n repo:", l10n_src)

    repo.remotes.origin.pull()

    print("deleting existing l10n content tree:", l10n_dst)

    l10n_src_files_dir = os.path.join(l10n_src, "l10n")

    old_locale_dirs = os.listdir(l10n_dst)

    for dir in old_locale_dirs:
        # Ensure we leave en-US alone.
        if dir != "en-US":
            shutil.rmtree(os.path.join(l10n_dst, dir), ignore_errors=True)

    print("updating l10n tree from", l10n_src_files_dir)

    def create_locale(src_dir):
        # Convert loop-client-l10n repo names to loop repo names.
        dst_dir = localeUtils.convertLocale(src_dir)

        # Don't copy the en-US files. Stick with what's in our tree as that might
        # be a later version.
        if dst_dir != "en-US":
            # Copy the l10n files, but ignore any `.keep`
            shutil.copytree(os.path.join(l10n_src_files_dir, src_dir),
                            os.path.join(l10n_dst, dst_dir),
                            ignore=shutil.ignore_patterns(".keep"))
        return dst_dir

    for x in os.listdir(l10n_src_files_dir):
        if x[0] != ".":
            create_locale(x)

    # Note: Use the destination directory here to get en-US as well.
    locale_list = localeUtils.getLocalesList(l10n_dst)

    print("updating locales list in", index_file_name)
    # We use encoding="UTF-8" so that we have a known consistent encoding format.
    # Sometimes the locale isn't always defined correctly for python, so we try
    # to handle that here.
    with io.open(index_file_name, "r+", encoding="UTF-8") as index_file:
        index_html = index_file.read()

        # Replace the one meta line with new locales.
        new_content = re.sub(
            '<meta name=(["|\'])locales\\1.*? content=(["|\']).*?\\2.*? />',
            '<meta name="locales" content="' + ",".join(locale_list) + '" />',
            index_html, 1, re.M | re.S)

        index_file.seek(0)
        index_file.truncate(0)
        index_file.write(new_content)

    print("updating locales list in", jar_file_name)
    with io.open(jar_file_name, "r+", encoding="UTF-8") as jar_file:
        jar_mn = jar_file.read()

        # Replace multiple locale registrations with new locales.
        # The jar.mn preprocessor can't cope with '-' so we add some defines
        # in so it can handle '_' instead.
        dashLocales = []
        for locale in locale_list:
            if "-" in locale:
                dashLocales.append('#define {0} {1}'.format(
                    locale.replace("-", "_"), locale))

        new_content = re.sub('(#define .+\n)+', '\n'.join(dashLocales) + '\n',
                             jar_mn)

        # One big if statement to avoid lots of if/endif lines, and the preprocessor
        # can't cope with '\' on the end of the line.
        jar_locales = [
            'AB_CD == {0}'.format(x.replace("-", "_")) for x in locale_list
        ]

        new_content = re.sub('(#if AB_CD.+\n)',
                             '#if ' + ' || '.join(jar_locales) + '\n',
                             new_content)

        jar_file.seek(0)
        jar_file.truncate(0)
        jar_file.write(new_content)

    print(
        "Please check the diffs, and then commit the result. Suggested commit message:"
    )
    print("chore(package): Update L10n from changeset",
          repo.heads.master.commit.hexsha)