Conditions | 7 |
Total Lines | 57 |
Lines | 0 |
Ratio | 0 % |
Tests | 1 |
CRAP Score | 48.6673 |
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 |
|
117 | 1 | def process_missing_movies(self): |
|
118 | """Trigger actions for movies that are in trakt, but was unable to be found in plex""" |
||
119 | |||
120 | if self.current.kwargs.get('section'): |
||
121 | # Collection cleaning disabled for individual syncs |
||
122 | return |
||
123 | |||
124 | # Increment progress steps |
||
125 | self.current.progress.group(Movies, 'missing:movies').add(len(self.p_pending)) |
||
126 | |||
127 | # Iterate over movies |
||
128 | for pk in list(self.p_pending): |
||
129 | # Increment one step |
||
130 | self.current.progress.group(Movies, 'missing:movies').step() |
||
131 | |||
132 | # Iterate over data handlers |
||
133 | triggered = False |
||
134 | |||
135 | for data in self.get_data(SyncMedia.Movies): |
||
136 | if data not in [SyncData.Collection]: |
||
137 | continue |
||
138 | |||
139 | # Retrieve movie |
||
140 | t_movie = self.trakt[(SyncMedia.Movies, data)].get(pk) |
||
141 | |||
142 | if not t_movie: |
||
143 | continue |
||
144 | |||
145 | log.debug('Found movie missing from plex: %r [data: %r]', pk, SyncData.title(data)) |
||
146 | |||
147 | # Trigger handler |
||
148 | self.execute_handlers( |
||
149 | SyncMedia.Movies, data, |
||
150 | |||
151 | key=None, |
||
152 | |||
153 | guid=Guid(*pk), |
||
154 | p_item=None, |
||
155 | |||
156 | t_item=t_movie |
||
157 | ) |
||
158 | |||
159 | # Mark triggered |
||
160 | triggered = True |
||
161 | |||
162 | # Check if action was triggered |
||
163 | if not triggered: |
||
164 | continue |
||
165 | |||
166 | # Remove movie from `pending` set |
||
167 | self.p_pending.remove(pk) |
||
168 | |||
169 | # Stop progress group |
||
170 | self.current.progress.group(Movies, 'missing:movies').stop() |
||
171 | |||
172 | # Report pending movies (no actions triggered) |
||
173 | self.log_pending('Unable to process %d movie(s)\n%s', self.p_pending) |
||
174 |
This check looks for calls to members that are non-existent. These calls will fail.
The member could have been renamed or removed.