6parser = argparse.ArgumentParser(
8 description=
"For pruning restarts from the logfile such that the latest successful timestep is left in the log",
10parser.add_argument(
"logfile", type=str)
11parser.add_argument(
"outputfile", type=str)
12args = parser.parse_args()
14output = args.outputfile
17with open(input,
"r")
as logfile:
18 loglines = logfile.readlines()
19 iterator = iter(loglines)
21 line = iterator.__next__()
23 while n < len(loglines):
25 regex = re.search(
r"^-{10}\Wtstep\W=\W(\d+).+?-{10}", line)
27 tstep = regex.group(1)
29 logdict[tstep] = [line]
30 line = iterator.__next__()
32 while not re.search(
r"^-{10}\Wtstep\W=\W(\d+).+?-{10}", line):
33 logdict[tstep].append(line)
36 line = iterator.__next__()
41 logdict[-1].append(line)
42 line = iterator.__next__()
48with open(output,
"w")
as fileoutput:
49 for lines
in logdict.values():
51 fileoutput.write(line)