Support to export inp
This commit is contained in:
@@ -2,7 +2,7 @@ from .project import list_project, have_project, create_project, delete_project
|
||||
from .project import is_project_open, get_project_open_count, open_project, close_project
|
||||
from .project import copy_project
|
||||
|
||||
from .parser import read_inp, dump_inp
|
||||
from .parser import read_inp, dump_inp, export_inp
|
||||
|
||||
from .database import API_ADD, API_UPDATE, API_DELETE
|
||||
from .database import ChangeSet
|
||||
|
||||
106
api/parser.py
106
api/parser.py
@@ -342,3 +342,109 @@ def dump_inp(project: str, inp: str):
|
||||
file.close()
|
||||
|
||||
close_project(project)
|
||||
|
||||
|
||||
def export_inp(project: str) -> ChangeSet:
|
||||
if not have_project(project):
|
||||
return ChangeSet()
|
||||
|
||||
if not is_project_open(project):
|
||||
open_project(project)
|
||||
|
||||
inp = ''
|
||||
|
||||
for name in section_name:
|
||||
if name == 'TITLE':
|
||||
inp += f'[{name}]\n'
|
||||
else:
|
||||
inp += f'\n[{name}]\n'
|
||||
|
||||
if name == 'TITLE':
|
||||
inp += '\n'.join(inp_out_title(project))
|
||||
|
||||
elif name == 'JUNCTIONS': # + coords
|
||||
inp += '\n'.join(inp_out_junction(project))
|
||||
|
||||
elif name == 'RESERVOIRS': # + coords
|
||||
inp += '\n'.join(inp_out_reservoir(project))
|
||||
|
||||
elif name == 'TANKS': # + coords
|
||||
inp += '\n'.join(inp_out_tank(project))
|
||||
|
||||
elif name == 'PIPES':
|
||||
inp += '\n'.join(inp_out_pipe(project))
|
||||
|
||||
elif name == 'PUMPS':
|
||||
inp += '\n'.join(inp_out_pump(project))
|
||||
|
||||
elif name == 'VALVES':
|
||||
inp += '\n'.join(inp_out_valve(project))
|
||||
|
||||
elif name == 'TAGS':
|
||||
inp += '\n'.join(inp_out_tag(project))
|
||||
|
||||
elif name == 'DEMANDS':
|
||||
inp += '\n'.join(inp_out_demand(project))
|
||||
|
||||
elif name == 'STATUS':
|
||||
inp += '\n'.join(inp_out_status(project))
|
||||
|
||||
elif name == 'PATTERNS':
|
||||
inp += '\n'.join(inp_out_pattern(project))
|
||||
|
||||
elif name == 'CURVES':
|
||||
inp += '\n'.join(inp_out_curve(project))
|
||||
|
||||
elif name == 'CONTROLS':
|
||||
inp += '\n'.join(inp_out_control(project))
|
||||
|
||||
elif name == 'RULES':
|
||||
inp += '\n'.join(inp_out_rule(project))
|
||||
|
||||
elif name == 'ENERGY':
|
||||
inp += '\n'.join(inp_out_energy(project))
|
||||
|
||||
elif name == 'EMITTERS':
|
||||
inp += '\n'.join(inp_out_emitter(project))
|
||||
|
||||
elif name == 'QUALITY':
|
||||
inp += '\n'.join(inp_out_quality(project))
|
||||
|
||||
elif name == 'SOURCES':
|
||||
inp += '\n'.join(inp_out_source(project))
|
||||
|
||||
elif name == 'REACTIONS':
|
||||
inp += '\n'.join(inp_out_reaction(project))
|
||||
|
||||
elif name == 'MIXING':
|
||||
inp += '\n'.join(inp_out_mixing(project))
|
||||
|
||||
elif name == 'TIMES':
|
||||
inp += '\n'.join(inp_out_time(project))
|
||||
|
||||
elif name == 'REPORT':
|
||||
inp += '\n'.join(inp_out_report(project))
|
||||
|
||||
elif name == 'OPTIONS':
|
||||
inp += '\n'.join(inp_out_option(project))
|
||||
|
||||
elif name == 'COORDINATES':
|
||||
inp += '\n'.join(inp_out_coord(project))
|
||||
|
||||
elif name == 'VERTICES':
|
||||
inp += '\n'.join(inp_out_vertex(project))
|
||||
|
||||
elif name == 'LABELS':
|
||||
inp += '\n'.join(inp_out_label(project))
|
||||
|
||||
elif name == 'BACKDROP':
|
||||
inp += '\n'.join(inp_out_backdrop(project))
|
||||
|
||||
elif name == 'END':
|
||||
pass # :)
|
||||
|
||||
inp += '\n'
|
||||
|
||||
close_project(project)
|
||||
|
||||
return ChangeSet({'operation': 'export', 'inp': inp})
|
||||
|
||||
@@ -142,6 +142,9 @@ def read_inp(name: str, inp: str) -> None:
|
||||
def dump_inp(name: str, inp: str) -> None:
|
||||
return api.dump_inp(name, inp)
|
||||
|
||||
def export_inp(name: str) -> ChangeSet:
|
||||
return api.export_inp(name)
|
||||
|
||||
def run_project(name: str) -> str:
|
||||
return epanet.run_project(name)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user