refactor: finish expfcts extractor refactor
This commit is contained in:
@@ -1,23 +1,63 @@
|
||||
import os, re
|
||||
import os
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
# region: Path Getter
|
||||
|
||||
|
||||
def _get_libcmo21_repo_directory() -> Path:
|
||||
repo_root = os.environ.get("LIBCMO21_REPO_ROOT", None)
|
||||
if repo_root is None:
|
||||
return Path(__file__).resolve().parent.parent.parent.parent.parent
|
||||
else:
|
||||
return Path(repo_root).resolve()
|
||||
|
||||
|
||||
def get_input_file_path() -> Path:
|
||||
return _get_libcmo21_repo_directory() / "BMap" / "BMap" / "BMExports.hpp"
|
||||
|
||||
|
||||
def _get_bmap_binder_directory() -> Path:
|
||||
bmap_binder_root = os.environ.get("BMAP_BINDER_ROOT", None)
|
||||
if bmap_binder_root is None:
|
||||
return Path(__file__).resolve().parent.parent
|
||||
else:
|
||||
return Path(bmap_binder_root).resolve()
|
||||
|
||||
|
||||
def get_output_file_path() -> Path:
|
||||
return _get_bmap_binder_directory() / "Extracted" / "BMExports.hpp"
|
||||
|
||||
|
||||
# endregion
|
||||
|
||||
# region: Extractor
|
||||
|
||||
# We should not only match BMAP_EXPORT,
|
||||
# because it may match the defination of BMAP_EXPORT.
|
||||
# So we add a bool at head because all BMap functions return bool.
|
||||
EXPFCTS_PATTERN: re.Pattern = re.compile(
|
||||
"^BMAP_EXPORT[ \\t]+bool[ \\t]+[^;]+;", re.MULTILINE
|
||||
)
|
||||
|
||||
|
||||
def extract_expfcts(infile: Path, outfile: Path) -> None:
|
||||
with open(infile, "r", encoding="utf-8") as fin:
|
||||
# read full text
|
||||
fulltext: str = fin.read()
|
||||
# do findall and write into file
|
||||
with open(outfile, "w", encoding="utf-8") as fout:
|
||||
for item in EXPFCTS_PATTERN.findall(fulltext):
|
||||
fout.write(item)
|
||||
fout.write("\n")
|
||||
|
||||
|
||||
# endregion
|
||||
|
||||
|
||||
def main():
|
||||
self_path: str = os.path.dirname(__file__)
|
||||
src_file: str = os.path.join(self_path, '../../BMap/BMExports.hpp')
|
||||
dst_file: str = os.path.join(self_path, 'dest/BMExports.hpp')
|
||||
|
||||
with open(src_file, 'r', encoding='utf-8') as fsrc:
|
||||
# read full text
|
||||
fulltext: str = fsrc.read()
|
||||
# do findall and write into file
|
||||
with open(dst_file, 'w', encoding='utf-8') as fdst:
|
||||
# We should not only match BMAP_EXPORT,
|
||||
# because it may match the defination of BMAP_EXPORT.
|
||||
# So we add a bool at head because all BMap functions return bool.
|
||||
for item in re.findall('^BMAP_EXPORT[ \\t]+bool[ \\t]+[^;]+;', fulltext, re.MULTILINE):
|
||||
fdst.write(item)
|
||||
fdst.write('\n')
|
||||
|
||||
print('DONE')
|
||||
extract_expfcts(get_input_file_path(), get_output_file_path())
|
||||
print("Done")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user