From 1caafe57e664db4425e5bbe6a15a61bb370d1498 Mon Sep 17 00:00:00 2001 From: Rikka Date: Mon, 10 Apr 2023 11:49:37 +0800 Subject: [PATCH] prop: write prop to /var/lib/waydroid/waydroid.cfg --- stuffs/general.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/stuffs/general.py b/stuffs/general.py index c0b8bea..9c2c348 100644 --- a/stuffs/general.py +++ b/stuffs/general.py @@ -1,3 +1,4 @@ +import configparser import os import re import zipfile @@ -54,16 +55,14 @@ 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 mount(self): img = os.path.join(images.get_image_dir(), self.partition+".img")