From d70390197ee3e06ee1fecbc14d1ed48ba4040c94 Mon Sep 17 00:00:00 2001 From: neodarz Date: Sat, 28 Sep 2019 19:30:41 +0200 Subject: Initial commit --- log.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 log.py (limited to 'log.py') diff --git a/log.py b/log.py new file mode 100644 index 0000000..a4ff80c --- /dev/null +++ b/log.py @@ -0,0 +1,20 @@ +#/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)) -- cgit v1.2.1