Refine set option to sync v2 & v3

This commit is contained in:
WQY\qiong
2023-03-08 22:18:28 +08:00
parent ca1a065d54
commit 7c9eb1555a
2 changed files with 16 additions and 5 deletions

View File

@@ -1,4 +1,5 @@
from .database import *
from .s23_options_v3 import set_option_v3
from .s23_options_util import generate_v3
@@ -107,8 +108,13 @@ def set_option_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
return DbChangeSet(redo_sql, undo_sql, [redo_cs], [undo_cs])
def set_option(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, set_option_cmd(name, cs))
def set_option(name: str, cs: ChangeSet, update_v3: bool = True) -> ChangeSet:
v2 = set_option_cmd(name, cs)
result = execute_command(name, v2)
if update_v3:
v3 = generate_v3(ChangeSet(v2.redo_cs[0]))
result.merge(set_option_v3(name, v3, False))
return result
#--------------------------------------------------------------

View File

@@ -5,7 +5,7 @@ from .s23_options import OPTION_HEADLOSS_HW, OPTION_HEADLOSS_DW, OPTION_HEADLOSS
from .s23_options import OPTION_UNBALANCED_STOP, OPTION_UNBALANCED_CONTINUE
from .s23_options import OPTION_QUALITY_NONE, OPTION_QUALITY_CHEMICAL, OPTION_QUALITY_AGE, OPTION_QUALITY_TRACE
from .s23_options import element_schema
from .s23_options import get_option_schema
from .s23_options import get_option_schema, set_option
from .s23_options_util import generate_v2, generate_v3
OPTION_V3_FLOW_UNITS_CFS = OPTION_UNITS_CFS
@@ -128,8 +128,13 @@ def set_option_v3_cmd(name: str, cs: ChangeSet) -> DbChangeSet:
return DbChangeSet(redo_sql, undo_sql, [redo_cs], [undo_cs])
def set_option_v3(name: str, cs: ChangeSet) -> ChangeSet:
return execute_command(name, set_option_v3_cmd(name, cs))
def set_option_v3(name: str, cs: ChangeSet, update_v2: bool = True) -> ChangeSet:
v3 = set_option_v3_cmd(name, cs)
result = execute_command(name, v3)
if update_v2:
v2 = generate_v2(ChangeSet(v3.redo_cs[0]))
result.merge(set_option(name, v2, False))
return result
def _parse_v2(v2_lines: list[str]) -> dict[str, str]: