diff --git a/pyvnt/Reference/error_classes.py b/pyvnt/Reference/error_classes.py index 5db3495..62dd668 100755 --- a/pyvnt/Reference/error_classes.py +++ b/pyvnt/Reference/error_classes.py @@ -106,4 +106,11 @@ def __init__(self, length: int): def __str__(self): return f"Length of values should be 7. Length of given list is {self.length}" +class VersionError(Exception): + def __init__(self, version: str): + self.version = version + + def __str__(self): + return f"Version {self.version} does not match supported version" + diff --git a/pyvnt/utils/check_deps.py b/pyvnt/utils/check_deps.py new file mode 100644 index 0000000..9ad315d --- /dev/null +++ b/pyvnt/utils/check_deps.py @@ -0,0 +1,24 @@ +import subprocess, re +from pyvnt.Reference.error_classes import VersionError +''' +This function checks for the existence of an external software package. +''' + +def check_package(name, version): + + pkg_cmd = "" + if name == "OpenFOAM": + pkg_cmd = "blockMesh" + + try: + res = subprocess.check_output([pkg_cmd, "-help"], text=True, shell=True) + + match = re.search(r"OpenFOAM-(\d+)", res) + + v = match.group(1) + + if v != version: + raise VersionError(v) + except Exception as e: + print(e) + print("OpenFOAM might not be installed or its environment might not be active") \ No newline at end of file