Passed
Push — master ( b25270...aeb165 )
by Dean
03:03
created

log_unsupported()   B

Complexity

Conditions 4

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 15.664
Metric Value
cc 4
dl 0
loc 24
ccs 1
cts 10
cp 0.1
crap 15.664
rs 8.6845
1 1
from plugin.sync.modes.core.base.mode import Mode
2 1
from plugin.sync.modes.core.base.pull import PullListsMode
3
4 1
unsupported_services = {
5
    'none': True,
6
    'plex': True
7
}
8
9
10 1
def mark_unsupported(dictionary, rating_key, guid):
11
    service = guid.service if guid else None
12
13
    if service not in dictionary:
14
        dictionary[service] = []
15
16
    dictionary[service].append(rating_key)
17
18
19 1
def log_unsupported(logger, message, dictionary):
20
    if len(dictionary) < 1:
21
        return
22
23
    # Display unsupported service list
24
    logger.info(
25
        message,
26
        len(dictionary),
27
        '\n'.join(format_unsupported(dictionary))
28
    )
29
30
    # Display individual warnings for each service
31
    for service in dictionary.keys():
32
        if service not in unsupported_services:
33
            # First occurrence of unsupported service
34
            logger.warn('Unsupported service: %s' % service)
35
36
            # Mark unsupported service as "seen"
37
            unsupported_services[service] = True
38
            continue
39
40
        # Duplicate occurrence of unsupported service
41
        logger.warn('Unsupported service: %s' % service, extra={
42
            'duplicate': True
43
        })
44
45
46 1
def format_unsupported(dictionary):
47
    keys = sorted(dictionary.keys())
48
49
    for service in keys:
50
        yield '    [%14s] Service not supported (%d items)' % (
51
            service,
52
            len(dictionary[service])
53
        )
54