1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00

add support for multiple config file locations

This commit is contained in:
checktheroads
2020-01-28 14:11:34 -07:00
parent dc4baebfa3
commit 69d66cb394
2 changed files with 130 additions and 37 deletions

View File

@@ -27,6 +27,38 @@ def cpu_count():
return multiprocessing.cpu_count()
async def check_path(path, mode="r"):
"""Verify if a path exists and is accessible.
Arguments:
path {Path|str} -- Path object or string of path
mode {str} -- File mode, r or w
Raises:
RuntimeError: Raised if file does not exist or is not accessible
Returns:
{Path|None} -- Path object if checks pass, None if not.
"""
from pathlib import Path
from aiofile import AIOFile
try:
if not isinstance(path, Path):
path = Path(path)
if not path.exists():
raise FileNotFoundError(f"{str(path)} does not exist.")
async with AIOFile(path, mode):
result = path
except Exception:
result = None
return result
def check_python():
"""Verify Python Version.