class License(object):
    """Represents a license."""
    def __init__(self, license):
        self.name = license.attrib["id"]
        self.text = license.text
        self.cfg = DockerConfig()

    def accept(self):
        agree = "\n\n".join([self.text, "Do you accept the license?"])
        if not self.is_accepted():
            if not click.confirm(agree):
                raise Exception("License not accepted.")
            self.cfg.accept_license(self.name)

        return True

    def is_accepted(self):
        return self.cfg.accepted_license(self.name)

    def force_accept(self):
        self.cfg.accept_license(self.name)

    def __str__(self):
        # encode to utf-8 for python 2
        return str(self.text.encode("utf-8"))

    def __hash__(self):
        return hash(self.name)

    def __eq__(self, other):
        return self.__class__ == other.__class__ and self.name == other.name
Пример #2
0
def create_docker_image(args):
    """Create a directory containing all the necessary ingredients to construct a docker image.

    Returns the created DockerDevice objects.
    """

    cfg = DockerConfig()
    if args.metrics:
        cfg.set_collect_metrics(True)
    if args.no_metrics:
        cfg.set_collect_metrics(False)

    if not cfg.decided_on_metrics():
        logging.warning(
            "Please opt in or out of metrics collection.\n"
            "You will receive this warning until an option is selected.\n"
            "To opt in or out pass the --metrics or --no-metrics flag\n"
            "Note, that metrics will only be collected if you opt in.")

    imgzip = [args.imgzip]
    if not os.path.exists(imgzip[0]):
        imgzip = [
            x.download() for x in emu_downloads_menu.find_image(imgzip[0])
        ]

    emuzip = [args.emuzip]
    if emuzip[0] in ["stable", "canary", "all"]:
        emuzip = [
            x.download() for x in emu_downloads_menu.find_emulator(emuzip[0])
        ]
    elif re.match("\d+", emuzip[0]):
        # We must be looking for a build id
        logging.info("Treating %s as a build id", emuzip[0])
        emuzip = [emu_downloads_menu.download_build(emuzip[0])]

    devices = []
    for (img, emu) in itertools.product(imgzip, emuzip):
        logging.info("Processing %s, %s", img, emu)
        rel = emu_downloads_menu.AndroidReleaseZip(img)
        if not rel.is_system_image():
            raise Exception(
                "{} is not a zip file with a system image".format(img))
        rel = emu_downloads_menu.AndroidReleaseZip(emu)
        if not rel.is_emulator():
            raise Exception(
                "{} is not a zip file with an emulator".format(emu))

        device = DockerDevice(emu, img, args.dest, args.gpu, args.repo,
                              args.tag)
        device.create_docker_file(args.extra, cfg.collect_metrics())
        img = device.create_container()
        if img and args.start:
            device.launch(img)
        if args.push:
            device.push(img)
        devices.append(device)

    return devices
Пример #3
0
def create_docker_image_interactive(args):
    """Interactively create a docker image by selecting the desired combination from a menu."""
    img = emu_downloads_menu.select_image(args.arm) or sys.exit(1)
    emulator = emu_downloads_menu.select_emulator() or sys.exit(1)
    cfg = DockerConfig()
    metrics = False

    if not cfg.decided_on_metrics():
        cfg.set_collect_metrics(
            click.confirm(
                "Would you like to help make the emulator better by sending usage statistics to Google upon (graceful) emulator exit?"
            ))
    metrics = cfg.collect_metrics()

    emu_zip = emulator.download("linux")
    logging.info("Processing %s, %s", img, emu)
    sys_docker = SystemImageContainer(img, args.repo)
    if not sys_docker.available() and not sys_docker.can_pull():
        sys_docker.build(args.dest)

    emu_docker = EmulatorContainer(emu_zip, sys_docker, args.repo, metrics)
    emu_docker.build(args.dest)

    if args.start:
        emu_docker.launch({"5555/tcp": 5555, "8554/tcp": 8554})
Пример #4
0
def metrics_config(args):
    cfg = DockerConfig()
    if args.metrics:
        cfg.set_collect_metrics(True)
    if args.no_metrics:
        cfg.set_collect_metrics(False)

    if not cfg.decided_on_metrics():
        logging.warning(
            "Please opt in or out of metrics collection.\n"
            "You will receive this warning until an option is selected.\n"
            "To opt in or out pass the --metrics or --no-metrics flag\n"
            "Note, that metrics will only be collected if you opt in.")
    return cfg
def create_docker_image_interactive(args):
    """Interactively create a docker image by selecting the desired combination from a menu."""
    img = emu_downloads_menu.select_image(args.arm) or sys.exit(1)
    emulator = emu_downloads_menu.select_emulator() or sys.exit(1)
    cfg = DockerConfig()
    metrics = False

    if not cfg.decided_on_metrics():
        cfg.set_collect_metrics(
            click.confirm(
                "Would you like to help make the emulator better by sending usage statistics to Google upon (graceful) emulator exit?"
            ))
    metrics = cfg.collect_metrics()

    img_zip = img.download()
    emu_zip = emulator.download("linux")
    device = DockerDevice(emu_zip, img_zip, args.dest, args.gpu)
    device.create_docker_file(args.extra, metrics)
    img = device.create_container()
    if img and args.start:
        device.launch(img)
 def __init__(self, license):
     self.name = license.attrib["id"]
     self.text = license.text
     self.cfg = DockerConfig()