部分移植
This commit is contained in:
34
src/heurams/kernel/particles/probe.py
Normal file
34
src/heurams/kernel/particles/probe.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from heurams.context import config_var
|
||||
import pathlib
|
||||
|
||||
def probe_by_filename(filename):
|
||||
"""探测指定文件的所有信息"""
|
||||
paths: dict = config_var.get().get("paths")
|
||||
formats = ["toml", "json"]
|
||||
result = {}
|
||||
for item, attr in paths.items():
|
||||
for i in formats:
|
||||
attr: pathlib.Path = pathlib.Path(attr) / filename + '.' + i
|
||||
if attr.exists():
|
||||
result[item.replace("_dir", "")] = str(attr)
|
||||
return result
|
||||
|
||||
def probe_all(is_stem = 1):
|
||||
"""依据目录探测所有信息"""
|
||||
paths: dict = config_var.get().get("paths")
|
||||
result = {}
|
||||
for item, attr in paths.items():
|
||||
attr: pathlib.Path = pathlib.Path(attr)
|
||||
result[item.replace("_dir", "")] = list()
|
||||
for i in attr.iterdir():
|
||||
if not i.is_dir():
|
||||
if is_stem:
|
||||
result[item.replace("_dir", "")].append(str(i.stem))
|
||||
else:
|
||||
result[item.replace("_dir", "")].append(str(i.name))
|
||||
return result
|
||||
|
||||
if __name__ == "__main__":
|
||||
import os
|
||||
print(os.getcwd())
|
||||
print(probe_all())
|
||||
Reference in New Issue
Block a user