Passed
Push — beta ( 02f296...72a57d )
by Dean
02:54
created

log_unsupported()   B

Complexity

Conditions 5

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 22.5589

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 23
ccs 1
cts 9
cp 0.1111
rs 8.2508
cc 5
crap 22.5589
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
IGNORED_SERVICES = [
5
    'none',
6
    'plex'
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 is None or service in IGNORED_SERVICES:
33
            logger.info('Ignoring service: %s' % service)
34
            continue
35
36
        # Log unsupported service warning
37
        logger.warn('Unsupported service: %s' % service, extra={
38
            'event': {
39
                'module': __name__,
40
                'name': 'unsupported_service',
41
                'key': service
42
            }
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