From e305dd1dc40471418e0ee221ce8f5e7b052e3bda Mon Sep 17 00:00:00 2001 From: Rikka Date: Mon, 10 Apr 2023 11:43:03 +0800 Subject: [PATCH] Write prop to /var/lib/waydroid/waydroid.cfg --- stuffs/general.py | 35 +++++++++++++++++------------------ tools/helper.py | 1 - 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/stuffs/general.py b/stuffs/general.py index d6df1a7..505f70c 100644 --- a/stuffs/general.py +++ b/stuffs/general.py @@ -1,3 +1,4 @@ +import configparser import glob import os import re @@ -60,27 +61,25 @@ class General: z.extractall(self.extract_to) def add_props(self): - with open(os.path.join("/var/lib/waydroid/waydroid_base.prop"), "r") as propfile: - prop_content = propfile.read() - for key in self.apply_props: - if key not in prop_content: - prop_content = prop_content+"\n{key}={value}".format(key=key, value=self.apply_props[key]) - else: - p = re.compile(r"^{key}=.*$".format(key=key), re.M) - prop_content = re.sub(p, "{key}={value}".format(key=key, value=self.apply_props[key]), prop_content) - with open(os.path.join("/var/lib/waydroid/waydroid_base.prop"), "w") as propfile: - propfile.write(prop_content) + cfg = configparser.ConfigParser() + cfg.read("/var/lib/waydroid/waydroid.cfg") + + for key in self.apply_props.keys(): + cfg.set('properties', key, self.apply_props[key]) + + with open("/var/lib/waydroid/waydroid.cfg", "w") as f: + cfg.write(f) def remove_props(self): - with open(os.path.join("/var/lib/waydroid/waydroid_base.prop"), "r") as propfile: - prop_content = propfile.read() - for key in self.apply_props: - if key in prop_content: - p = re.compile(r"^{key}=.*(\n)*".format(key=key), re.M) - prop_content = re.sub(p, "", prop_content) - with open(os.path.join("/var/lib/waydroid/waydroid_base.prop"), "w") as propfile: - propfile.write(prop_content) + cfg = configparser.ConfigParser() + cfg.read("/var/lib/waydroid/waydroid.cfg") + for key in self.apply_props.keys(): + cfg.remove_option('properties', key) + + with open("/var/lib/waydroid/waydroid.cfg", "w") as f: + cfg.write(f) + def mount(self): img = os.path.join(images.get_image_dir(), self.partition+".img") mount_point = "" diff --git a/tools/helper.py b/tools/helper.py index 0f6a833..23b86fd 100644 --- a/tools/helper.py +++ b/tools/helper.py @@ -90,7 +90,6 @@ def shell(arg: str, env: Optional[str] = None): def download_file(url, f_name): md5 = "" - # response = requests.get(url, stream=True, proxies=os.getenv("https_proxy","HTTPS_PROXY")) response = requests.get(url, stream=True) total_size_in_bytes = int(response.headers.get('content-length', 0)) block_size = 1024 # 1 Kibibyte