Support database simulation
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
import ctypes
|
||||
import platform
|
||||
import os
|
||||
import sys
|
||||
sys.path.append("..")
|
||||
from api import project
|
||||
from api import parser
|
||||
|
||||
_lib_core = None
|
||||
_lib_output = None
|
||||
|
||||
def load_epanet():
|
||||
def _load_epanet():
|
||||
_platform = platform.system()
|
||||
if _platform != "Windows":
|
||||
raise Exception(f'Platform {_platform} unsupported (not yet)')
|
||||
@@ -15,19 +19,25 @@ def load_epanet():
|
||||
#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:
|
||||
def run_project(name: str, readable: bool = True) -> str:
|
||||
if not project.have_project(name):
|
||||
raise Exception("No such project!")
|
||||
|
||||
dir = os.path.dirname(os.getcwd())
|
||||
|
||||
db_inp = os.path.join(os.path.join(dir, 'db_inp'), name + '.inp')
|
||||
parser.dump_inp(name, db_inp)
|
||||
|
||||
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')
|
||||
inp = os.path.join(os.path.join(dir, 'db_inp'), name + '.inp')
|
||||
rpt = os.path.join(os.path.join(dir, 'temp'), name + '.rpt')
|
||||
opt = os.path.join(os.path.join(dir, 'temp'), name + '.opt')
|
||||
command = f'{exe} {inp} {rpt} {opt}'
|
||||
print(command)
|
||||
os.popen(command)
|
||||
#print(command)
|
||||
result = os.system(command)
|
||||
return ''
|
||||
|
||||
if __name__ == '__main__':
|
||||
load_epanet()
|
||||
run_epanet('net3')
|
||||
_load_epanet()
|
||||
run_project('net3')
|
||||
|
||||
Reference in New Issue
Block a user