コード例 #1
0
    def prepare(self, scenario, customization):
        self.scenario = scenario
        self.customization = customization

        # early checks to avoid extra work
        if self.customization != "all":
            if find_customization(self.customization) is None:
                raise IOError("Cannot find customization %r" %
                              self.customization)

        if self.scenario != "all" and self.scenario not in scenarii:
            raise IOError("Cannot find scenario %r" % self.scenario)

        if not self.android and self.firefox is not None:
            logger.info("Verifying Desktop Firefox binary")
            # we want to verify we do have a firefox binary
            # XXX so lame
            if not os.path.exists(self.firefox):
                if "MOZ_FETCHES_DIR" in os.environ:
                    target = os.path.join(os.environ["MOZ_FETCHES_DIR"],
                                          self.firefox)
                    if os.path.exists(target):
                        self.firefox = target

            if not os.path.exists(self.firefox):
                raise IOError("Cannot find %s" % self.firefox)

            version = get_version(self.firefox)
            logger.info("Working with Firefox %s" % version)

        logger.info(os.environ)
        if self.archive:
            self.archive = os.path.abspath(self.archive)
            logger.info("Archives directory is %s" % self.archive)
            if not os.path.exists(self.archive):
                os.makedirs(self.archive, exist_ok=True)

        logger.info("Verifying Geckodriver binary presence")
        if shutil.which(self.geckodriver) is None and not os.path.exists(
                self.geckodriver):
            raise IOError("Cannot find %s" % self.geckodriver)

        if not self.skip_logs:
            try:
                if self.android:
                    plat = "%s-%s" % (
                        self.device_name,
                        self.firefox.split("org.mozilla.")[-1],
                    )
                else:
                    plat = get_current_platform()
                self.changelog = read_changelog(plat)
                logger.info("Got the changelog from TaskCluster")
            except ProfileNotFoundError:
                logger.info(
                    "changelog not found on TaskCluster, creating a local one."
                )
                self.changelog = Changelog(self.archive)
        else:
            self.changelog = []
コード例 #2
0
ファイル: client.py プロジェクト: Floflis/gecko-b2g
 def _get_changelog():
     try:
         download_file(changelog_url, target=downloaded_changelog)
     except ArchiveNotFound:
         shutil.rmtree(download_dir)
         raise ProfileNotFoundError(changelog_url)
     return Changelog(download_dir)
コード例 #3
0
def read_changelog(platform):
    params = {"platform": platform}
    changelog_url = CHANGELOG_LINK % params
    get_logger().msg("Getting %s" % changelog_url)
    exists, __ = check_exists(changelog_url)
    if exists != 200:
        raise ProfileNotFoundError(exists)
    download_dir = tempfile.mkdtemp()
    downloaded_changelog = os.path.join(download_dir, "changelog.json")
    download_file(changelog_url, target=downloaded_changelog)
    return Changelog(download_dir)
コード例 #4
0
ファイル: client.py プロジェクト: tsl143/browser-f
def read_changelog(platform, repo="mozilla-central"):
    params = {"platform": platform, "repo": repo}
    changelog_url = CHANGELOG_LINK % params
    logger.info("Getting %s" % changelog_url)
    download_dir = tempfile.mkdtemp()
    downloaded_changelog = os.path.join(download_dir, "changelog.json")
    try:
        download_file(changelog_url, target=downloaded_changelog)
    except ArchiveNotFound:
        shutil.rmtree(download_dir)
        raise ProfileNotFoundError(changelog_url)
    return Changelog(download_dir)
コード例 #5
0
ファイル: client.py プロジェクト: erikrose/gecko-dev
def read_changelog(platform):
    params = {"platform": platform}
    changelog_url = CHANGELOG_LINK % params
    get_logger().msg("Getting %s" % changelog_url)
    download_dir = tempfile.mkdtemp()
    downloaded_changelog = os.path.join(download_dir, "changelog.json")
    try:
        download_file(changelog_url, target=downloaded_changelog)
    except ArchiveNotFound:
        shutil.rmtree(download_dir)
        raise ProfileNotFoundError(changelog_url)
    return Changelog(download_dir)
コード例 #6
0
ファイル: runner.py プロジェクト: SimonAayani/gecko-dev
def main(args=sys.argv[1:]):
    parser = argparse.ArgumentParser(description="Profile Creator")
    parser.add_argument("archive", help="Archives Dir", type=str, default=None)
    parser.add_argument("--firefox",
                        help="Firefox Binary",
                        type=str,
                        default=None)
    parser.add_argument("--scenario",
                        help="Scenario to use",
                        type=str,
                        default="all")
    parser.add_argument("--profile",
                        help="Existing profile Dir",
                        type=str,
                        default=None)
    parser.add_argument("--customization",
                        help="Profile customization to use",
                        type=str,
                        default="all")
    parser.add_argument(
        "--fresh-profile",
        help="Create a fresh profile",
        action="store_true",
        default=False,
    )
    parser.add_argument("--visible",
                        help="Don't use headless mode",
                        action="store_true",
                        default=False)
    parser.add_argument("--archives-dir",
                        help="Archives local dir",
                        type=str,
                        default="/tmp/archives")
    parser.add_argument("--force-new",
                        help="Create from scratch",
                        action="store_true",
                        default=False)
    parser.add_argument(
        "--strict",
        help="Errors out immediatly on a scenario failure",
        action="store_true",
        default=True,
    )
    parser.add_argument(
        "--geckodriver",
        help="Path to the geckodriver binary",
        type=str,
        default=sys.platform.startswith("win") and "geckodriver.exe"
        or "geckodriver",
    )

    parser.add_argument("--device-name",
                        help="Name of the device",
                        type=str,
                        default=None)

    args = parser.parse_args(args=args)

    # unpacking a dmg
    # XXX do something similar if we get an apk (but later)
    # XXX we want to do
    #   adb install -r target.apk
    #   and get the installed app name
    if args.firefox is not None and args.firefox.endswith("dmg"):
        target = os.path.join(os.path.dirname(args.firefox), "firefox.app")
        extract_from_dmg(args.firefox, target)
        args.firefox = os.path.join(target, "Contents", "MacOS", "firefox")

    args.android = args.firefox is not None and args.firefox.startswith(
        "org.mozilla")

    if not args.android and args.firefox is not None:
        LOG("Verifying Desktop Firefox binary")
        # we want to verify we do have a firefox binary
        # XXX so lame
        if not os.path.exists(args.firefox):
            if "MOZ_FETCHES_DIR" in os.environ:
                target = os.path.join(os.environ["MOZ_FETCHES_DIR"],
                                      args.firefox)
                if os.path.exists(target):
                    args.firefox = target

        if not os.path.exists(args.firefox):
            raise IOError("Cannot find %s" % args.firefox)

        version = get_version(args.firefox)
        LOG("Working with Firefox %s" % version)

    LOG(os.environ)
    args.archive = os.path.abspath(args.archive)
    LOG("Archives directory is %s" % args.archive)
    if not os.path.exists(args.archive):
        os.makedirs(args.archive, exist_ok=True)

    LOG("Verifying Geckodriver binary presence")
    if shutil.which(args.geckodriver) is None and not os.path.exists(
            args.geckodriver):
        raise IOError("Cannot find %s" % args.geckodriver)

    try:
        plat = args.android and "android" or get_current_platform()
        changelog = read_changelog(plat)
        LOG("Got the changelog from TaskCluster")
    except ProfileNotFoundError:
        LOG("changelog not found on TaskCluster, creating a local one.")
        changelog = Changelog(args.archive)
    loop = asyncio.get_event_loop()

    async def one_run(scenario, customization):
        if args.android:
            env = AndroidEnv(
                args.profile,
                args.firefox,
                args.geckodriver,
                args.archive,
                args.device_name,
            )
        else:
            env = DesktopEnv(
                args.profile,
                args.firefox,
                args.geckodriver,
                args.archive,
                args.device_name,
            )
        return await ProfileCreator(scenario, customization, args.archive,
                                    changelog, args.force_new,
                                    env).run(not args.visible)

    async def run_all(args):
        if args.scenario != "all":
            return await one_run(args.scenario, args.customization)

        # this is the loop that generates all combinations of profile
        # for the current platform when "all" is selected
        res = []
        for scenario in scenarii.keys():
            if args.customization != "all":
                try:
                    res.append(await one_run(scenario, args.customization))
                except Exception:
                    ERROR("Something went wrong on this one.")
                    if args.strict:
                        raise
            else:
                for customization in get_customizations():
                    try:
                        res.append(await one_run(scenario, customization))
                    except Exception:
                        ERROR("Something went wrong on this one.")
                        if args.strict:
                            raise
        return res

    try:
        loop.run_until_complete(run_all(args))
        LOG("Saving changelog in %s" % args.archive)
        changelog.save(args.archive)
    finally:
        loop.close()
コード例 #7
0
class Runner:
    def __init__(
        self,
        profile,
        firefox,
        geckodriver,
        archive,
        device_name,
        strict,
        force_new,
        visible,
    ):
        self.force_new = force_new
        self.profile = profile
        self.geckodriver = geckodriver
        self.archive = archive
        self.device_name = device_name
        self.strict = strict
        self.visible = visible
        # unpacking a dmg
        # XXX do something similar if we get an apk (but later)
        # XXX we want to do
        #   adb install -r target.apk
        #   and get the installed app name
        if firefox is not None and firefox.endswith("dmg"):
            target = os.path.join(os.path.dirname(firefox), "firefox.app")
            extract_from_dmg(firefox, target)
            firefox = os.path.join(target, "Contents", "MacOS", "firefox")
        self.firefox = firefox
        self.android = self.firefox is not None and self.firefox.startswith(
            "org.mozilla")

    def prepare(self, scenario, customization):
        self.scenario = scenario
        self.customization = customization

        # early checks to avoid extra work
        if self.customization != "all":
            if find_customization(self.customization) is None:
                raise IOError("Cannot find customization %r" %
                              self.customization)

        if self.scenario != "all" and self.scenario not in scenarii:
            raise IOError("Cannot find scenario %r" % self.scenario)

        if not self.android and self.firefox is not None:
            logger.info("Verifying Desktop Firefox binary")
            # we want to verify we do have a firefox binary
            # XXX so lame
            if not os.path.exists(self.firefox):
                if "MOZ_FETCHES_DIR" in os.environ:
                    target = os.path.join(os.environ["MOZ_FETCHES_DIR"],
                                          self.firefox)
                    if os.path.exists(target):
                        self.firefox = target

            if not os.path.exists(self.firefox):
                raise IOError("Cannot find %s" % self.firefox)

            version = get_version(self.firefox)
            logger.info("Working with Firefox %s" % version)

        logger.info(os.environ)
        self.archive = os.path.abspath(self.archive)
        logger.info("Archives directory is %s" % self.archive)
        if not os.path.exists(self.archive):
            os.makedirs(self.archive, exist_ok=True)

        logger.info("Verifying Geckodriver binary presence")
        if shutil.which(self.geckodriver) is None and not os.path.exists(
                self.geckodriver):
            raise IOError("Cannot find %s" % self.geckodriver)

        try:
            if self.android:
                plat = "%s-%s" % (
                    self.device_name,
                    self.firefox.split("org.mozilla.")[-1],
                )
            else:
                plat = get_current_platform()
            self.changelog = read_changelog(plat)
            logger.info("Got the changelog from TaskCluster")
        except ProfileNotFoundError:
            logger.info(
                "changelog not found on TaskCluster, creating a local one.")
            self.changelog = Changelog(self.archive)

    def _create_env(self):
        if self.android:
            klass = AndroidEnv
        else:
            klass = DesktopEnv

        return klass(self.profile, self.firefox, self.geckodriver,
                     self.archive, self.device_name)

    def display_error(self, scenario, customization):
        logger.error("%s x %s failed." % (scenario, customization),
                     exc_info=True)
        if self.strict:
            raise

    async def one_run(self, scenario, customization):
        """Runs one single conditioned profile.

        Create an instance of the environment and run the ProfileCreator.
        """
        env = self._create_env()
        return await ProfileCreator(scenario, customization, self.archive,
                                    self.changelog, self.force_new,
                                    env).run(not self.visible)

    async def run_all(self):
        """Runs the conditioned profile builders"""
        if self.scenario != "all":
            selected_scenario = [self.scenario]
        else:
            selected_scenario = scenarii.keys()

        # this is the loop that generates all combinations of profile
        # for the current platform when "all" is selected
        res = []
        failures = 0
        for scenario in selected_scenario:
            if self.customization != "all":
                try:
                    res.append(await self.one_run(scenario,
                                                  self.customization))
                except Exception:
                    failures += 1
                    self.display_error(scenario, self.customization)
            else:
                for customization in get_customizations():
                    logger.info("Customization %s" % customization)
                    try:
                        res.append(await self.one_run(scenario, customization))
                    except Exception:
                        failures += 1
                        self.display_error(scenario, customization)

        return failures, [one_res for one_res in res if one_res]

    def save(self):
        self.changelog.save(self.archive)