diff --git a/tools/conf_migration_tool/conf_migrate.py b/tools/conf_migration_tool/rdp_conf_migrate.py similarity index 98% rename from tools/conf_migration_tool/conf_migrate.py rename to tools/conf_migration_tool/rdp_conf_migrate.py index 331d89d7e0..922adab0c0 100755 --- a/tools/conf_migration_tool/conf_migrate.py +++ b/tools/conf_migration_tool/rdp_conf_migrate.py @@ -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)) @@ -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, @@ -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: @@ -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' diff --git a/tools/conf_migration_tool/tests/test_config_file.py b/tools/conf_migration_tool/tests/test_config_file.py index 6a3cbd7155..cc1bfb414a 100644 --- a/tools/conf_migration_tool/tests/test_config_file.py +++ b/tools/conf_migration_tool/tests/test_config_file.py @@ -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) diff --git a/tools/conf_migration_tool/tests/test_executable_version.py b/tools/conf_migration_tool/tests/test_executable_version.py index 2ebebf883b..c5ee3ac939 100644 --- a/tools/conf_migration_tool/tests/test_executable_version.py +++ b/tools/conf_migration_tool/tests/test_executable_version.py @@ -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):