Skip to content
Snippets Groups Projects
Commit 91b91ff7 authored by Nathan Daelman's avatar Nathan Daelman
Browse files

Make __main__.py work

parent d8c658b7
No related branches found
No related tags found
No related merge requests found
from pathlib import Path
import yaml
from general_parser import trace_files
from maple_parser import handler_maple
maple_dir = "maple"
maple_files = ["gga_k_apbe.mpl"]
def get_libxc_settings() -> tuple[str, str]:
# Read the YAML file
with open("config.yaml", "r") as file:
config = yaml.safe_load(file)
file.close()
return config["libxc"]["path"], config["libxc"]["maple"]
def __main__():
# Parse the Maple files
maple_dir = "{}/{}/".format(*get_libxc_settings())
maple_files = [str(file).split('/')[-1] for file in Path(maple_dir).rglob('*.mpl')]
for maple_file in maple_files:
triples = trace_files(
maple_file, maple_dir, handler_maple, triples=set()
)
for triple in triples:
if triple[2] == "FileReference":
print(f"Maple file {triple[0]} references {triple[1]}")
# execute the main function
if __name__ == "__main__":
__main__()
......@@ -5,3 +5,5 @@ neo4j:
port: 7687
libxc:
path: '/home/nathan/Documents/libxc/'
maple: "maple/"
src: "src/"
......@@ -15,6 +15,9 @@ BlockProcessor = Callable[[Block], Triple]
FileHandler = Callable[[FileName], set[Triple]]
def file_path_to_name(file_path: str) -> str:
return file_path.split("/")[-1]
def read_file(file_path: str, line_processor: Callable[[str], str]) -> FileContents:
with open(file_path, "r") as file:
contents = [line_processor(line) for line in file.readlines()]
......
......@@ -7,6 +7,7 @@ from general_parser import (
process_lines,
read_file,
clean_line,
file_path_to_name,
)
......@@ -53,10 +54,6 @@ def split_formula(formula: str) -> MapleFormula:
# Composed, ready-made functions
def file_path_to_name(file_path: str) -> str:
return file_path.split("/")[-1]
def handler_maple(
file_path: str,
) -> set[Triple]: # decide on how to handle file_name rather than file_path
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment