base path is now configurable

This commit is contained in:
Calin Crisan 2016-02-21 13:34:41 +02:00
parent b02587811a
commit b0c2a9c742

View File

@ -194,6 +194,7 @@ def _set_os_settings(s):
def _get_motioneye_settings(): def _get_motioneye_settings():
port = 80 port = 80
base_path = ''
motion_binary = '/usr/bin/motion' motion_binary = '/usr/bin/motion'
debug = False debug = False
motion_keep_alive = False motion_keep_alive = False
@ -213,28 +214,33 @@ def _get_motioneye_settings():
except: except:
continue continue
name = name.replace('_', '-') name = name.replace('-', '_')
if name == 'port': if name == 'port':
port = int(value) port = int(value)
elif name == 'motion-binary': elif name == 'base_path':
base_path = value.strip()
elif name == 'motion_binary':
motion_binary = value motion_binary = value
elif name == 'log-level': elif name == 'log_level':
debug = value == 'debug' debug = value == 'debug'
elif name == 'mjpg-client-idle-timeout': elif name == 'mjpg_client_idle_timeout':
motion_keep_alive = value == '0' motion_keep_alive = value == '0'
s = { s = {
'port': port, 'port': port,
'basePath': base_path,
'motionBinary': motion_binary, 'motionBinary': motion_binary,
'motionKeepAlive': motion_keep_alive, 'motionKeepAlive': motion_keep_alive,
'debug': debug 'debug': debug
} }
logging.debug('motioneye settings: port=%(port)s, motion_binary=%(motionBinary)s, motion_keep_alive=%(motionKeepAlive)s, debug=%(debug)s' % s) logging.debug(('motioneye settings: port=%(port)s, base_path=%(basePath)s, motion_binary=%(motionBinary)s, ' +
'motion_keep_alive=%(motionKeepAlive)s, debug=%(debug)s') % s)
return s return s
@ -242,12 +248,14 @@ def _get_motioneye_settings():
def _set_motioneye_settings(s): def _set_motioneye_settings(s):
s = dict(s) s = dict(s)
s.setdefault('port', 80) s.setdefault('port', 80)
s.setdefault('basePath', '')
s.setdefault('motionBinary', '/usr/bin/motion') s.setdefault('motionBinary', '/usr/bin/motion')
debug = s.setdefault('debug', False) # value needed later debug = s.setdefault('debug', False) # value needed later
s.setdefault('motion_keep_alive', False) s.setdefault('motion_keep_alive', False)
logging.debug('writing motioneye settings to %s: ' % MOTIONEYE_CONF + logging.debug('writing motioneye settings to %s: ' % MOTIONEYE_CONF +
'port=%(port)s, motion_binary=%(motionBinary)s, debug=%(debug)s, motion_keep_alive=%(motionKeepAlive)s' % s) ('port=%(port)s, base_path=%(basePath)s, motion_binary=%(motionBinary)s, ' +
'motion_keep_alive=%(motionKeepAlive)s, debug=%(debug)s') % s)
lines = [] lines = []
if os.path.exists(MOTIONEYE_CONF): if os.path.exists(MOTIONEYE_CONF):
@ -265,31 +273,44 @@ def _set_motioneye_settings(s):
except: except:
continue continue
name = name.replace('_', '-') name = name.replace('-', '_')
if name == 'port': if name == 'port':
lines[i] = 'port %s' % s.pop('port') lines[i] = 'port %s' % s.pop('port')
elif name == 'motion-binary': elif name == 'base_path':
lines[i] = 'motion-binary %s' % s.pop('motionBinary') base_path = s.pop('basePath')
if base_path:
elif name == 'log-level': lines[i] = 'base_path %s' % base_path
lines[i] = 'log-level %s' % ['info', 'debug'][s.pop('debug')]
elif name == 'mjpg-client-idle-timeout': else:
lines[i] = 'mjpg-client-idle-timeout %s' % [10, 0][s.pop('motionKeepAlive')] lines[i] = None
elif name == 'motion_binary':
lines[i] = 'motion_binary %s' % s.pop('motionBinary')
elif name == 'log_level':
lines[i] = 'log_level %s' % ['info', 'debug'][s.pop('debug')]
elif name == 'mjpg_client_idle_timeout':
lines[i] = 'mjpg_client_idle_timeout %s' % [10, 0][s.pop('motionKeepAlive')]
lines = [l for l in lines if l is not None]
if 'port' in s: if 'port' in s:
lines.append('port %s' % s.pop('port')) lines.append('port %s' % s.pop('port'))
if s.get('basePath'):
lines.append('base_path %s' % s.pop('basePath'))
if 'motionBinary' in s: if 'motionBinary' in s:
lines.append('motion-binary %s' % s.pop('motionBinary')) lines.append('motion_binary %s' % s.pop('motionBinary'))
if 'debug' in s: if 'debug' in s:
lines.append('log-level %s' % ['info', 'debug'][s.pop('debug')]) lines.append('log_level %s' % ['info', 'debug'][s.pop('debug')])
if 'motionKeepAlive' in s: if 'motionKeepAlive' in s:
lines.append('mjpg-client-idle-timeout %s' % [10, 0][s.pop('motionKeepAlive')]) lines.append('mjpg_client_idle_timeout %s' % [10, 0][s.pop('motionKeepAlive')])
with open(MOTIONEYE_CONF, 'w') as f: with open(MOTIONEYE_CONF, 'w') as f:
for line in lines: for line in lines:
@ -456,6 +477,21 @@ def port():
} }
@additional_config
def basePath():
return {
'label': 'Base Path',
'description': 'sets a base path of all the URIs used by motionEye (useful when running behind a reverse proxy exposing the motionEye UI at /cams, for example)',
'type': 'str',
'section': 'expertSettings',
'advanced': True,
'reboot': True,
'get': _get_motioneye_settings,
'set': _set_motioneye_settings,
'get_set_dict': True
}
@additional_config @additional_config
def motionBinary(): def motionBinary():
return { return {