-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgparser.py
41 lines (35 loc) · 1.28 KB
/
gparser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# gparser.py
# Copyright (C) 2022 mazen428, mohamedSulaimanAlmarzooqi
# This program is free software:
# you can redistribute it and/or modify it under the terms of the GNU General Public License 3.0 or later
# See the file LICENSE for more details.
import utils
import logging
import time
def parse(file_name: str, from_res: tuple, to_res: tuple) -> str:
final_text = ""
with open(file_name, "r") as f:
lines = f.readlines()
logging.info(
f"Parsing {file_name} with {len(lines)} entries: from: {from_res} to: {to_res}."
)
start = time.perf_counter_ns()
for i in lines:
i = i.strip()
if not i or i.startswith("#") or i.startswith(";"):
continue
parsed = i.split("=")
if len(parsed) != 2:
continue
coordinates = parsed[1].strip().strip('"').split(",")
coordinates = tuple([int(t) for t in coordinates])
converted_coordinate = utils.convert_res(
int(coordinates[0]), int(coordinates[1]), from_res, to_res
)
final_text += (
f'{parsed[0]} = "{converted_coordinate[0]},{converted_coordinate[1]}"\n'
)
logging.info(
f"parse complete: took {(time.perf_counter_ns() - start) / 1000000} milliseconds"
)
return final_text