feat(projects): automate project infrastructure provisioning
This commit is contained in:
@@ -5,7 +5,10 @@ from .options import get_option_schema, get_option_v3_schema, generate_v2, gener
|
||||
def _parse_v2(v2_lines: list[str]) -> dict[str, str]:
|
||||
cs_v2 = g_update_prefix | { 'type' : 'option' }
|
||||
for s in v2_lines:
|
||||
tokens = s.split()
|
||||
stripped = s.strip()
|
||||
if not stripped or stripped.startswith(';'):
|
||||
continue
|
||||
tokens = stripped.split()
|
||||
if tokens[0].upper() == 'PATTERN': # can not upper id
|
||||
value = tokens[1] if len(tokens) > 1 else ''
|
||||
cs_v2 |= { 'PATTERN' : value }
|
||||
@@ -23,6 +26,22 @@ def _parse_v2(v2_lines: list[str]) -> dict[str, str]:
|
||||
return cs_v2
|
||||
|
||||
|
||||
def _option_changes(option_type: str, *change_sets: ChangeSet) -> ChangeSet:
|
||||
values: dict[str, str] = {}
|
||||
for change_set in change_sets:
|
||||
for operation in change_set.operations:
|
||||
values.update(
|
||||
{
|
||||
key: str(value)
|
||||
for key, value in operation.items()
|
||||
if key not in {'operation', 'type'}
|
||||
}
|
||||
)
|
||||
if not values:
|
||||
return ChangeSet()
|
||||
return ChangeSet(g_update_prefix | {'type': option_type} | values)
|
||||
|
||||
|
||||
def _inp_in_option_v3(section: list[str]) -> ChangeSet:
|
||||
if len(section) <= 0:
|
||||
return ChangeSet()
|
||||
@@ -30,10 +49,11 @@ def _inp_in_option_v3(section: list[str]) -> ChangeSet:
|
||||
cs_v3 = g_update_prefix | { 'type' : 'option_v3' }
|
||||
v2_lines = []
|
||||
for s in section:
|
||||
if s.startswith(';'):
|
||||
stripped = s.strip()
|
||||
if not stripped or stripped.startswith(';'):
|
||||
continue
|
||||
|
||||
tokens = s.strip().split()
|
||||
tokens = stripped.split()
|
||||
key = tokens[0]
|
||||
if key in get_option_v3_schema('').keys():
|
||||
value = ''
|
||||
@@ -43,14 +63,17 @@ def _inp_in_option_v3(section: list[str]) -> ChangeSet:
|
||||
value = ' '.join(tokens[1:])
|
||||
cs_v3 |= { key : value }
|
||||
else:
|
||||
v2_lines.append(s.strip())
|
||||
v2_lines.append(stripped)
|
||||
|
||||
# unlikely...
|
||||
cs_v2 = _parse_v2(v2_lines)
|
||||
direct_v2 = _option_changes('option', ChangeSet(cs_v2))
|
||||
direct_v3 = _option_changes('option_v3', ChangeSet(cs_v3))
|
||||
generated_v2 = generate_v2(direct_v3) if direct_v3.operations else ChangeSet()
|
||||
generated_v3 = generate_v3(direct_v2) if direct_v2.operations else ChangeSet()
|
||||
|
||||
result = ChangeSet(cs_v3)
|
||||
result.merge(generate_v3(ChangeSet(cs_v2)))
|
||||
result.merge(generate_v2(result))
|
||||
result = ChangeSet()
|
||||
result.merge(_option_changes('option', generated_v2, direct_v2))
|
||||
result.merge(_option_changes('option_v3', generated_v3, direct_v3))
|
||||
return result
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user