Skip to content

Commit

Permalink
[tools] Rename rdp conf migration script
Browse files Browse the repository at this point in the history
The goal is to keep the rdp conf migration script so the name should
be more explicit
  • Loading branch information
mengtan committed Mar 22, 2024
1 parent 9396905 commit a899359
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ def parse_configuration(content: str) -> ConfigurationFragmentListType:
return list(map(_to_fragment, rgx_ini_parser.finditer(content)))


def parse_configuration_from_file(filename: str) -> Tuple[str, ConfigurationFragmentListType]:
def parse_configuration_from_file(
filename: str
) -> Tuple[str, ConfigurationFragmentListType]:
with open(filename, encoding='utf-8') as f:
content = f.read()
return (content, parse_configuration(content))
Expand Down Expand Up @@ -560,13 +562,14 @@ def update_to_dict(item: UpdateItem) -> Optional[Dict[str, str]]:
update_if(d, 'toIniOnly', item.to_ini_only)
return d

def dict_to_dict(values: Dict[str, MigrationKeyOrderType]) -> Dict[str, MigrationKeyOrderType]:
def dict_to_dict(values: Dict[str, MigrationKeyOrderType]
) -> Dict[str, MigrationKeyOrderType | str]:
data = {}
for k, item in values.items():
obj = visitor[type(item)](item)
obj = visitor[type(item)](item) # type: ignore
if obj:
data[k] = obj
return {'kind': 'values', 'values': data}
return {'kind': 'values', 'values': data} # type: ignore

visitor = {
RemoveItem: remove_to_dict,
Expand All @@ -580,7 +583,7 @@ def dict_to_dict(values: Dict[str, MigrationKeyOrderType]) -> Dict[str, Migratio
for version, desc in defs:
data = {}
for section, values_or_item in desc.items():
obj = visitor[type(values_or_item)](values_or_item)
obj = visitor[type(values_or_item)](values_or_item) # type: ignore
if obj:
data[section] = obj
if data:
Expand All @@ -589,13 +592,13 @@ def dict_to_dict(values: Dict[str, MigrationKeyOrderType]) -> Dict[str, Migratio
return json_array


def main(migration_defs: List[MigrationType],
def main(migration_defs: Iterable[MigrationType],
value_injections_desc: ValuesInjectionsDescType,
argv: List[str]) -> int:
if len(argv) != 4 or argv[1] not in {'-s', '-f'}:
if len(argv) == 2 and argv[1] == '--dump=json':
import json # noqa: PLC0415
print(json.dumps(dump_json(migration_defs)))
print(json.dumps(dump_json(migration_defs))) # type: ignore
return 0

print(f'{argv[0]} {{-s|-f}} old_version ini_filename\n'
Expand Down
39 changes: 21 additions & 18 deletions tools/conf_migration_tool/tests/test_config_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,33 @@
import os

from typing import Tuple
from conf_migrate import (parse_configuration,
migration_filter,
migration_def_to_actions,
fragments_to_spans_of_sections,
migrate,
migrate_file,
RedemptionVersion,
UpdateItem,
RemoveItem,
MoveSection,
ConfigKind,
ConfigurationFragment,
MigrationDescType,
migration_defs,
extract_value_injections,
build_with_injected_values,
_merge_session_log_format_10_5_31,
_merge_performance_flags_10_5_31)
from rdp_conf_migrate import (
parse_configuration,
migration_filter,
migration_def_to_actions,
fragments_to_spans_of_sections,
migrate,
migrate_file,
RedemptionVersion,
UpdateItem,
RemoveItem,
MoveSection,
ConfigKind,
ConfigurationFragment,
MigrationDescType,
migration_defs,
extract_value_injections,
build_with_injected_values,
_merge_session_log_format_10_5_31,
_merge_performance_flags_10_5_31
)


def process_migrate(migrate_def: MigrationDescType, ini: str) -> Tuple[bool, str]:
r = migrate(parse_configuration(ini), migrate_def)
return (r[0], ''.join(fragment.text for fragment in r[1]))


def find_migrade_def(version: RedemptionVersion) -> MigrationDescType:
return next(migrate_def for def_version, migrate_def in migration_defs
if version == def_version)
Expand Down
2 changes: 1 addition & 1 deletion tools/conf_migration_tool/tests/test_executable_version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
import unittest

from conf_migrate import RedemptionVersion, RedemptionVersionError
from rdp_conf_migrate import RedemptionVersion, RedemptionVersionError

class Test_RedemptionVersion(unittest.TestCase):
def test_invalid_version(self):
Expand Down

0 comments on commit a899359

Please sign in to comment.