File: compat.py

package info (click to toggle)
crazy-complete 0.3.6-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,404 kB
  • sloc: python: 7,949; sh: 4,636; makefile: 74
file content (44 lines) | stat: -rw-r--r-- 1,287 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'''Code for maintaining backward compatibility with previous versions of crazy-complete.'''

from . import utils

# Wrong types in configuration structures are silently ignored, because
# they are handled elsewhere


def fix_option_dictionary(dictionary):
    '''Fix an option dictionary.'''

    if not isinstance(dictionary, dict):
        return

    if 'group' in dictionary:
        if 'groups' in dictionary:
            utils.warn('Both `group` and `groups` found. `group` is deprecated. Removing `group` in favour of `groups`')
            dictionary.pop('group')
        else:
            utils.warn('`group` is deprecated. Please use `groups` instead')
            dictionary['groups'] = [dictionary.pop('group')]


def fix_commandline_dictionary(dictionary):
    '''Fix a commandline dictionary.'''

    if not isinstance(dictionary, dict):
        return

    options = dictionary.get('options', [])

    if isinstance(options, list):
        for option in options:
            fix_option_dictionary(option)


def fix_commandline_dictionaries(dictionaries):
    '''Fix a list of commandline dictionaries.'''

    if not isinstance(dictionaries, list):
        return

    for commandline_dictionary in dictionaries:
        fix_commandline_dictionary(commandline_dictionary)