From 8d11e5b87eb2a4081896dc33cded1ef217dc44a7 Mon Sep 17 00:00:00 2001 From: Greger Stolt Nilsen Date: Mon, 11 Oct 2021 18:41:26 +0200 Subject: [PATCH 1/2] Add override of download location. Add ability to override download location by setting environment variable ANDROID_REPOSITORY. --- emu/emu_downloads_menu.py | 19 +++++++++++-------- emu/platform_tools.py | 4 +++- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/emu/emu_downloads_menu.py b/emu/emu_downloads_menu.py index 283645c6..8892c54b 100644 --- a/emu/emu_downloads_menu.py +++ b/emu/emu_downloads_menu.py @@ -27,15 +27,17 @@ 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/google_atd/sys-img2-1.xml", - "https://dl.google.com/android/repository/sys-img/android-tv/sys-img2-1.xml", + "%s/android/repository/sys-img/android/sys-img2-1.xml" % ANDROID_REPOSITORY, + "%s/android/repository/sys-img/google_apis/sys-img2-1.xml" % ANDROID_REPOSITORY, + "%s/android/repository/sys-img/google_apis_playstore/sys-img2-1.xml" % ANDROID_REPOSITORY, + "%s/android/repository/sys-img/google_atd/sys-img2-1.xml" % ANDROID_REPOSITORY, + "%s/android/repository/sys-img/android-tv/sys-img2-1.xml" % ANDROID_REPOSITORY, ] -EMU_REPOS = ["https://dl.google.com/android/repository/repository2-1.xml"] +EMU_REPOS = ["%s/android/repository/repository2-1.xml" % ANDROID_REPOSITORY] CHANNEL_MAPPING = { "channel-0": "stable", @@ -161,7 +163,8 @@ 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.url = "%s/android/repository/sys-img/%s/%s" % ( + ANDROID_REPOSITORY, self.tag, self.zip, ) @@ -214,7 +217,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] = "%s/android/repository/%s" % (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 f1dafdf2..a29b65a2 100644 --- a/emu/platform_tools.py +++ b/emu/platform_tools.py @@ -11,18 +11,20 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import os import zipfile from pathlib import Path from emu.utils import download +ANDROID_REPOSITORY = os.environ.get("ANDROID_REPOSITORY", "https://dl.google.com") class PlatformTools(object): """The platform tools zip file. It will be downloaded on demand.""" # Platform tools, needed to get adb. PLATFORM_TOOLS_URL = ( - "https://dl.google.com/android/repository/platform-tools_r29.0.5-linux.zip" + '%s/android/repository/platform-tools_r29.0.5-linux.zip' % ANDROID_REPOSITORY ) PLATFORM_TOOLS_ZIP = "platform-tools-latest-linux.zip" From 2216fc1b976df01358196a0ee3e36b66749417ec Mon Sep 17 00:00:00 2001 From: Greger Stolt Nilsen Date: Thu, 4 Nov 2021 14:28:40 +0100 Subject: [PATCH 2/2] Add option to manually name image. --- emu/containers/emulator_container.py | 6 +++++- emu/emu_docker.py | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/emu/containers/emulator_container.py b/emu/containers/emulator_container.py index 01980c7c..2ff3dd8d 100644 --- a/emu/containers/emulator_container.py +++ b/emu/containers/emulator_container.py @@ -31,11 +31,12 @@ 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="" + 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([f'"{s}"' for s in extra]) @@ -100,6 +101,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"], diff --git a/emu/emu_docker.py b/emu/emu_docker.py index ce144b89..a6e4e607 100644 --- a/emu/emu_docker.py +++ b/emu/emu_docker.py @@ -103,7 +103,7 @@ def create_docker_image(args): continue emu_docker = EmulatorContainer( - emulator, sys_docker, args.repo, cfg.collect_metrics(), args.extra + emulator, sys_docker, args.repo, cfg.collect_metrics(), args.extra, args.name ) emu_docker.build(Path(args.dest) / "emulator") @@ -255,6 +255,9 @@ def main(): 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(