#/bin/python3 import platform import subprocess from config import * import commands def tail_log(): if commands.file_len(LOG_PATH_FILE) > LINES_MAX: if platform.system().lower()=='windows': datas = commands.tail(LOG_PATH_FILE, LINES_MIN) with open(LOG_PATH_FILE, "wb") as f: f.write(b' \n'.join(datas)) else: command = ["tail", "-"+str(LINES_MIN), str(LOG_PATH_FILE)] proc = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) datas = proc.stdout.decode('utf-8') with open(LOG_PATH_FILE, "w") as f: f.write("".join(datas))