Пример #1
0
async def test_semaphore_wrapper():
    """``semaphore_wrapper`` limits concurrency through the passed ``Semaphore``."""
    sem = asyncio.Semaphore(2)
    futures = [
        asyncio.ensure_future(
            aio.semaphore_wrapper(sem, async_time(sleep_time=0.1))),
        asyncio.ensure_future(
            aio.semaphore_wrapper(sem, async_time(sleep_time=0.1))),
        asyncio.ensure_future(
            aio.semaphore_wrapper(sem, async_time(sleep_time=0.1))),
        asyncio.ensure_future(
            aio.semaphore_wrapper(sem, async_time(sleep_time=0.1))),
    ]
    with pytest.raises(TimeoutError):
        await aio.raise_future_exceptions(futures, timeout=0.15)
    results1 = []
    for fut in futures:
        try:
            if not fut.exception():
                results1.append(fut.result())
        except asyncio.InvalidStateError:
            pass
    assert len(results1) == 2  # only 2 futures had time to finish in .15s
    results2 = await aio.raise_future_exceptions(futures)
    assert len(results2) == 4
    assert results1 == results2[0:2]
Пример #2
0
async def build_revision_dict(bump_config, repo_path, old_contents):
    """Add l10n revision information to the ``platform_dict``.

    If we have an ``l10n_repo_url``, use that as a template for the locale
    repo url. If ``pin`` is set in the ``old_contents`` for that locale, save
    the previous revision and pin. Otherwise, find the latest revision in the
    locale repo, and use that.

    The ``l10n_repo_url`` will look something like
    https://hg.mozilla.org/l10n-central/%(locale)s/json-pushes?version=2&tipsonly=1

    Otherwise, add a ``default`` revision to each locale in the
    ``platform_dict``.

    Args:
        bump_config (dict): one of the dictionaries from the
            payload ``l10n_bump_info``
        repo_path (str): the path to the repo on disk
        old_contents (dict): the old contents of the l10n changesets, if any.

    Returns:
        dict: locale to dictionary of platforms and revision

    """
    log.info("Building revision dict...")
    platform_dict = build_platform_dict(bump_config, repo_path)
    revision_dict = {}
    if bump_config.get("l10n_repo_url"):
        semaphore = asyncio.Semaphore(5)
        tasks = []
        for locale, value in platform_dict.items():
            if old_contents.get(locale, {}).get("pin"):
                value["revision"] = old_contents[locale]["revision"]
                value["pin"] = old_contents[locale]["pin"]
            else:
                tasks.append(
                    asyncio.create_task(
                        semaphore_wrapper(
                            semaphore,
                            get_latest_revision(
                                locale, bump_config["l10n_repo_url"]))))
                value["pin"] = False
            revision_dict[locale] = value
        await asyncio.gather(*tasks)
        for task in tasks:
            (locale, revision) = task.result()
            revision_dict[locale]["revision"] = revision
    else:
        for k, v in platform_dict.items():
            v["revision"] = "default"
            revision_dict[k] = v
    log.info("revision_dict:\n%s" % pprint.pformat(revision_dict))
    return revision_dict
Пример #3
0
async def create_pkg_files(config, sign_config, all_paths):
    """Create .pkg installers from the .app files.

    Args:
        sign_config (dict): the running config for this key
        all_paths: (list): the list of App objects to pkg

    Raises:
        IScriptError: on failure

    """
    log.info("Creating PKG files")
    futures = []
    semaphore = asyncio.Semaphore(config.get("concurrency_limit", 2))
    for app in all_paths:
        # call set_app_path_and_name because we may not have called sign_app() earlier
        set_app_path_and_name(app)
        app.pkg_path = app.app_path.replace(".appex", ".pkg").replace(".app", ".pkg")
        app.pkg_name = os.path.basename(app.pkg_path)
        pkg_opts = []
        if sign_config.get("pkg_cert_id"):
            pkg_opts = ["--sign", sign_config["pkg_cert_id"]]
        futures.append(
            asyncio.ensure_future(
                semaphore_wrapper(
                    semaphore,
                    run_command(
                        [
                            "pkgbuild",
                            "--keychain",
                            sign_config["signing_keychain"],
                            "--install-location",
                            "/Applications",
                            "--component",
                            app.app_path,
                            app.pkg_path,
                        ]
                        + pkg_opts,
                        cwd=app.parent_dir,
                        exception=IScriptError,
                    ),
                )
            )
        )
    await raise_future_exceptions(futures)