Support to import inp

This commit is contained in:
WQY\qiong
2023-02-16 23:28:22 +08:00
parent 1984c537a1
commit 78f56ac025
3 changed files with 66 additions and 4 deletions

View File

@@ -73,9 +73,40 @@ def _parse_inp(inp: str) -> dict[str, list[str]]:
return file
def _read_inp(inp: str) -> ChangeSet:
file = _parse_inp(inp)
def _parse_cs(cs: ChangeSet) -> dict[str, list[str]]:
file: dict[str, list[str]] = {}
for s in section_name:
file[s] = []
section = ''
for line in str(cs.operations[0]['inp']).split('\n'):
line = line.strip()
if line == '':
# skip empty line for control and rule
if section == 'CONTROLS' or section == 'RULES':
pass
else:
section = ''
continue
if line.startswith('['):
is_section = False
for s in section_name:
if line.startswith(f'[{s}'):
section = s
is_section = True
break
if is_section:
continue
if section != '':
file[section].append(line)
return file
def _read_inp(file: dict[str, list[str]]) -> ChangeSet:
file_cs: dict[str, ChangeSet] = {}
for s in section_name:
file_cs[s] = ChangeSet()
@@ -227,10 +258,38 @@ def read_inp(project: str, inp: str):
create_project(project)
open_project(project)
execute_batch_commands(project, _read_inp(inp))
file = _parse_inp(inp)
cs = _read_inp(file)
execute_batch_commands(project, cs)
op = get_current_operation(project)
set_restore_operation(project, op)
close_project(project)
def import_inp(project: str, cs: ChangeSet) -> ChangeSet:
if is_project_open(project):
close_project(project)
if have_project(project):
delete_project(project)
create_project(project)
open_project(project)
file = _parse_cs(cs)
new_cs = _read_inp(file)
success_cs = execute_batch_commands(project, new_cs)
op = get_current_operation(project)
set_restore_operation(project, op)
close_project(project)
# return ?
return success_cs
def dump_inp(project: str, inp: str):
if not have_project(project):