pylint warnings fixed

This commit is contained in:
Fabio Manganiello 2019-07-13 18:25:42 +02:00
parent 07dbe57641
commit 0b05d7d8de

View file

@ -12,7 +12,7 @@ from platypush.config import Config
from platypush.message.response import Response from platypush.message.response import Response
from platypush.message.event.camera import CameraRecordingStartedEvent, \ from platypush.message.event.camera import CameraRecordingStartedEvent, \
CameraRecordingStoppedEvent, CameraVideoRenderedEvent, \ CameraRecordingStoppedEvent, CameraVideoRenderedEvent, \
CameraPictureTakenEvent, CameraFrameCapturedEvent, CameraEvent CameraPictureTakenEvent, CameraFrameCapturedEvent
from platypush.plugins import Plugin, action from platypush.plugins import Plugin, action
@ -52,8 +52,7 @@ class CameraPlugin(Plugin):
sleep_between_frames=_default_sleep_between_frames, sleep_between_frames=_default_sleep_between_frames,
max_stored_frames=_max_stored_frames, max_stored_frames=_max_stored_frames,
color_transform=_default_color_transform, color_transform=_default_color_transform,
scale_x=None, scale_y=None, rotate=None, flip=None, scale_x=None, scale_y=None, rotate=None, flip=None, **kwargs):
*args, **kwargs):
""" """
:param device_id: Index of the default video device to be used for :param device_id: Index of the default video device to be used for
capturing (default: 0) capturing (default: 0)
@ -115,7 +114,7 @@ class CameraPlugin(Plugin):
:type flip: int :type flip: int
""" """
super().__init__(*args, **kwargs) super().__init__(**kwargs)
self.default_device_id = device_id self.default_device_id = device_id
self.frames_dir = os.path.abspath(os.path.expanduser(frames_dir)) self.frames_dir = os.path.abspath(os.path.expanduser(frames_dir))
@ -153,7 +152,6 @@ class CameraPlugin(Plugin):
return self._devices[device_id] return self._devices[device_id]
def _release_device(self, device_id, wait_thread_termination=True): def _release_device(self, device_id, wait_thread_termination=True):
if device_id in self._is_recording: if device_id in self._is_recording:
self._is_recording[device_id].clear() self._is_recording[device_id].clear()
@ -174,8 +172,8 @@ class CameraPlugin(Plugin):
if device_id in self._recording_info: if device_id in self._recording_info:
del self._recording_info[device_id] del self._recording_info[device_id]
@staticmethod
def _store_frame_to_file(self, frame, frames_dir, image_file): def _store_frame_to_file(frame, frames_dir, image_file):
if image_file: if image_file:
filepath = image_file filepath = image_file
else: else:
@ -185,7 +183,6 @@ class CameraPlugin(Plugin):
cv2.imwrite(filepath, frame) cv2.imwrite(filepath, frame)
return filepath return filepath
def _get_stored_frames_files(self, frames_dir): def _get_stored_frames_files(self, frames_dir):
ret = sorted([ ret = sorted([
os.path.join(frames_dir, f) for f in os.listdir(frames_dir) os.path.join(frames_dir, f) for f in os.listdir(frames_dir)
@ -194,7 +191,6 @@ class CameraPlugin(Plugin):
]) ])
return ret return ret
def _get_avg_fps(self, frames_dir): def _get_avg_fps(self, frames_dir):
files = self._get_stored_frames_files(frames_dir) files = self._get_stored_frames_files(frames_dir)
frame_time_diff = 0.0 frame_time_diff = 0.0
@ -214,13 +210,11 @@ class CameraPlugin(Plugin):
return n_frames / frame_time_diff if n_frames and frame_time_diff else 0 return n_frames / frame_time_diff if n_frames and frame_time_diff else 0
def _remove_expired_frames(self, frames_dir, max_stored_frames): def _remove_expired_frames(self, frames_dir, max_stored_frames):
files = self._get_stored_frames_files(frames_dir) files = self._get_stored_frames_files(frames_dir)
for f in files[:len(files) - max_stored_frames]: for f in files[:len(files) - max_stored_frames]:
os.unlink(f) os.unlink(f)
def _make_video_file(self, frames_dir, video_file, video_type): def _make_video_file(self, frames_dir, video_file, video_type):
files = self._get_stored_frames_files(frames_dir) files = self._get_stored_frames_files(frames_dir)
if not files: if not files:
@ -239,7 +233,6 @@ class CameraPlugin(Plugin):
self.fire_event(CameraVideoRenderedEvent(filename=video_file)) self.fire_event(CameraVideoRenderedEvent(filename=video_file))
shutil.rmtree(frames_dir, ignore_errors=True) shutil.rmtree(frames_dir, ignore_errors=True)
def _recording_thread(self): def _recording_thread(self):
def thread(duration, video_file, image_file, device_id, def thread(duration, video_file, image_file, device_id,
frames_dir, n_frames, sleep_between_frames, frames_dir, n_frames, sleep_between_frames,
@ -326,7 +319,6 @@ class CameraPlugin(Plugin):
return thread return thread
@action @action
def start_recording(self, duration=None, video_file=None, video_type=None, def start_recording(self, duration=None, video_file=None, video_type=None,
device_id=None, frames_dir=None, device_id=None, frames_dir=None,
@ -360,6 +352,7 @@ class CameraPlugin(Plugin):
return self.status(device_id=device_id) return self.status(device_id=device_id)
recording_started = threading.Event() recording_started = threading.Event()
def on_recording_started(event): def on_recording_started(event):
recording_started.set() recording_started.set()
@ -520,7 +513,6 @@ class CameraPlugin(Plugin):
}, disable_logging=True) }, disable_logging=True)
return resp return resp
@action @action
def get_default_device_id(self): def get_default_device_id(self):
return self.default_device_id return self.default_device_id