]> glassweightruler.freedombox.rocks Git - waydroid.git/blobdiff - tools/actions/initializer.py
tools: Remove unused requests import
[waydroid.git] / tools / actions / initializer.py
index c5783a459a125c9cb3f68c0d7c3dd7ccda846573..62878105f45aef5b72b941ef7af74c7d9b6c7d63 100644 (file)
@@ -2,7 +2,6 @@
 # SPDX-License-Identifier: GPL-3.0-or-later
 import logging
 import os
-import requests
 from tools import helpers
 import tools.config
 
@@ -21,6 +20,16 @@ def setup_config(args):
     cfg = tools.config.load(args)
     args.arch = helpers.arch.host()
     cfg["waydroid"]["arch"] = args.arch
+
+    preinstalled_images = tools.config.defaults["preinstalled_images_path"]
+    if not args.images_path:
+        if os.path.isdir(preinstalled_images):
+            if os.path.isfile(preinstalled_images + "/system.img") and os.path.isfile(preinstalled_images + "/vendor.img"):
+                args.images_path = preinstalled_images
+            else:
+                logging.error("Missing system or vendor on preinstalled images dir, fallback to default")
+    if not args.images_path:
+        args.images_path = tools.config.defaults["images_path"]
     cfg["waydroid"]["images_path"] = args.images_path
 
     channels_cfg = tools.config.load_channels()
@@ -35,25 +44,32 @@ def setup_config(args):
 
     args.system_ota = args.system_channel + "/" + args.rom_type + \
         "/waydroid_" + args.arch + "/" + args.system_type + ".json"
-    system_request = requests.get(args.system_ota)
-    if system_request.status_code != 200:
-        raise ValueError(
-            "Failed to get system OTA channel: {}".format(args.system_ota))
+    system_request = helpers.http.retrieve(args.system_ota)
+    if system_request[0] != 200:
+        if args.images_path != preinstalled_images:
+            raise ValueError(
+                "Failed to get system OTA channel: {}, error: {}".format(args.system_ota, system_request[0]))
+        else:
+            args.system_ota = "None"
 
     device_codename = helpers.props.host_get(args, "ro.product.device")
     args.vendor_type = None
     for vendor in [device_codename, get_vendor_type(args)]:
         vendor_ota = args.vendor_channel + "/waydroid_" + \
             args.arch + "/" + vendor + ".json"
-        vendor_request = requests.get(vendor_ota)
-        if vendor_request.status_code == 200:
+        vendor_request = helpers.http.retrieve(vendor_ota)
+        if vendor_request[0] == 200:
             args.vendor_type = vendor
             args.vendor_ota = vendor_ota
             break
 
     if not args.vendor_type:
-        raise ValueError(
-            "Failed to get vendor OTA channel: {}".format(vendor_ota))
+        if args.images_path != preinstalled_images:
+            raise ValueError(
+                "Failed to get vendor OTA channel: {}".format(vendor_ota))
+        else:
+            args.vendor_ota = "None"
+            args.vendor_type = get_vendor_type(args)
 
     cfg["waydroid"]["vendor_type"] = args.vendor_type
     cfg["waydroid"]["system_ota"] = args.system_ota
@@ -74,7 +90,8 @@ def init(args):
             logging.info("Stopping container")
             helpers.lxc.stop(args)
         helpers.images.umount_rootfs(args)
-        helpers.images.get(args)
+        if args.images_path != tools.config.defaults["preinstalled_images_path"]:
+            helpers.images.get(args)
         if not os.path.isdir(tools.config.defaults["rootfs"]):
             os.mkdir(tools.config.defaults["rootfs"])
         helpers.lxc.setup_host_perms(args)