forked from platypush/platypush
Removed some optional top-level imports.
Optional top-level imports in Tornado route declarations will trigger `ImportError`. While this will just mean that those routes will be skipped, it will also generate a lot of noise on the logs.
This commit is contained in:
parent
e0af2daaff
commit
27cf1bec52
4 changed files with 10 additions and 14 deletions
|
@ -30,8 +30,7 @@ def get_routes():
|
||||||
if hasattr(module, '__routes__'):
|
if hasattr(module, '__routes__'):
|
||||||
routes.extend(module.__routes__)
|
routes.extend(module.__routes__)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning('Could not import module %s', mod_name)
|
logger().warning('Could not import module %s: %s', mod_name, str(e))
|
||||||
logger.exception(e)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
return routes
|
return routes
|
||||||
|
|
|
@ -3,8 +3,6 @@ import threading
|
||||||
from dataclasses import asdict, dataclass
|
from dataclasses import asdict, dataclass
|
||||||
from typing import Optional, Union, Tuple, Set
|
from typing import Optional, Union, Tuple, Set
|
||||||
|
|
||||||
import numpy as np
|
|
||||||
|
|
||||||
from platypush.plugins.camera.model.writer import (
|
from platypush.plugins.camera.model.writer import (
|
||||||
StreamWriter,
|
StreamWriter,
|
||||||
VideoWriter,
|
VideoWriter,
|
||||||
|
@ -78,6 +76,8 @@ class Camera:
|
||||||
Calculates the effective resolution of the camera in pixels, taking
|
Calculates the effective resolution of the camera in pixels, taking
|
||||||
into account the base resolution, the scale and the rotation.
|
into account the base resolution, the scale and the rotation.
|
||||||
"""
|
"""
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
assert self.info.resolution, 'No base resolution specified'
|
assert self.info.resolution, 'No base resolution specified'
|
||||||
rot = (self.info.rotate or 0) * math.pi / 180
|
rot = (self.info.rotate or 0) * math.pi / 180
|
||||||
sin = math.sin(rot)
|
sin = math.sin(rot)
|
||||||
|
|
|
@ -7,8 +7,6 @@ import time
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from typing import Optional, IO
|
from typing import Optional, IO
|
||||||
|
|
||||||
from PIL.Image import Image
|
|
||||||
|
|
||||||
from platypush.utils import get_redis
|
from platypush.utils import get_redis
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,11 +26,12 @@ class VideoWriter(ABC):
|
||||||
self.closed = False
|
self.closed = False
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def write(self, image: Image):
|
def write(self, image):
|
||||||
"""
|
"""
|
||||||
Write an image to the channel.
|
Write an image to the channel.
|
||||||
|
|
||||||
:param image: PIL Image instance.
|
:param image: PIL Image instance.
|
||||||
|
:type image: PIL.Image.Image
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
@ -88,7 +87,7 @@ class StreamWriter(VideoWriter, ABC):
|
||||||
self.redis_queue = redis_queue
|
self.redis_queue = redis_queue
|
||||||
self.sock = sock
|
self.sock = sock
|
||||||
|
|
||||||
def write(self, image: Image):
|
def write(self, image):
|
||||||
data = self.encode(image)
|
data = self.encode(image)
|
||||||
with self.ready:
|
with self.ready:
|
||||||
if self.buffer.closed:
|
if self.buffer.closed:
|
||||||
|
@ -116,7 +115,7 @@ class StreamWriter(VideoWriter, ABC):
|
||||||
get_redis().publish(self.redis_queue, data)
|
get_redis().publish(self.redis_queue, data)
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def encode(self, image: Image) -> bytes:
|
def encode(self, image) -> bytes:
|
||||||
"""
|
"""
|
||||||
Encode an image before sending it to the channel.
|
Encode an image before sending it to the channel.
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,6 @@ import time
|
||||||
from abc import ABC
|
from abc import ABC
|
||||||
from typing import Optional, Tuple
|
from typing import Optional, Tuple
|
||||||
|
|
||||||
from PIL.Image import Image
|
|
||||||
|
|
||||||
from platypush.plugins.camera.model.camera import Camera
|
from platypush.plugins.camera.model.camera import Camera
|
||||||
from platypush.plugins.camera.model.writer import (
|
from platypush.plugins.camera.model.writer import (
|
||||||
VideoWriter,
|
VideoWriter,
|
||||||
|
@ -73,7 +71,7 @@ class FFmpegWriter(VideoWriter, ABC):
|
||||||
def is_closed(self):
|
def is_closed(self):
|
||||||
return self.closed or not self.ffmpeg or self.ffmpeg.poll() is not None
|
return self.closed or not self.ffmpeg or self.ffmpeg.poll() is not None
|
||||||
|
|
||||||
def write(self, image: Image):
|
def write(self, image):
|
||||||
if self.is_closed():
|
if self.is_closed():
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -146,7 +144,7 @@ class FFmpegStreamWriter(StreamWriter, FFmpegWriter, ABC):
|
||||||
self._reader = threading.Thread(target=self._reader_thread)
|
self._reader = threading.Thread(target=self._reader_thread)
|
||||||
self._reader.start()
|
self._reader.start()
|
||||||
|
|
||||||
def encode(self, image: Image) -> bytes:
|
def encode(self, image) -> bytes:
|
||||||
return image.convert('RGB').tobytes()
|
return image.convert('RGB').tobytes()
|
||||||
|
|
||||||
def _reader_thread(self):
|
def _reader_thread(self):
|
||||||
|
@ -173,7 +171,7 @@ class FFmpegStreamWriter(StreamWriter, FFmpegWriter, ABC):
|
||||||
|
|
||||||
self._sock_send(self.frame)
|
self._sock_send(self.frame)
|
||||||
|
|
||||||
def write(self, image: Image):
|
def write(self, image):
|
||||||
if self.is_closed():
|
if self.is_closed():
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue