2021-09-17 09:27:44 +02:00
|
|
|
#!/usr/bin/python3
|
|
|
|
import re
|
|
|
|
from pathlib import Path
|
|
|
|
from typing import Dict
|
2021-09-17 09:32:41 +02:00
|
|
|
from config import DEFAULT_IMPORT_INDENTATION
|
2021-09-17 09:27:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
def parse_counters(filepath: Path, break_point: Dict) -> Dict:
|
|
|
|
if not filepath.is_file():
|
|
|
|
return {}
|
|
|
|
counters: Dict = {}
|
|
|
|
with open(filepath) as f:
|
|
|
|
for line in f:
|
2021-09-17 14:12:46 +02:00
|
|
|
match = re.search(r"(.*): (\d*\.)*?(\d+)", line)
|
|
|
|
if not match:
|
|
|
|
continue
|
|
|
|
counter, _, num = match.groups()
|
2021-09-17 09:27:44 +02:00
|
|
|
num = int(num)
|
|
|
|
if counter in break_point and num >= break_point[counter]:
|
|
|
|
return counters
|
|
|
|
counters[counter] = num
|
|
|
|
return counters
|
|
|
|
|
|
|
|
|
|
|
|
def dict2setcounters(counters: Dict):
|
|
|
|
counters_as_list = [(counter, counters[counter]) for counter in counters.keys()]
|
2021-09-17 09:32:41 +02:00
|
|
|
return ''.join(' ' * DEFAULT_IMPORT_INDENTATION + r'\setcounter{' + counter + '}{' + str(num) + '}\n'
|
|
|
|
for (counter, num) in counters_as_list)
|