]> glassweightruler.freedombox.rocks Git - waydroid.git/blob - tools/helpers/props.py
logging: Use RotatingFileHandler to trim logfile at 5MB
[waydroid.git] / tools / helpers / props.py
1 # Copyright 2021 Oliver Smith
2 # SPDX-License-Identifier: GPL-3.0-or-later
3 from shutil import which
4 import subprocess
5 import logging
6 import tools.helpers.run
7 from tools.interfaces import IPlatform
8
9
10 def host_get(args, prop):
11 if which("getprop") is not None:
12 command = ["getprop", prop]
13 return subprocess.run(command, stdout=subprocess.PIPE).stdout.decode('utf-8').strip()
14 else:
15 return ""
16
17 def host_set(args, prop, value):
18 if which("setprop") is not None:
19 command = ["setprop", prop, value]
20 tools.helpers.run.user(args, command)
21
22 def get(args, prop):
23 platformService = IPlatform.get_service(args)
24 if platformService:
25 return platformService.getprop(prop, "")
26 else:
27 logging.error("Failed to access IPlatform service")
28
29 def set(args, prop, value):
30 platformService = IPlatform.get_service(args)
31 if platformService:
32 platformService.setprop(prop, value)
33 else:
34 logging.error("Failed to access IPlatform service")
35
36 def file_get(args, file, prop):
37 with open(file) as build_prop:
38 for line in build_prop:
39 line = line.strip()
40 if len(line) == 0 or line[0] == "#":
41 continue
42 k,v = line.partition("=")[::2]
43 if k == prop:
44 return v
45 return ""