| 1 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 2 |
# Copyright (C) 2025-2026 Benjamin Abendroth <[email protected]> |
| 3 |
|
| 4 |
'''Code for maintaining backward compatibility with previous versions.''' |
| 5 |
|
| 6 |
from . import utils |
| 7 |
|
| 8 |
# Wrong types in configuration structures are silently ignored, because |
| 9 |
# they are handled elsewhere |
| 10 |
|
| 11 |
|
| 12 |
def fix_option_dictionary(dictionary): |
| 13 |
'''Fix an option dictionary.''' |
| 14 |
|
| 15 |
if not isinstance(dictionary, dict): |
| 16 |
return |
| 17 |
|
| 18 |
if 'group' in dictionary: |
| 19 |
if 'groups' in dictionary: |
| 20 |
msg = ('Both `group` and `groups` found. `group` is deprecated. ' |
| 21 |
'Removing `group` in favour of `groups`') |
| 22 |
utils.warn(msg) |
| 23 |
dictionary.pop('group') |
| 24 |
else: |
| 25 |
utils.warn('`group` is deprecated. Please use `groups` instead') |
| 26 |
dictionary['groups'] = [dictionary.pop('group')] |
| 27 |
|
| 28 |
|
| 29 |
def fix_commandline_dictionary(dictionary): |
| 30 |
'''Fix a commandline dictionary.''' |
| 31 |
|
| 32 |
if not isinstance(dictionary, dict): |
| 33 |
return |
| 34 |
|
| 35 |
options = dictionary.get('options', []) |
| 36 |
|
| 37 |
if isinstance(options, list): |
| 38 |
for option in options: |
| 39 |
fix_option_dictionary(option) |
| 40 |
|
| 41 |
|
| 42 |
def fix_commandline_dictionaries(dictionaries): |
| 43 |
'''Fix a list of commandline dictionaries.''' |
| 44 |
|
| 45 |
if not isinstance(dictionaries, list): |
| 46 |
return |
| 47 |
|
| 48 |
for commandline_dictionary in dictionaries: |
| 49 |
fix_commandline_dictionary(commandline_dictionary) |