Passed
Push — master ( 694e2f...150a8e )
by Dean
09:10 queued 06:18
created

SyncRatingsConflictOption.on_database_changed()   A

Complexity

Conditions 2

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 1
CRAP Score 4.3145

Importance

Changes 0
Metric Value
dl 10
loc 10
ccs 1
cts 6
cp 0.1666
rs 9.4285
c 0
b 0
f 0
cc 2
crap 4.3145
1 1
from plugin.core.environment import translate as _
0 ignored issues
show
Bug introduced by
The name environment does not seem to exist in module plugin.core.
Loading history...
Configuration introduced by
Unable to import 'plugin.core.environment' (invalid syntax (<string>, line 101))

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
2 1
from plugin.preferences.options.core.base import SimpleOption
3 1
from plugin.preferences.options.core.description import Description
4 1
from plugin.preferences.options.o_sync.constants import MODE_KEYS_BY_LABEL, RESOLUTION_KEYS_BY_LABEL, MODE_LABELS_BY_KEY, \
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (123/120).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
5
    RESOLUTION_LABELS_BY_KEY, MODE_IDS_BY_KEY, RESOLUTION_IDS_BY_KEY
6 1
from plugin.sync.core.enums import SyncConflictResolution, SyncMode
7
8 1
import logging
9
10 1
log = logging.getLogger(__name__)
11
12
13 1 View Code Duplication
class SyncRatingsOption(SimpleOption):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
14 1
    key = 'sync.ratings.mode'
15 1
    type = 'enum'
16
17 1
    choices = MODE_LABELS_BY_KEY
18 1
    default = SyncMode.Full
19
20 1
    group = (_('Sync'), _('Ratings'))
21 1
    label = _('Mode')
22 1
    description = Description(
23
        _("Syncing mode for movie and episode ratings *(applies to both automatic and manual syncs)*."), [
24
            (_("Full"), _(
25
                "Synchronize ratings with your Trakt.tv profile"
26
            )),
27
            (_("Pull"), _(
28
                "Only pull ratings from your Trakt.tv profile"
29
            )),
30
            (_("Push"), _(
31
                "Only push ratings to your Trakt.tv profile"
32
            )),
33
            (_("Fast Pull"), _(
34
                "Only pull changes to ratings from your Trakt.tv profile"
35
            )),
36
            (_("Disabled"), _(
37
                "Completely disable syncing of ratings"
38
            )),
39
        ]
40
    )
41 1
    order = 210
42
43 1
    preference = 'sync_ratings'
44
45 1
    def on_database_changed(self, value, account=None):
46
        if value not in MODE_IDS_BY_KEY:
47
            log.warn('Unknown value: %r', value)
48
            return
49
50
        # Map `value` to plex preference
51
        value = MODE_IDS_BY_KEY[value]
52
53
        # Update preference
54
        return self._update_preference(value, account)
55
56 1
    def on_plex_changed(self, value, account=None):
57
        if value not in MODE_KEYS_BY_LABEL:
58
            log.warn('Unknown value: %r', value)
59
            return
60
61
        # Map plex `value`
62
        value = MODE_KEYS_BY_LABEL[value]
63
64
        # Update database
65
        self.update(value, account, emit=False)
66
        return value
67
68
69 1 View Code Duplication
class SyncRatingsConflictOption(SimpleOption):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
70 1
    key = 'sync.ratings.conflict'
71 1
    type = 'enum'
72
73 1
    choices = RESOLUTION_LABELS_BY_KEY
74 1
    default = SyncConflictResolution.Latest
75
76 1
    group = (_('Sync'), _('Ratings'))
77 1
    label = _('Conflict resolution')
78 1
    description = Description(
79
        _("Rating to use when a conflict exists between Plex and your Trakt.tv profile."), [
80
            (_("Latest"), _(
81
                "Use the most recent rating"
82
            )),
83
            (_("Trakt"), _(
84
                "Use the rating from your Trakt.tv profile"
85
            )),
86
            (_("Plex"), _(
87
                "Use the rating from Plex"
88
            ))
89
        ]
90
    )
91 1
    order = 211
92
93 1
    preference = 'sync_ratings_conflict'
94
95 1
    def on_database_changed(self, value, account=None):
96
        if value not in RESOLUTION_IDS_BY_KEY:
97
            log.warn('Unknown value: %r', value)
98
            return
99
100
        # Map `value` to plex preference
101
        value = RESOLUTION_IDS_BY_KEY[value]
102
103
        # Update preference
104
        return self._update_preference(value, account)
105
106 1
    def on_plex_changed(self, value, account=None):
107
        if value not in RESOLUTION_KEYS_BY_LABEL:
108
            log.warn('Unknown value: %r', value)
109
            return
110
111
        # Map plex `value`
112
        value = RESOLUTION_KEYS_BY_LABEL[value]
113
114
        # Update database
115
        self.update(value, account, emit=False)
116
        return value
117