Skip to content

Commit

Permalink
Merge pull request #8 from sweetcheetah/lint
Browse files Browse the repository at this point in the history
implement pylint suggestions
  • Loading branch information
sweetcheetah authored Sep 5, 2024
2 parents ed41911 + eae6fbb commit 417a724
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
18 changes: 12 additions & 6 deletions stream.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
#!/usr/bin/env python3
"""A simple streaming mjpg server"""

import io
import logging
Expand All @@ -24,7 +25,9 @@


class StreamingOutput(io.BufferedIOBase):
def __init__(self):
"""Simple class to create streaming output"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.frame = None
self.condition = Condition()

Expand All @@ -35,7 +38,9 @@ def write(self, buf):


class StreamingHandler(server.BaseHTTPRequestHandler):
def do_GET(self):
"""Simple class to handle http requests"""
def do_GET(self): # pylint: disable=invalid-name
"""Handle GET requests"""
if self.path == '/':
self.send_response(301)
self.send_header('Location', '/index.html')
Expand Down Expand Up @@ -65,21 +70,22 @@ def do_GET(self):
self.end_headers()
self.wfile.write(frame)
self.wfile.write(b'\r\n')
except Exception as e:
except BrokenPipeError as exception:
logging.warning(
'Removed streaming client %s: %s',
self.client_address, str(e))
self.client_address, str(exception))
else:
self.send_error(404)
self.end_headers()


class StreamingServer(socketserver.ThreadingMixIn, server.HTTPServer):
"""Configuration for the http server"""
allow_reuse_address = True
daemon_threads = True


picam2 = Picamera2()
picam2 = Picamera2() # pylint: disable=not-callable
picam2.configure(picam2.create_video_configuration(main={"size": (640, 480)}))
output = StreamingOutput()
picam2.start_recording(MJPEGEncoder(), FileOutput(output))
Expand Down
23 changes: 15 additions & 8 deletions streaming.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
#!/usr/bin/env python3
"""Interface to easily enable the creation of a streaming mjpg server"""

import io
import logging
Expand Down Expand Up @@ -28,7 +29,9 @@


class StreamingOutput(io.BufferedIOBase):
def __init__(self):
"""Simple class to create streaming output"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.frame = None
self.condition = Condition()

Expand All @@ -38,7 +41,9 @@ def write(self, buf):
self.condition.notify_all()

class StreamingHandler(server.BaseHTTPRequestHandler):
def do_GET(self):
"""Simple class to handle http requests"""
def do_GET(self): # pylint: disable=invalid-name
"""Handle GET requests"""
if self.path == '/':
self.send_response(301)
self.send_header('Location', '/index.html')
Expand Down Expand Up @@ -68,29 +73,31 @@ def do_GET(self):
self.end_headers()
self.wfile.write(frame)
self.wfile.write(b'\r\n')
except Exception as e:
except BrokenPipeError as exception:
logging.warning(
'Removed streaming client %s: %s',
self.client_address, str(e))
self.client_address, str(exception))
else:
self.send_error(404)
self.end_headers()


class StreamingServer(socketserver.ThreadingMixIn, server.HTTPServer):
"""Configuration for the http server"""
allow_reuse_address = True
daemon_threads = True


def serve(port: int = 3001):
picam2 = Picamera2()
"""Start streaming"""
picam2 = Picamera2() # pylint: disable=not-callable
picam2.configure(picam2.create_video_configuration(main={"size": (640, 480)}))
picam2.start_recording(MJPEGEncoder(), FileOutput(output))

try:
address = ('', port)
server = StreamingServer(address, StreamingHandler)
server.serve_forever()
streaming_server = StreamingServer(address, StreamingHandler)
streaming_server.serve_forever()
finally:
picam2.stop_recording()

Expand Down

0 comments on commit 417a724

Please sign in to comment.