Parse [OPTIONS]

This commit is contained in:
WQY\qiong
2022-11-12 17:29:42 +08:00
parent 27c112d1fb
commit 1dae56939f
2 changed files with 22 additions and 2 deletions

View File

@@ -69,10 +69,9 @@ def set_time(name: str, cs: ChangeSet) -> ChangeSet:
def inp_in_time(section: list[str]) -> ChangeSet: def inp_in_time(section: list[str]) -> ChangeSet:
cs = g_update_prefix | { 'type' : 'time' } cs = g_update_prefix | { 'type' : 'time' }
keys = ['DURATION', 'HYDRAULIC TIMESTEP', 'QUALITY TIMESTEP', 'RULE TIMESTEP', 'PATTERN TIMESTEP', 'PATTERN START', 'REPORT TIMESTEP', 'REPORT START', 'START CLOCKTIME', 'STATISTIC']
for s in section: for s in section:
line = s.upper().strip() line = s.upper().strip()
for key in keys: for key in get_time_schema('').keys():
if line.startswith(key): if line.startswith(key):
value = line.removeprefix(key).strip() value = line.removeprefix(key).strip()
cs |= { key : value } cs |= { key : value }

View File

@@ -103,3 +103,24 @@ def set_option_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
def set_option(name: str, cs: ChangeSet) -> ChangeSet: def set_option(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, set_option_cache(name, cs)) return execute_command(name, set_option_cache(name, cs))
def inp_in_option(section: list[str]) -> ChangeSet:
cs = g_update_prefix | { 'type' : 'option' }
for s in section:
line = s.upper().strip()
for key in get_option_schema('').keys():
if line.startswith(key):
value = line.removeprefix(key).strip()
cs |= { key : value }
return ChangeSet(cs)
def inp_out_option(name: str) -> list[str]:
lines = []
objs = read_all(name, f"select * from options")
for obj in objs:
key = obj['key']
value = obj['value']
lines.append(f'{key} {value}')
return lines