Conditions | 9 |
Total Lines | 65 |
Lines | 0 |
Ratio | 0 % |
Tests | 1 |
CRAP Score | 81 |
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:
If many parameters/temporary variables are present:
1 | 1 | from plugin.sync.core.constants import GUID_AGENTS |
|
14 | 1 | @elapsed.clock |
|
15 | def run(self): |
||
16 | # Retrieve movie sections |
||
17 | p_sections, p_sections_map = self.sections('movie') |
||
18 | |||
19 | # Fetch movies with account settings |
||
20 | p_items = self.plex.library.movies.mapped( |
||
21 | p_sections, [ |
||
22 | MetadataItem.library_section |
||
23 | ], |
||
24 | account=self.current.account.plex.key, |
||
25 | parse_guid=True |
||
26 | ) |
||
27 | |||
28 | # Calculate total number of movies |
||
29 | pending = {} |
||
30 | |||
31 | for data in self.get_data(SyncMedia.Movies): |
||
32 | if data not in pending: |
||
33 | pending[data] = {} |
||
34 | |||
35 | for pk in self.trakt[(SyncMedia.Movies, data)]: |
||
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) |
||
50 | |||
51 | # Store in item map |
||
52 | self.current.map.add(p_item.get('library_section'), rating_key, [key, pk]) |
||
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): |
||
60 | t_movie = self.trakt[(SyncMedia.Movies, data)].get(pk) |
||
61 | |||
62 | self.execute_handlers( |
||
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() |
||
75 | |||
76 | # Log details |
||
77 | log_unsupported(log, 'Found %d unsupported movie(s)\n%s', unsupported_movies) |
||
78 | log.debug('Pending: %r', pending) |
||
79 |