diff --git a/emu/containers/emulator_container.py b/emu/containers/emulator_container.py index 22beb31c..f95aebbb 100644 --- a/emu/containers/emulator_container.py +++ b/emu/containers/emulator_container.py @@ -30,10 +30,11 @@ class EmulatorContainer(DockerContainer): """ NO_METRICS_MESSAGE = "No metrics are collected when running this container." - def __init__(self, emulator, system_image_container, repository=None, metrics=False, extra=""): + def __init__(self, emulator, system_image_container, repository=None, metrics=False, extra="", name=None): self.emulator_zip = AndroidReleaseZip(emulator) self.system_image_container = system_image_container self.metrics = metrics + self.name = name if type(extra) is list: extra = " ".join(extra) @@ -96,6 +97,9 @@ def write(self, dest): self.emulator_zip.extract(os.path.join(dest, "emu")) def image_name(self): + if self.name: + return self.name + name = "{}-{}-{}".format( self.props["ro.build.version.sdk"], self.props["qemu.short_tag"], self.props["qemu.short_abi"] ) diff --git a/emu/emu_docker.py b/emu/emu_docker.py index 633e2284..27a1a460 100644 --- a/emu/emu_docker.py +++ b/emu/emu_docker.py @@ -74,7 +74,8 @@ def create_docker_image(args): emuzip = [args.emuzip] if emuzip[0] in ["stable", "canary", "all"]: - emuzip = [x.download() for x in emu_downloads_menu.find_emulator(emuzip[0])] + emuzip = [x.download() + for x in emu_downloads_menu.find_emulator(emuzip[0])] elif re.match(r"\d+", emuzip[0]): # We must be looking for a build id logging.info("Treating %s as a build id", emuzip[0]) @@ -95,7 +96,8 @@ def create_docker_image(args): if args.sys: continue - emu_docker = EmulatorContainer(emu, sys_docker, args.repo, cfg.collect_metrics(), args.extra) + emu_docker = EmulatorContainer( + emu, sys_docker, args.repo, cfg.collect_metrics(), args.extra, args.name) emu_docker.build(args.dest) if args.start: @@ -140,10 +142,12 @@ def main(): """Entry point that parses the argument, and invokes the proper functions.""" parser = argparse.ArgumentParser( - description="List and create emulator docker containers ({}).".format(emu.__version__), + description="List and create emulator docker containers ({}).".format( + emu.__version__), formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) - parser.add_argument("-v", "--verbose", dest="verbose", action="store_true", help="Set verbose logging") + parser.add_argument("-v", "--verbose", dest="verbose", + action="store_true", help="Set verbose logging") subparsers = parser.add_subparsers() @@ -161,7 +165,8 @@ def main(): license_parser = subparsers.add_parser( "licenses", help="Lists all licenses and gives you a chance to accept or reject them." ) - license_parser.add_argument("--accept", action="store_true", help="Accept all licensens after displaying them.") + license_parser.add_argument( + "--accept", action="store_true", help="Accept all licensens after displaying them.") license_parser.set_defaults(func=accept_licenses) create_parser = subparsers.add_parser( @@ -192,7 +197,8 @@ def main(): create_parser.add_argument( "--dest", default=os.path.join(os.getcwd(), "src"), help="Destination for the generated docker files" ) - create_parser.add_argument("--tag", default="", help="Docker tag, defaults to the emulator build id") + create_parser.add_argument( + "--tag", default="", help="Docker tag, defaults to the emulator build id") create_parser.add_argument( "--repo", default="us-docker.pkg.dev/android-emulator-268719/images", @@ -212,14 +218,18 @@ def main(): action="store_true", help="When enabled, the emulator will send usage metrics to Google when the container exists gracefully.", ) - create_parser.add_argument("--no-metrics", action="store_true", help="Disables the collection of usage metrics.") + create_parser.add_argument( + "--no-metrics", action="store_true", help="Disables the collection of usage metrics.") create_parser.add_argument( "--start", action="store_true", help="Starts the container after creating it. " "All exposed ports are forwarded, and your private adbkey (if available) is injected but not stored.", ) - create_parser.add_argument("--sys", action="store_true", help="Process system image layer only.") + create_parser.add_argument( + "--sys", action="store_true", help="Process system image layer only.") + create_parser.add_argument( + "--name", help="Name to give image when pushed.", default=None) create_parser.set_defaults(func=create_docker_image) create_inter = subparsers.add_parser( @@ -269,7 +279,8 @@ def main(): dist_parser.add_argument( "--dest", default=os.path.join(os.getcwd(), "src"), help="Destination for the generated docker files" ) - dist_parser.add_argument("--git", action="store_true", help="Create a git commit, and push to destination.") + dist_parser.add_argument("--git", action="store_true", + help="Create a git commit, and push to destination.") dist_parser.add_argument( "--sys", action="store_true", help="Write system image steps, otherwise write emulator steps." ) @@ -291,7 +302,8 @@ def main(): # Configure logger. lvl = logging.DEBUG if args.verbose else logging.WARNING handler = colorlog.StreamHandler() - handler.setFormatter(colorlog.ColoredFormatter("%(log_color)s%(levelname)s:%(message)s")) + handler.setFormatter(colorlog.ColoredFormatter( + "%(log_color)s%(levelname)s:%(message)s")) logging.root = colorlog.getLogger("root") logging.root.addHandler(handler) logging.root.setLevel(lvl) diff --git a/emu/emu_downloads_menu.py b/emu/emu_downloads_menu.py index 70063fd1..2e53de4f 100644 --- a/emu/emu_downloads_menu.py +++ b/emu/emu_downloads_menu.py @@ -27,14 +27,16 @@ from emu.utils import download from emu.docker_config import DockerConfig +ANDROID_REPOSITORY = os.environ.get("ANDROID_REPOSITORY", "https://dl.google.com/") + SYSIMG_REPOS = [ - "https://dl.google.com/android/repository/sys-img/android/sys-img2-1.xml", - "https://dl.google.com/android/repository/sys-img/google_apis/sys-img2-1.xml", - "https://dl.google.com/android/repository/sys-img/google_apis_playstore/sys-img2-1.xml", - "https://dl.google.com/android/repository/sys-img/android-tv/sys-img2-1.xml", + f"{ANDROID_REPOSITORY}/android/repository/sys-img/android/sys-img2-1.xml", + f"{ANDROID_REPOSITORY}/android/repository/sys-img/google_apis/sys-img2-1.xml", + f"{ANDROID_REPOSITORY}/android/repository/sys-img/google_apis_playstore/sys-img2-1.xml", + f"{ANDROID_REPOSITORY}/android/repository/sys-img/android-tv/sys-img2-1.xml", ] -EMU_REPOS = ["https://dl.google.com/android/repository/repository2-1.xml"] +EMU_REPOS = [f"{ANDROID_REPOSITORY}/android/repository/repository2-1.xml"] CHANNEL_MAPPING = {"channel-0": "stable", "channel-1": "beta", "channel-2": "dev", "channel-3": "canary"} @@ -147,7 +149,7 @@ def __init__(self, pkg, licenses): url_element = pkg.find(".//url") self.zip = url_element.text - self.url = "https://dl.google.com/android/repository/sys-img/%s/%s" % (self.tag, self.zip) + self.url = f"{ANDROID_REPOSITORY}/android/repository/sys-img/{self.tag}/{self.zip}" def short_tag(self): return self.SHORT_TAG[self.tag] @@ -192,7 +194,7 @@ def __init__(self, pkg, licenses): for archive in archives: url = archive.find(".//url").text hostos = archive.find("host-os").text - self.urls[hostos] = "https://dl.google.com/android/repository/%s" % url + self.urls[hostos] = f"{ANDROID_REPOSITORY}/android/repository/{url}" def download_name(self): return "emulator-{}.zip".format(self.version) diff --git a/emu/platform_tools.py b/emu/platform_tools.py index 4bd3a396..5a86f64e 100644 --- a/emu/platform_tools.py +++ b/emu/platform_tools.py @@ -17,7 +17,7 @@ from emu.utils import download # Platform tools, needed to get adb. -PLATFORM_TOOLS_URL = "https://dl.google.com/android/repository/platform-tools_r29.0.5-linux.zip" +PLATFORM_TOOLS_URL = f'{os.environ.get("ANDROID_REPOSITORY", "https://dl.google.com")}/android/repository/platform-tools_r29.0.5-linux.zip' class PlatformTools(object):