Python: Add UCI helper functions

library_additions
Marc 2021-07-21 15:01:10 +01:00
parent 72360a8ada
commit 9618b46a76
No known key found for this signature in database
GPG Key ID: 0657563F705ACAAE
1 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,36 @@
from logging import Logger
from typing import Optional, Tuple, List, Union
import subprocess
import os
def uci_set(key: str, value) -> bool:
"""
Set a UCI property to value
:param key: The UCI key to target
:param value: The value to set the UCI key to
:return: True if successful, false if not.
"""
argument = f"{key}='{value}'"
out = subprocess.run(["uci", "set", argument])
if out.returncode != 0:
return False
out = subprocess.run(["uci", "commit"])
if out.returncode != 0:
return False
return True
def uci_get(key: str) -> str:
"""
Get a UCI value from it's key
:param key: The UCI key to target
:return: str
"""
out = subprocess.run(["uci", "get", key])
return out.stdout