From 61afe5522b835b9f4dbfc8b6556920677fd1d174 Mon Sep 17 00:00:00 2001 From: "WQY\\qiong" Date: Sat, 3 Jun 2023 05:39:36 +0800 Subject: [PATCH] Do not write out new keys --- api/s23_options.py | 117 +++++++++++++++++++++++---------------------- 1 file changed, 60 insertions(+), 57 deletions(-) diff --git a/api/s23_options.py b/api/s23_options.py index 08d674c..aca00a4 100644 --- a/api/s23_options.py +++ b/api/s23_options.py @@ -1,57 +1,60 @@ -from .database import * -from .s23_options_util import get_option_schema, generate_v3 - - -def _inp_in_option(section: list[str]) -> ChangeSet: - if len(section) <= 0: - return ChangeSet() - - cs = g_update_prefix | { 'type' : 'option' } - for s in section: - if s.startswith(';'): - continue - - tokens = s.strip().split() - if tokens[0].upper() == 'PATTERN': # can not upper id - value = tokens[1] if len(tokens) > 1 else '' - cs |= { 'PATTERN' : value } - elif tokens[0].upper() == 'QUALITY': # can not upper trace node - value = tokens[1] if len(tokens) > 1 else '' - if len(tokens) > 2: - value += f' {tokens[2]}' - cs |= { 'QUALITY' : value } - else: - line = s.upper().strip() - for key in get_option_schema('').keys(): - if line.startswith(key): - value = line.removeprefix(key).strip() - cs |= { key : value } - - result = ChangeSet(cs) - result.merge(generate_v3(result)) - return result - - -def inp_in_option(section: list[str]) -> str: - sql = '' - result = _inp_in_option(section) - for op in result.operations: - for key in op.keys(): - if key == 'operation' or key == 'type': - continue - if op['type'] == 'option': - sql += f"update options set value = '{op[key]}' where key = '{key}';" - else: - sql += f"update options_v3 set value = '{op[key]}' where key = '{key}';" - return sql - - -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'] - if str(value).strip() != '': - lines.append(f'{key} {value}') - return lines +from .database import * +from .s23_options_util import get_option_schema, generate_v3 + + +def _inp_in_option(section: list[str]) -> ChangeSet: + if len(section) <= 0: + return ChangeSet() + + cs = g_update_prefix | { 'type' : 'option' } + for s in section: + if s.startswith(';'): + continue + + tokens = s.strip().split() + if tokens[0].upper() == 'PATTERN': # can not upper id + value = tokens[1] if len(tokens) > 1 else '' + cs |= { 'PATTERN' : value } + elif tokens[0].upper() == 'QUALITY': # can not upper trace node + value = tokens[1] if len(tokens) > 1 else '' + if len(tokens) > 2: + value += f' {tokens[2]}' + cs |= { 'QUALITY' : value } + else: + line = s.upper().strip() + for key in get_option_schema('').keys(): + if line.startswith(key): + value = line.removeprefix(key).strip() + cs |= { key : value } + + result = ChangeSet(cs) + result.merge(generate_v3(result)) + return result + + +def inp_in_option(section: list[str]) -> str: + sql = '' + result = _inp_in_option(section) + for op in result.operations: + for key in op.keys(): + if key == 'operation' or key == 'type': + continue + if op['type'] == 'option': + sql += f"update options set value = '{op[key]}' where key = '{key}';" + else: + sql += f"update options_v3 set value = '{op[key]}' where key = '{key}';" + return sql + + +def inp_out_option(name: str) -> list[str]: + lines = [] + objs = read_all(name, f"select * from options") + for obj in objs: + key = obj['key'] + # release version does not support new keys and has error message + if key == 'HTOL' or key == 'QTOL' or key == 'RQTOL': + continue + value = obj['value'] + if str(value).strip() != '': + lines.append(f'{key} {value}') + return lines