58 lines
1.9 KiB
Python
58 lines
1.9 KiB
Python
from functools import wraps
|
|
import logging
|
|
|
|
|
|
def log_args_decorator(func):
|
|
"""
|
|
A decorator that logs the arguments passed to a function.
|
|
"""
|
|
@wraps(func)
|
|
def wrapper(*args, **kwargs):
|
|
arg_names = func.__code__.co_varnames[:func.__code__.co_argcount]
|
|
pos_args = dict(zip(arg_names, args))
|
|
all_args = {**pos_args, **kwargs}
|
|
|
|
logging.debug(
|
|
f"Calling function '{func.__name__}' with arguments: {all_args}")
|
|
result = func(*args, **kwargs)
|
|
logging.info(f"Function '{func.__name__}' returned: {result}")
|
|
return result
|
|
return wrapper
|
|
|
|
|
|
def sudo_check(file):
|
|
import gstreamerAutotest as pe
|
|
import subprocess
|
|
import logging
|
|
import emoji
|
|
import os
|
|
|
|
uauth_pass = os.getenv("UAUTH")
|
|
if uauth_pass is None:
|
|
logging.fatal(emoji.emojize(f"""
|
|
:warning: Please, create .env file with UAUTH variable. Before running {file}.
|
|
UAUTH variable should match your password for sudo access to the docker.
|
|
example:
|
|
{os.getcwd()}$ cat .env
|
|
UAUTH=123
|
|
""")
|
|
)
|
|
raise Exception(emoji.emojize(
|
|
":cross_mark: Password isn't set properly"))
|
|
else:
|
|
logging.debug(emoji.emojize(f":warning: pass:{uauth_pass} :warning:"))
|
|
|
|
proc = subprocess.Popen('sudo -S ls', shell=True,
|
|
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
|
stderr=subprocess.STDOUT, text=True)
|
|
pe.passwordAuth(proc)
|
|
code = proc.wait()
|
|
if proc.returncode != 0:
|
|
logging.fatal(emoji.emojize(f"""
|
|
:cross_mark: Password isn't correct in UAUTH
|
|
error={proc.returncode}
|
|
"""))
|
|
raise Exception(emoji.emojize(":cross_mark: Password isn't correct"))
|
|
|
|
logging.info(emoji.emojize(":check_mark_button: Sudo access verified"))
|