X-Git-Url: https://glassweightruler.freedombox.rocks/gitweb/waydroid.git/blobdiff_plain/1f0393876d891d0e32a995d0bf7259cc6505afdc..d28d65fa09cf76015ebfd65ec9485c8bdd108b22:/tools/helpers/props.py diff --git a/tools/helpers/props.py b/tools/helpers/props.py index bcc7c34..8b6ca5b 100644 --- a/tools/helpers/props.py +++ b/tools/helpers/props.py @@ -1,6 +1,7 @@ # Copyright 2021 Oliver Smith # SPDX-License-Identifier: GPL-3.0-or-later from shutil import which +import subprocess import logging import os import tools.helpers.run @@ -10,7 +11,7 @@ from tools.interfaces import IPlatform def host_get(args, prop): if which("getprop") is not None: command = ["getprop", prop] - return tools.helpers.run.user(args, command, output_return=True).strip() + return subprocess.run(command, stdout=subprocess.PIPE).stdout.decode('utf-8').strip() else: return "" @@ -20,31 +21,26 @@ def host_set(args, prop, value): tools.helpers.run.user(args, command) def get(args, prop): - if os.path.exists(tools.config.session_defaults["config_path"]): - session_cfg = tools.config.load_session() - if session_cfg["session"]["state"] == "RUNNING": - platformService = IPlatform.get_service(args) - if platformService: - return platformService.getprop(prop, "") - else: - logging.error("Failed to access IPlatform service") - else: - logging.error("WayDroid container is {}".format( - session_cfg["session"]["state"])) + platformService = IPlatform.get_service(args) + if platformService: + return platformService.getprop(prop, "") else: - logging.error("WayDroid session is stopped") + logging.error("Failed to access IPlatform service") def set(args, prop, value): - if os.path.exists(tools.config.session_defaults["config_path"]): - session_cfg = tools.config.load_session() - if session_cfg["session"]["state"] == "RUNNING": - platformService = IPlatform.get_service(args) - if platformService: - platformService.setprop(prop, value) - else: - logging.error("Failed to access IPlatform service") - else: - logging.error("WayDroid container is {}".format( - session_cfg["session"]["state"])) + platformService = IPlatform.get_service(args) + if platformService: + platformService.setprop(prop, value) else: - logging.error("WayDroid session is stopped") + logging.error("Failed to access IPlatform service") + +def file_get(args, file, prop): + with open(file) as build_prop: + for line in build_prop: + line = line.strip() + if len(line) == 0 or line[0] == "#": + continue + k,v = line.partition("=")[::2] + if k == prop: + return v + return ""