KasperskyLab-TinyCheck/server/frontend/app/utils.py
2020-11-24 19:45:03 +01:00

36 lines
914 B
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import psutil
import time
import yaml
import sys
import os
from functools import reduce
def terminate_process(process):
"""
Terminale all instances of a process defined by its name.
:return: bool - status of the operation
"""
terminated = False
for proc in psutil.process_iter():
if proc.name() == process:
proc.terminate()
if process == "hostapd":
time.sleep(2)
terminated = True
return terminated
def read_config(path):
"""
Read a value from the configuration
:return: value (it can be any type)
"""
dir = "/".join(sys.path[0].split("/")[:-2])
config = yaml.load(open(os.path.join(dir, "config.yaml"), "r"),
Loader=yaml.SafeLoader)
return reduce(dict.get, path, config)