From e1d6d0ac3c22a1c87e926c60d5778acfaf0e9af7 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Sun, 24 Aug 2014 10:36:08 +0300 Subject: [PATCH] find_motion() result is now cached; motion webcontrol option is now enabled on port 7999 --- src/config.py | 14 +++++++++++--- src/motionctl.py | 9 ++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/config.py b/src/config.py index 0fc2a2b..36ec6a7 100644 --- a/src/config.py +++ b/src/config.py @@ -104,7 +104,9 @@ def get_main(as_lines=False): def set_main(main_config): global _main_config_cache - _set_default_motion(main_config) + old_motion = _is_old_motion() + + _set_default_motion(main_config, old_motion) _main_config_cache = dict(main_config) _set_wifi_settings(main_config) @@ -1221,9 +1223,9 @@ def _is_old_motion(): return False -def _set_default_motion(data): +def _set_default_motion(data, old_motion=False): data.setdefault('@enabled', True) - + data.setdefault('@show_advanced', False) data.setdefault('@admin_username', 'admin') data.setdefault('@admin_password', '') @@ -1234,6 +1236,12 @@ def _set_default_motion(data): data.setdefault('@wifi_enabled', False) data.setdefault('@wifi_name', '') data.setdefault('@wifi_key', '') + + if old_motion: + data.setdefault('control_port', 7999) + + else: + data.setdefault('webcontrol_port', 7999) def _set_default_motion_camera(camera_id, data, old_motion=False): diff --git a/src/motionctl.py b/src/motionctl.py index aab9a5b..e62aa5c 100644 --- a/src/motionctl.py +++ b/src/motionctl.py @@ -28,9 +28,14 @@ import settings _started = False +_motion_binary_cache = None def find_motion(): + global _motion_binary_cache + if _motion_binary_cache: + return _motion_binary_cache + try: binary = subprocess.check_output('which motion', shell=True).strip() @@ -46,7 +51,9 @@ def find_motion(): result = re.findall('^motion Version ([^,]+)', help) version = result and result[0] or '' - return (binary, version) + _motion_binary_cache = (binary, version) + + return _motion_binary_cache def start(): -- 2.39.5