Test Setup Failed
Push — develop ( 06bf6f...d0ed0b )
by Dean
03:31
created

Movies.run()   D

Complexity

Conditions 9

Size

Total Lines 65

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 81
Metric Value
cc 9
dl 0
loc 65
ccs 1
cts 26
cp 0.0385
crap 81
rs 4.5755

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1 1
from plugin.sync.core.constants import GUID_AGENTS
2 1
from plugin.sync.core.enums import SyncMedia
3 1
from plugin.sync.modes.core.base import log_unsupported, mark_unsupported
4 1
from plugin.sync.modes.pull.base import Base
5
6 1
from plex_database.models import MetadataItem
7 1
import elapsed
8 1
import logging
9
10 1
log = logging.getLogger(__name__)
11
12
13 1
class Movies(Base):
0 ignored issues
show
Coding Style introduced by
This class has no __init__ method.
Loading history...
14 1
    @elapsed.clock
15
    def run(self):
16
        # Retrieve movie sections
17
        p_sections, p_sections_map = self.sections('movie')
0 ignored issues
show
Bug introduced by
The Instance of Movies does not seem to have a member named sections.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Unused Code introduced by
The variable p_sections_map seems to be unused.
Loading history...
18
19
        # Fetch movies with account settings
20
        p_items = self.plex.library.movies.mapped(
0 ignored issues
show
Bug introduced by
The Instance of Movies does not seem to have a member named plex.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
21
            p_sections, [
22
                MetadataItem.library_section
23
            ],
24
            account=self.current.account.plex.key,
0 ignored issues
show
Bug introduced by
The Instance of Movies does not seem to have a member named current.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
25
            parse_guid=True
26
        )
27
28
        # Calculate total number of movies
29
        pending = {}
30
31
        for data in self.get_data(SyncMedia.Movies):
0 ignored issues
show
Bug introduced by
The Instance of Movies does not seem to have a member named get_data.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
32
            if data not in pending:
33
                pending[data] = {}
34
35
            for pk in self.trakt[(SyncMedia.Movies, data)]:
0 ignored issues
show
Bug introduced by
The Instance of Movies does not seem to have a member named trakt.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
36
                pending[data][pk] = False
37
38
        # Task started
39
        unsupported_movies = {}
40
41
        for rating_key, guid, p_item in p_items:
42
            if not guid or guid.agent not in GUID_AGENTS:
43
                mark_unsupported(unsupported_movies, rating_key, guid, p_item)
44
                continue
45
46
            key = (guid.agent, guid.sid)
47
48
            # Try retrieve `pk` for `key`
49
            pk = self.trakt.table.get(key)
0 ignored issues
show
Bug introduced by
The Instance of Movies does not seem to have a member named trakt.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
50
51
            # Store in item map
52
            self.current.map.add(p_item.get('library_section'), rating_key, [key, pk])
0 ignored issues
show
Bug introduced by
The Instance of Movies does not seem to have a member named current.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
53
54
            if pk is None:
55
                # No `pk` found
56
                continue
57
58
            # Execute data handlers
59
            for data in self.get_data(SyncMedia.Movies):
0 ignored issues
show
Bug introduced by
The Instance of Movies does not seem to have a member named get_data.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
60
                t_movie = self.trakt[(SyncMedia.Movies, data)].get(pk)
0 ignored issues
show
Bug introduced by
The Instance of Movies does not seem to have a member named trakt.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
61
62
                self.execute_handlers(
0 ignored issues
show
Bug introduced by
The Instance of Movies does not seem to have a member named execute_handlers.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
63
                    SyncMedia.Movies, data,
64
                    key=rating_key,
65
66
                    p_item=p_item,
67
                    t_item=t_movie
68
                )
69
70
                # Increment one step
71
                self.step(pending, data, pk)
72
73
            # Task checkpoint
74
            self.checkpoint()
0 ignored issues
show
Bug introduced by
The Instance of Movies does not seem to have a member named checkpoint.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
75
76
        # Log details
77
        log_unsupported(log, 'Found %d unsupported movie(s)\n%s', unsupported_movies)
78
        log.debug('Pending: %r', pending)
79