]> www.vanbest.org Git - motioneye-debian/commitdiff
added relayevent.sh to speed up event passing a bit
authorCalin Crisan <ccrisan@gmail.com>
Sun, 6 Mar 2016 17:05:22 +0000 (19:05 +0200)
committerCalin Crisan <ccrisan@gmail.com>
Sun, 6 Mar 2016 17:05:22 +0000 (19:05 +0200)
motioneye/__init__.py
motioneye/meyectl.py
motioneye/scripts/relayevent.sh [new file with mode: 0755]
motioneye/settings.py
setup.py

index 17ad1afd98870e7edfc551d7aa5e448ad1a71712..c4ff575ad3a7084eab8e05ba1918801a991cd31e 100644 (file)
@@ -1,2 +1,2 @@
 
-VERSION = "0.31.2"
+VERSION = "0.31.3"
index a388d0cfe445bcd7910618c1d8369323783e39d0..44d61120538a4f3e92c1fb596e25cda210649667 100755 (executable)
@@ -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 (executable)
index 0000000..b1d1609
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+if [ -z "$3" ]; then
+    echo "Usage: $0 <motioneye.conf> <event> <thread_id> [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
+
+
index 301b1791c6784bc0bb932915960a919932a80a10..88dccf7002d1a1779c7450cd02a9eceb9eb1e441 100644 (file)
@@ -5,6 +5,8 @@ import sys
 
 import motioneye
 
+_config_file = None
+
 # the root directory of the project
 PROJECT_PATH = os.path.dirname(motioneye.__file__)
 
index 24729e5addd3eab8f97395ad09f30f7cabe2e174..fcf425681069543e801cec7181b510723f82e3ea 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -69,7 +69,8 @@ setup(
         'motioneye': [
             'static/*.*',
             'static/*/*',
-            'templates/*'
+            'templates/*',
+            'scripts/*'
         ]
     },