[git fast commit] 29. Jan 2019 - 20:22:02

This commit is contained in:
Yannik Schmidt
2019-01-29 20:22:02 +01:00
parent 62fa05962c
commit 59e5816b06
2 changed files with 68 additions and 60 deletions

View File

@@ -3,69 +3,26 @@ import time
import threading
def readfile(filename, start_at_end=True, exit_on_eof=False, parsingBackend=None):
last_round_end = None
f = open(filename)
count = 0
if start_at_end:
f.seek(0,2)
# outer loop, continue reading rounds #
while True:
# reset #
round_lines = []
last_line_was_winner = False
## try to read in a full round ##
seek_start = True
while True:
old_line_nr = f.tell()
line = f.readline()
# if no line or incomplete line, sleep and try again #
if not line:
if exit_on_eof:
return
time.sleep(5000)
continue
elif not line.endswith("\n"):
f.seek(old_line_nr)
time.sleep(5000)
continue
if seek_start and not "round_start_active" in line and line:
continue
elif "round_start_active" in line:
seek_start = False
elif "plugin unloaded" in line:
round_lines = []
seek_start = True
continue
# and line and stop if it was round end #
round_lines += [line]
if last_line_was_winner and not parsing.is_round_end(line):
f.seek(f.tell()-1,0)
break
elif parsing.is_round_end(line):
last_round_end = line
break
elif parsing.is_winner_event(line):
last_line_was_winner = True
# parse and evaluate round #
r=parsing.parse_round(round_lines)
if not r:
continue
try:
TS.evaluate_round(r)
except Warning as e:
pass
try:
if cpus > 1:
raise NotImplementedError("Multiprocessing not implemeted yet")
else:
if callable(parsingBackend):
parsingBackend(f)
else:
parsingBackend.parse(f)
except TypeError:
raise RuntimeError("parsingBackend musst be callable or have .parse() callable")
f.close()
def readfiles(filenames,start_at_end=True,nofollow=False):
def readfiles(filenames, parsingBackend, start_at_end=True, nofollow=False):
for f in filenames:
threading.Thread(target=readfile,args=(f,start_at_end,nofollow,)).start()
threading.Thread(target=readfile,args=\
(f, start_at_end, nofollow, parsingBackend)).start()

View File

@@ -8,8 +8,59 @@ def is_plugin_output(line):
def is_winner_event(line):
return "0x42,winner" in line
def get_key(dic,key):
tmp = list(dic)
return tmp[tmp.index(key)]
tmp = list(dic)
return tmp[tmp.index(key)]
def group_rounds(f, exit_of_eof=True):
last_round_end = None
seek_start = True
while True:
old_line_nr = f.tell()
line = f.readline()
# if no line or incomplete line, sleep and try again #
if not line:
if exit_on_eof:
return
time.sleep(5000)
continue
elif not line.endswith("\n"):
f.seek(old_line_nr)
time.sleep(5000)
continue
if seek_start and not "round_start_active" in line and line:
continue
elif "round_start_active" in line:
seek_start = False
elif "plugin unloaded" in line:
round_lines = []
seek_start = True
continue
# and line and stop if it was round end #
round_lines += [line]
if last_line_was_winner and not parsingBackend.is_round_end(line):
f.seek(f.tell()-1,0)
break
elif parsing.is_round_end(line):
last_round_end = line
break
elif parsing.is_winner_event(line):
last_line_was_winner = True
# parse and evaluate round #
r=parsing.parse_round(round_lines)
if not r:
continue
try:
TS.evaluate_round(r)
except Warning as e:
pass
def parseRoundFromLines(r):