import ctypes import platform import os _lib_core = None _lib_output = None def load_epanet(): _platform = platform.system() if _platform != "Windows": raise Exception(f'Platform {_platform} unsupported (not yet)') _lib_core = ctypes.CDLL("./epanet2.dll") #version = ctypes.c_int() #lib_core.EN_getversion(ctypes.byref(version)) #print(f'Load EPANET {version}') _lib_output = ctypes.CDLL("./epanet-output.dll") # readable True => json, False => binary output def run_epanet(project: str, readable: bool = True) -> str: dir = os.path.dirname(os.getcwd()) exe = os.path.join(os.path.join(dir, 'epanet'), 'runepanet.exe') inp = os.path.join(os.path.join(dir, 'inp'), project + '.inp') rpt = os.path.join(os.path.join(dir, 'temp'), project + '.rpt') opt = os.path.join(os.path.join(dir, 'temp'), project + '.opt') command = f'{exe} {inp} {rpt} {opt}' print(command) os.popen(command) return '' if __name__ == '__main__': load_epanet() run_epanet('net3')