From: Calin Crisan Date: Sun, 8 Feb 2015 12:17:37 +0000 (+0200) Subject: the time interval used when gathering email attachment pictures is now X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=eb8e3b35d0035f99057fcaa6c29ba568bfa1c929;p=motioneye-debian the time interval used when gathering email attachment pictures is now configurable --- diff --git a/motioneye.py b/motioneye.py index b4d4383..c290b4b 100755 --- a/motioneye.py +++ b/motioneye.py @@ -63,7 +63,6 @@ def _configure_settings(): set_default_setting('LOCAL_TIME_FILE', None) set_default_setting('ENABLE_REBOOT', False) set_default_setting('SMTP_TIMEOUT', 60) - set_default_setting('NOTIFY_MEDIA_TIMESPAN', 5) set_default_setting('ZIP_TIMEOUT', 500) length = len(sys.argv) - 1 diff --git a/sendmail.py b/sendmail.py index 1ac1e25..a720758 100755 --- a/sendmail.py +++ b/sendmail.py @@ -85,13 +85,13 @@ def send_mail(server, port, account, password, tls, to, subject, message, files) conn.quit() -def make_message(subject, message, camera_id, moment, callback): +def make_message(subject, message, camera_id, moment, timespan, callback): camera_config = config.get_camera(camera_id) def on_media_files(media_files): timestamp = time.mktime(moment.timetuple()) - media_files = [m for m in media_files if abs(m['timestamp'] - timestamp) < settings.NOTIFY_MEDIA_TIMESPAN] # filter out non-recent media files + media_files = [m for m in media_files if abs(m['timestamp'] - timestamp) < timespan] # filter out non-recent media files media_files.sort(key=lambda m: m['timestamp'], reverse=True) media_files = [os.path.join(camera_config['target_dir'], re.sub('^/', '', m['path'])) for m in media_files] @@ -116,12 +116,15 @@ def make_message(subject, message, camera_id, moment, callback): callback(s, m, media_files) - time.sleep(settings.NOTIFY_MEDIA_TIMESPAN) + if not timespan: + return on_media_files([]) + + time.sleep(timespan) # give motion some time to create motion pictures mediafiles.list_media(camera_config, media_type='picture', callback=on_media_files) def print_usage(): - print 'Usage: sendmail.py ' + print 'Usage: sendmail.py [timespan]' if __name__ == '__main__': @@ -138,6 +141,11 @@ if __name__ == '__main__': msg_id = sys.argv[7] camera_id = sys.argv[8] moment = sys.argv[9] + try: + timespan = int(sys.argv[10]) + + except: + timespan = 5 message = messages.get(msg_id) subject = subjects.get(msg_id) @@ -158,6 +166,7 @@ if __name__ == '__main__': logging.debug('camera_id = %s' % camera_id) logging.debug('moment = %s' % moment.strftime('%Y-%m-%d %H:%M:%S')) logging.debug('smtp timeout = %d' % settings.SMTP_TIMEOUT) + logging.debug('timespan = %d' % timespan) if not to: logging.info('no email address specified') @@ -181,7 +190,7 @@ if __name__ == '__main__': def ioloop_timeout(): io_loop.stop() - make_message(subject, message, camera_id, moment, on_message) + make_message(subject, message, camera_id, moment, timespan, on_message) io_loop.add_timeout(datetime.timedelta(seconds=settings.SMTP_TIMEOUT), ioloop_timeout) io_loop.start() diff --git a/settings_default.py b/settings_default.py index 253893e..948a337 100644 --- a/settings_default.py +++ b/settings_default.py @@ -77,8 +77,5 @@ ENABLE_REBOOT = False # the timeout in seconds to use when talking to a SMTP server SMTP_TIMEOUT = 60 -# the interval in seconds to consider around the moment of the event when attaching media files to notifications -NOTIFY_MEDIA_TIMESPAN = 5 - # the time to wait for zip file creation ZIP_TIMEOUT = 500 diff --git a/src/config.py b/src/config.py index 09215a6..1a636a1 100644 --- a/src/config.py +++ b/src/config.py @@ -19,6 +19,7 @@ import errno import logging import os.path import re +import shlex from collections import OrderedDict @@ -730,14 +731,15 @@ def camera_ui_to_dict(ui): send_mail_path = os.path.abspath(send_mail_path) emails = re.sub('\\s', '', ui['email_notifications_addresses']) - on_event_start.append('%(script)s "%(server)s" "%(port)s" "%(account)s" "%(password)s" "%(tls)s" "%(to)s" "motion_start" "%%t" "%%Y-%%m-%%dT%%H:%%M:%%S"' % { + on_event_start.append('%(script)s "%(server)s" "%(port)s" "%(account)s" "%(password)s" "%(tls)s" "%(to)s" "motion_start" "%%t" "%%Y-%%m-%%dT%%H:%%M:%%S" "%(timespan)s"' % { 'script': send_mail_path, 'server': ui['email_notifications_smtp_server'], 'port': ui['email_notifications_smtp_port'], 'account': ui['email_notifications_smtp_account'], 'password': ui['email_notifications_smtp_password'], 'tls': ui['email_notifications_smtp_tls'], - 'to': emails}) + 'to': emails, + 'timespan': ui['email_notifications_picture_time_span']}) if ui['web_hook_notifications_enabled']: web_hook_path = os.path.join(settings.PROJECT_PATH, 'webhook.py') @@ -1033,8 +1035,8 @@ def camera_dict_to_ui(data): command_notifications = [] for e in on_event_start: if e.count('sendmail.py') and e.count('motion_start'): - e = e.replace('"', '').split(' ') - if len(e) != 10: + e = shlex.split(e) + if len(e) < 10: continue ui['email_notifications_enabled'] = True @@ -1044,9 +1046,14 @@ def camera_dict_to_ui(data): ui['email_notifications_smtp_password'] = e[4] ui['email_notifications_smtp_tls'] = e[5].lower() == 'true' ui['email_notifications_addresses'] = e[6] + try: + ui['email_notifications_picture_time_span'] = int(e[10]) + + except: + ui['email_notifications_picture_time_span'] = 5 elif e.count('webhook.py'): - e = e.replace('"', '').split(' ') + e = shlex.split(e) if len(e) != 3: continue diff --git a/static/js/main.js b/static/js/main.js index 5ecfe6f..0695ca8 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -494,6 +494,7 @@ function initUI() { makeNumberValidator($('#postCaptureEntry'), 0, 100, false, false, true); makeNumberValidator($('#minimumMotionFramesEntry'), 1, 1000, false, false, true); makeNumberValidator($('#smtpPortEntry'), 1, 65535, false, false, true); + makeNumberValidator($('#emailPictureTimeSpan'), 0, 60, false, false, true); /* time validators */ makeTimeValidator($('#mondayFromEntry')); @@ -811,6 +812,7 @@ function updateConfigUi() { $('#smtpAccountEntry').parents('tr:eq(0)').each(markHide); $('#smtpPasswordEntry').parents('tr:eq(0)').each(markHide); $('#smtpTlsSwitch').parents('tr:eq(0)').each(markHide); + $('#emailPictureTimeSpan').parents('tr:eq(0)').each(markHide); } if (!$('#webHookNotificationsSwitch').get(0).checked) { @@ -995,6 +997,7 @@ function cameraUi2Dict() { 'email_notifications_smtp_account': $('#smtpAccountEntry').val(), 'email_notifications_smtp_password': $('#smtpPasswordEntry').val(), 'email_notifications_smtp_tls': $('#smtpTlsSwitch')[0].checked, + 'email_notifications_picture_time_span': $('#emailPictureTimeSpan').val(), 'web_hook_notifications_enabled': $('#webHookNotificationsSwitch')[0].checked, 'web_hook_notifications_url': $('#webHookUrlEntry').val(), 'web_hook_notifications_http_method': $('#webHookHttpMethodSelect').val(), @@ -1235,6 +1238,7 @@ function dict2CameraUi(dict) { $('#smtpAccountEntry').val(dict['email_notifications_smtp_account']); $('#smtpPasswordEntry').val(dict['email_notifications_smtp_password']); $('#smtpTlsSwitch')[0].checked = dict['email_notifications_smtp_tls']; + $('#emailPictureTimeSpan').val(dict['email_notifications_picture_time_span']); $('#webHookNotificationsSwitch')[0].checked = dict['web_hook_notifications_enabled']; $('#webHookUrlEntry').val(dict['web_hook_notifications_url']); $('#webHookHttpMethodSelect').val(dict['web_hook_notifications_http_method']); diff --git a/templates/main.html b/templates/main.html index 3a24ecb..0d5a47a 100644 --- a/templates/main.html +++ b/templates/main.html @@ -499,6 +499,11 @@ ? + + Attached Pictures Time Span + seconds + ? +