From f2bc3261d6c0f37938a6f82a3e574b8b2df761f1 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Sun, 17 Nov 2013 14:35:17 +0200 Subject: [PATCH] added a requirements test --- doc/todo.txt | 2 -- motioneye.py | 67 ++++++++++++++++++++++++++++++++++++++++++++++- src/mediafiles.py | 8 ++++++ src/motionctl.py | 4 +-- src/v4l2ctl.py | 8 ++++++ 5 files changed, 84 insertions(+), 5 deletions(-) diff --git a/doc/todo.txt b/doc/todo.txt index 7abc86d..0a24257 100644 --- a/doc/todo.txt +++ b/doc/todo.txt @@ -12,5 +12,3 @@ -> chaining two or more remote motionEye cameras breaks updating configuration -> browser compatibility test --> requirements test - \ No newline at end of file diff --git a/motioneye.py b/motioneye.py index ad5eb9b..adc8bc0 100755 --- a/motioneye.py +++ b/motioneye.py @@ -23,7 +23,6 @@ import os.path import re import signal import sys -import tornado.ioloop import settings @@ -32,8 +31,67 @@ sys.path.append(os.path.join(settings.PROJECT_PATH, 'src')) VERSION = '0.5' +def _test_requirements(): + import mediafiles + import motionctl + import v4l2ctl + + try: + import tornado # @UnusedImport + tornado = True + + except ImportError: + tornado = False + + try: + import jinja2 # @UnusedImport + jinja2 = True + + except ImportError: + jinja2 = False + + try: + import PIL.Image # @UnusedImport + pil = True + + except ImportError: + pil = False + + ffmpeg = mediafiles.find_ffmpeg() is not None + motion = motionctl.find_motion() is not None + v4lutils = v4l2ctl.find_v4l2_ctl() is not None + + ok = True + if not tornado: + print('please install tornado (python-tornado)') + ok = False + + if not jinja2: + print('please install jinja2 (python-jinja2)') + ok = False + + if not pil: + print('please install PIL (python-imaging)') + ok = False + + if not ffmpeg: + print('please install ffmpeg') + ok = False + + if not motion: + print('please install motion') + ok = False + + if not v4lutils: + print('please install v4l-utils') + ok = False + + return ok + + def _configure_signals(): def bye_handler(signal, frame): + import tornado.ioloop import motionctl logging.info('interrupt signal received, shutting down...') @@ -174,6 +232,7 @@ def _do_thumbnails(): def _start_server(): + import tornado.ioloop import server server.application.listen(settings.PORT, settings.LISTEN) @@ -183,6 +242,7 @@ def _start_server(): def _start_motion(): + import tornado.ioloop import config import motionctl @@ -207,6 +267,7 @@ def _start_motion(): def _start_cleanup(): + import tornado.ioloop import mediafiles ioloop = tornado.ioloop.IOLoop.instance() @@ -229,6 +290,7 @@ def _start_cleanup(): def _start_movie_thumbnailer(): + import tornado.ioloop import mediafiles ioloop = tornado.ioloop.IOLoop.instance() @@ -250,6 +312,9 @@ def _start_movie_thumbnailer(): if __name__ == '__main__': + if not _test_requirements(): + sys.exit(01) + cmd = _configure_settings() _configure_signals() _configure_logging() diff --git a/src/mediafiles.py b/src/mediafiles.py index d5d73ff..4392d16 100644 --- a/src/mediafiles.py +++ b/src/mediafiles.py @@ -84,6 +84,14 @@ def _remove_older_files(dir, moment, exts): os.remove(full_path) +def find_ffmpeg(): + try: + return subprocess.check_output('which ffmpeg', shell=True).strip() + + except subprocess.CalledProcessError: # not found + return None + + def cleanup_media(media_type): logging.debug('cleaning up %(media_type)ss...' % {'media_type': media_type}) diff --git a/src/motionctl.py b/src/motionctl.py index 3cd3f24..b7aeb13 100644 --- a/src/motionctl.py +++ b/src/motionctl.py @@ -25,7 +25,7 @@ import config import settings -def find_program(): +def find_motion(): try: return subprocess.check_output('which motion', shell=True).strip() @@ -37,7 +37,7 @@ def start(): if running(): raise Exception('motion is already running') - program = find_program() + program = find_motion() if not program: raise Exception('motion executable could not be found') diff --git a/src/v4l2ctl.py b/src/v4l2ctl.py index 7671d9e..b17a20d 100644 --- a/src/v4l2ctl.py +++ b/src/v4l2ctl.py @@ -25,6 +25,14 @@ _ctrls_cache = {} _ctrl_values_cache = {} +def find_v4l2_ctl(): + try: + return subprocess.check_output('which v4l2-ctl', shell=True).strip() + + except subprocess.CalledProcessError: # not found + return None + + def list_devices(): global _resolutions_cache -- 2.39.5