diff options
author | neodarz <neodarz@neodarz.net> | 2019-09-28 19:30:41 +0200 |
---|---|---|
committer | neodarz <neodarz@neodarz.net> | 2019-09-28 19:30:41 +0200 |
commit | d70390197ee3e06ee1fecbc14d1ed48ba4040c94 (patch) | |
tree | 325267c8d64ed2d7282d1d3166b0a651b9594ddc /log.py | |
download | pykeepalive-master.tar.xz pykeepalive-master.zip |
Diffstat (limited to 'log.py')
-rw-r--r-- | log.py | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -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)) |