Skip to content

Commit

Permalink
added checks for openfoam installation
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaHobbyist committed Oct 29, 2024
1 parent a7b8009 commit e20f6c2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pyvnt/Reference/error_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


24 changes: 24 additions & 0 deletions pyvnt/utils/check_deps.py
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit e20f6c2

Please sign in to comment.