Beispiel #1
0
    async def build_profile(self, device, headless):
        scenario = self.scenario
        profile = self.env.profile
        customization_data = self.customization_data

        scenario_func = scenarii[scenario]
        if scenario in customization_data.get("scenario", {}):
            options = customization_data["scenario"][scenario]
            LOG("Loaded options for that scenario %s" % str(options))
        else:
            options = {}

        # Adding general options
        options["platform"] = self.env.target_platform

        if not self.force_new:
            try:
                custom_name = customization_data["name"]
                get_profile(profile, self.env.target_platform, scenario, custom_name)
            except ProfileNotFoundError:
                # XXX we'll use a fresh profile for now
                fresh_profile(profile, customization_data)
        else:
            fresh_profile(profile, customization_data)

        LOG("Updating profile located at %r" % profile)
        metadata = Metadata(profile)

        LOG("Starting the Gecko app...")
        self.env.prepare(logfile=self._log_filename("adb"))
        geckodriver_logs = self._log_filename("geckodriver")
        LOG("Writing geckodriver logs in %s" % geckodriver_logs)
        try:
            firefox_instance = Firefox(**self.env.get_browser_args(headless))
            with open(geckodriver_logs, "w") as glog:
                async with get_session(
                    self.env.get_geckodriver(log_file=glog), firefox_instance
                ) as session:
                    self.env.check_session(session)
                    LOG("Running the %s scenario" % scenario)
                    metadata.update(await scenario_func(session, options))
                    LOG("%s scenario done." % scenario)

        except Exception:
            ERROR("%s scenario broke!" % scenario)

        self.env.stop_browser()
        self.env.collect_profile()

        # writing metadata
        metadata.write(
            name=self.scenario,
            customization=self.customization_data["name"],
            version=self.env.get_browser_version(),
            platform=self.env.target_platform,
        )

        LOG("Profile at %s" % profile)
        LOG("Done.")
        return metadata
Beispiel #2
0
async def build_profile(args):
    scenarii = scenario[args.scenarii]

    # getting the latest archive from the server
    if TASK_CLUSTER:
        url = TC_LINK % args.scenarii
        basename = 'today-%s.tgz' % args.scenarii
    else:
        basename = '%s-latest.tar.gz' % args.scenarii
        url = args.archives_server + '/%s' % basename

    exists, headers = check_exists(url)
    metadata = {}

    if exists:
        target = os.path.join(args.archives_dir, basename)
        archive = download_file(url, target=target, check_file=False)
        with tarfile.open(archive, "r:gz") as tar:
            logger.msg("Checking the tarball content...")
            size = len(list(tar))
            with progress.Bar(expected_size=size) as bar:
                def _extract(self, *args, **kw):
                    if not TASK_CLUSTER:
                        bar.show(bar.last_progress + 1)
                    try:
                        return self.old(*args, **kw)
                    finally:
                        pass
                        # if args[0].name == ".hp.json":
                        #   import pdb; pdb.set_trace()

                tar.old = tar.extract
                tar.extract = functools.partial(_extract, tar)
                tar.extractall(args.profile)

    logger.msg("Updating profile located at %r" % args.profile)

    f_args = ["-profile", args.profile]
    if platform.system() != 'Darwin':
        f_args.append('-headless')

    caps = {"moz:firefoxOptions": {"args": f_args}}
    if args.firefox is not None:
        caps['moz:firefoxOptions']['binary'] = args.firefox

    logger.msg("Starting the Fox...")
    with open('gecko.log', 'a+') as glog:
        async with get_session(CustomGeckodriver(log_file=glog),
                               Firefox(**caps)) as session:
            metadata = await scenarii(session, args)

    # writing metadata
    logger.msg("Creating metadata...")
    metadata['name'] = args.scenarii
    with open(os.path.join(args.profile, '.hp.json'), 'w') as f:
        f.write(json.dumps(metadata))

    logger.msg("Done.")
Beispiel #3
0
async def build_profile(args):
    scenarii = scenario[args.scenarii]
    if not args.force_new:
        get_profile(args)
    logger.msg("Updating profile located at %r" % args.profile)
    metadata_file = os.path.join(args.profile, ".hp.json")

    with open(metadata_file) as f:
        metadata = json.loads(f.read())

    f_args = ["-profile", args.profile]
    if platform.system() != "Darwin":
        f_args.append("-headless")

    caps = {"moz:firefoxOptions": {"args": f_args}}
    if args.firefox is not None:
        caps["moz:firefoxOptions"]["binary"] = args.firefox

    logger.msg("Starting the Fox...")
    with open("gecko.log", "a+") as glog:
        async with get_session(CustomGeckodriver(log_file=glog),
                               Firefox(**caps)) as session:
            logger.msg("Running the %s scenario" % args.scenarii)
            metadata.update(await scenarii(session, args))

    # writing metadata
    logger.msg("Creating metadata...")
    ts = str(datetime.datetime.now())
    if "created" not in metadata:
        metadata["created"] = ts
    metadata["updated"] = ts
    metadata["name"] = args.scenarii
    metadata["platform"] = sys.platform
    metadata["age"] = get_age(metadata)
    metadata["version"] = "69.0a1"  # add the build id XXX
    metadata["customization"] = "vanilla"  # add themes

    with open(metadata_file, "w") as f:
        f.write(json.dumps(metadata))

    logger.msg("Profile at %s" % args.profile)
    logger.msg("Done.")
Beispiel #4
0
    async def build_profile(self, device, headless):
        scenario = self.scenario
        profile = self.env.profile
        customization_data = self.customization_data

        scenario_func = scenarii[scenario]
        if scenario in customization_data.get("scenario", {}):
            options = customization_data["scenario"][scenario]
            logger.info("Loaded options for that scenario %s" % str(options))
        else:
            options = {}

        # Adding general options
        options["platform"] = self.env.target_platform

        if not self.force_new:
            try:
                custom_name = customization_data["name"]
                get_profile(profile, self.env.target_platform, scenario,
                            custom_name)
            except ProfileNotFoundError:
                # XXX we'll use a fresh profile for now
                fresh_profile(profile, customization_data)
        else:
            fresh_profile(profile, customization_data)

        logger.info("Updating profile located at %r" % profile)
        metadata = Metadata(profile)

        logger.info("Starting the Gecko app...")
        adb_logs = self._log_filename("adb")
        self.env.prepare(logfile=adb_logs)
        geckodriver_logs = self._log_filename("geckodriver")
        logger.info("Writing geckodriver logs in %s" % geckodriver_logs)
        step = START
        try:
            firefox_instance = Firefox(**self.env.get_browser_args(headless))
            step = INIT_GECKODRIVER
            with open(geckodriver_logs, "w") as glog:
                geckodriver = self.env.get_geckodriver(log_file=glog)
                step = START_SESSION
                async with get_session(geckodriver,
                                       firefox_instance) as session:
                    step = START_SCENARIO
                    self.env.check_session(session)
                    logger.info("Running the %s scenario" % scenario)
                    metadata.update(await scenario_func(session, options))
                    logger.info("%s scenario done." % scenario)
                    await close_extra_windows(session)
        except Exception:
            logger.error("%s scenario broke!" % scenario)
            if step == START:
                logger.info("Could not initialize the browser")
            elif step == INIT_GECKODRIVER:
                logger.info("Could not initialize Geckodriver")
            elif step == START_SESSION:
                logger.info("Could not start the session, check %s first" %
                            geckodriver_logs)
            else:
                logger.info(
                    "Could not run the scenario, probably a faulty scenario")
            raise
        finally:
            self.env.stop_browser()
            for logfile in (adb_logs, geckodriver_logs):
                if os.path.exists(logfile):
                    obfuscate_file(logfile)
        self.env.collect_profile()

        # writing metadata
        metadata.write(
            name=self.scenario,
            customization=self.customization_data["name"],
            version=self.env.get_browser_version(),
            platform=self.env.target_platform,
        )

        logger.info("Profile at %s.\nDone." % profile)
        return metadata