strix

A simple web UI for motion
git clone https://www.brianlane.com/git/strix
Log | Files | Refs | LICENSE

commit 195ef49ab68a6b8e2d4ca583deccb1870906f697
parent e42420adb757f195c23d1fbde1110634281b9b4e
Author: Brian C. Lane <bcl@brianlane.com>
Date:   Sat,  1 Jul 2017 12:48:00 -0700

Starting on Event Processing

Diffstat:
Msrc/strix/__init__.py | 31+++++++++++++++++++++++++++++++
Msrc/strix/queue.py | 40+++++++++++++++++++++++++++++++++++++---
2 files changed, 68 insertions(+), 3 deletions(-)

diff --git a/src/strix/__init__.py b/src/strix/__init__.py @@ -14,9 +14,13 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +import os import re +import time +import threading import strix.cmdline +import strix.queue import motion.config ## Check the motion args @@ -93,3 +97,30 @@ def run(): print("ERROR: %s" % e) list(map(p_e, errors)) return False + + queue_path = os.path.abspath(os.path.join(base_dir, "queue/")) + if not os.path.exists(queue_path): + print("ERROR: %s does not exist. Is motion running?" % queue_path) + return False + queue_quit = threading.Event() + queue_thread = threading.Thread(name="queue-thread", + target=strix.queue.monitor_queue, + args=(queue_path,queue_quit)) + queue_thread.start() + + try: + while True: + time.sleep(10) + except Exception as e: + print("ERROR: %s" % e) + except KeyboardInterrupt: + print("Exiting due to ^C") + + # Tell the threads to quit + for t in [queue_quit]: + t.set() + + # Wait until everything is done + print("Waiting for threads to quit") + for t in [queue_thread]: + t.join() diff --git a/src/strix/queue.py b/src/strix/queue.py @@ -14,9 +14,43 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -import threading +from glob import glob +import os +import time +import multiprocessing as mp ## Handle watching the queue and dispatching movie creation and directory moving -class Queue(threading.Threading): - pass +def process_event(event): + print("Processing %s" % event) + + # Convert event to a path, replace _ with / + # Make sure it exists + # Make a ./debug/ directory and move the *m.jpg files into it + # Make a movie out of the jpg files with ffmpeg + # Make a movie out of the debug images + # Create a thumbnail + # Move the directory to its final location + +def monitor_queue(queue_path, quit): + threads = [] + + while not quit.is_set(): + time.sleep(5) + # Remove any threads from the list that have finished + for t in threads[:]: + if not t.is_alive(): + threads.remove(t) + + print("Checking %s" % queue_path) + for event in glob(os.path.join(queue_path, "*")): + os.unlink(event) + thread = mp.Process(target=process_event, args=(event,)) + threads.append(thread) + thread.start() + + print("monitor_queue waiting for threads to finish") + for t in threads: + t.join() + + print("monitor_queue is quitting")