From: Calin Crisan Date: Sun, 6 Mar 2016 17:05:22 +0000 (+0200) Subject: added relayevent.sh to speed up event passing a bit X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=ca58b81e5dadc6ecb117d09bda93cff932aa640b;p=motioneye-debian added relayevent.sh to speed up event passing a bit --- diff --git a/motioneye/__init__.py b/motioneye/__init__.py index 17ad1af..c4ff575 100644 --- a/motioneye/__init__.py +++ b/motioneye/__init__.py @@ -1,2 +1,2 @@ -VERSION = "0.31.2" +VERSION = "0.31.3" diff --git a/motioneye/meyectl.py b/motioneye/meyectl.py index a388d0c..44d6112 100755 --- a/motioneye/meyectl.py +++ b/motioneye/meyectl.py @@ -32,12 +32,18 @@ _LOG_FILE = 'motioneye.log' def find_command(command): - cmd = __file__ - cmd = sys.executable + ' ' + cmd - cmd = cmd.replace('-b', '') # remove server-specific options - cmd += ' %s ' % command - cmd += ' '.join([pipes.quote(arg) for arg in sys.argv[2:] - if arg not in ['-b']]) + if command == 'relayevent': + relayevent_sh = os.path.join(os.path.dirname(__file__), 'scripts/relayevent.sh') + + cmd = relayevent_sh + ' "%s"' % (settings._config_file or '') + + else: + cmd = __file__ + cmd = sys.executable + ' ' + cmd + cmd = cmd.replace('-b', '') # remove server-specific options + cmd += ' %s ' % command + cmd += ' '.join([pipes.quote(arg) for arg in sys.argv[2:] + if arg not in ['-b']]) return cmd @@ -128,6 +134,7 @@ def load_settings(): # use the config file directory as base path # if not specified otherwise in the config file base_dir = os.path.dirname(config_file) + settings._config_file = config_file if not conf_path_given[0]: settings.CONF_PATH = base_dir diff --git a/motioneye/scripts/relayevent.sh b/motioneye/scripts/relayevent.sh new file mode 100755 index 0000000..b1d1609 --- /dev/null +++ b/motioneye/scripts/relayevent.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +if [ -z "$3" ]; then + echo "Usage: $0 [filename]" + exit -1 +fi + +motioneye_conf=$1 +if [ -f "$motioneye_conf" ]; then + port=$(cat $motioneye_conf | grep -E '^port' | cut -d ' ' -f 2) + conf_path=$(cat $motioneye_conf | grep -E '^conf_path' | cut -d ' ' -f 2) + if [ -n "$conf_path" ]; then + motion_conf="$conf_path/motion.conf" + if [ -r "$motion_conf" ]; then + username=$(cat $motion_conf | grep 'admin_username' | cut -d ' ' -f 3) + password=$(cat $motion_conf | grep 'admin_password' | cut -d ' ' -f 3) + fi + fi +fi + +test -z "$port" && port="8765" +test -z "$username" && username="admin" + +event="$2" +thread_id="$3" +filename="$4" + +uri="/_relay_event/?_username=$username&event=$event&thread_id=$thread_id" +data="{\"filename\": \"$filename\"}" +signature=$(echo -n "POST:$uri:$data:$password" | sha1sum | cut -d ' ' -f 1) + +curl -H "Content-Type: application/json" -X POST "http://127.0.0.1:$port$uri&_signature=$signature" -d "$data" &>/dev/null + + diff --git a/motioneye/settings.py b/motioneye/settings.py index 301b179..88dccf7 100644 --- a/motioneye/settings.py +++ b/motioneye/settings.py @@ -5,6 +5,8 @@ import sys import motioneye +_config_file = None + # the root directory of the project PROJECT_PATH = os.path.dirname(motioneye.__file__) diff --git a/setup.py b/setup.py index 24729e5..fcf4256 100644 --- a/setup.py +++ b/setup.py @@ -69,7 +69,8 @@ setup( 'motioneye': [ 'static/*.*', 'static/*/*', - 'templates/*' + 'templates/*', + 'scripts/*' ] },