コード例 #1
0
async def l10n_bump(config, task, repo_path):
    """Perform a version bump.

    This function takes its inputs from task by using the ``get_l10n_bump_info``
    function from treescript.task. Using `next_version` and `files`.

    This function does nothing (but logs) if the current version and next version
    match, and nothing if the next_version is actually less than current_version.

    Args:
        config (dict): the running config
        task (dict): the running task
        repo_path (str): the source directory

    Raises:
        TaskVerificationError: if a file specified is not allowed, or
                               if the file is not in the target repository.

    Returns:
        bool: True if there are any changes.

    """
    log.info("Preparing to bump l10n changesets.")
    dontbuild = get_dontbuild(task)
    ignore_closed_tree = get_ignore_closed_tree(task)
    l10n_bump_info = get_l10n_bump_info(task)
    revision_info = None
    changes = 0

    if not ignore_closed_tree:
        if not await check_treestatus(config, task):
            log.info("Treestatus is closed; skipping l10n bump.")
            return
    for bump_config in l10n_bump_info:
        if bump_config.get("revision_url"):
            revision_info = await get_revision_info(bump_config, repo_path)
        path = os.path.join(repo_path, bump_config["path"])
        old_contents = load_json_or_yaml(path, is_path=True)
        new_contents = build_revision_dict(bump_config, revision_info,
                                           repo_path)
        if old_contents == new_contents:
            continue
        with open(path, "w") as fh:
            fh.write(
                json.dumps(new_contents,
                           sort_keys=True,
                           indent=4,
                           separators=(",", ": ")))
        locale_map = build_locale_map(old_contents, new_contents)
        message = build_commit_message(bump_config["name"],
                                       locale_map,
                                       dontbuild=dontbuild,
                                       ignore_closed_tree=ignore_closed_tree)
        await run_hg_command(config,
                             "commit",
                             "-m",
                             message,
                             repo_path=repo_path)
        changes += 1
    return changes
コード例 #2
0
async def _maybe_bump_l10n(config, task, repo_path):
    if get_l10n_bump_info(task, raise_on_empty=False):
        await l10n_bump(config, task, repo_path)
        output = await run_hg_command(config, "log", "--patch", "--verbose", "-r", ".", repo_path=repo_path, return_output=True, expected_exit_codes=(0, 1))
        path = os.path.join(config["artifact_dir"], "public", "logs", "l10n_bump.diff")
        makedirs(os.path.dirname(path))
        with open(path, "w") as fh:
            fh.write(output)
コード例 #3
0
ファイル: l10n.py プロジェクト: bhearsum/scriptworker-scripts
async def l10n_bump(config, task, repo_path, repo_type="hg"):
    """Perform a l10n revision bump.

    This function takes its inputs from task by using the ``get_l10n_bump_info``
    function from treescript.task. It then calculates the locales, the platforms
    for each locale, and the locale revision for each locale.

    Args:
        config (dict): the running config
        task (dict): the running task
        repo_path (str): the source directory
        repo_type (str): the repository type

    Raises:
        TaskVerificationError: if a file specified is not allowed, or
                               if the file is not in the target repository.

    Returns:
        int: non-zero if there are any changes.

    """
    vcs = get_vcs_module(repo_type)

    log.info("Preparing to bump l10n changesets.")

    ignore_closed_tree = get_ignore_closed_tree(task)
    if not ignore_closed_tree:
        if not await check_treestatus(config, task):
            log.info("Treestatus is closed; skipping l10n bump.")
            return 0

    dontbuild = get_dontbuild(task)
    l10n_bump_info = get_l10n_bump_info(task)
    changes = 0

    for bump_config in l10n_bump_info:
        path = os.path.join(repo_path, bump_config["path"])
        old_contents = load_json_or_yaml(path, is_path=True)
        new_contents = await build_revision_dict(bump_config, repo_path,
                                                 deepcopy(old_contents))
        if old_contents == new_contents:
            continue
        with open(path, "w") as fh:
            fh.write(
                json.dumps(new_contents,
                           sort_keys=True,
                           indent=4,
                           separators=(",", ": ")))
        locale_map = build_locale_map(old_contents, new_contents)
        message = build_commit_message(bump_config["name"],
                                       locale_map,
                                       dontbuild=dontbuild,
                                       ignore_closed_tree=ignore_closed_tree)
        await vcs.commit(config, repo_path, message)
        changes += 1
    return changes
コード例 #4
0
def test_missing_l10n_bump_info(task_defn):
    with pytest.raises(TaskVerificationError):
        ttask.get_l10n_bump_info(task_defn)
コード例 #5
0
def test_get_l10n_bump_info(task_defn, l10n_bump_info):
    task_defn["payload"]["l10n_bump_info"] = l10n_bump_info
    tested_info = ttask.get_l10n_bump_info(task_defn)
    assert tested_info == l10n_bump_info