]> www.vanbest.org Git - motioneye-debian/commitdiff
implemented media files cleanup
authorCalin Crisan <ccrisan@gmail.com>
Sat, 12 Oct 2013 18:23:28 +0000 (21:23 +0300)
committerCalin Crisan <ccrisan@gmail.com>
Sat, 12 Oct 2013 18:23:28 +0000 (21:23 +0300)
doc/todo.txt
motioneye.py
settings.py
src/cleanup.py [new file with mode: 0644]
src/config.py
src/handlers.py
static/js/main.js

index ccb284cef7c63d54b9dedcffd2e02591fae29b97..a127156c9ebf5f11f5946ffbb1a96a3635a930c9 100644 (file)
@@ -1,4 +1,6 @@
 
+-> implement file preserving
+
 -> style scroll bars
 -> hint text next to section titles
 -> clickable hints
 -> add a previewer for snapshots
 -> add a motioneye.svg icon
 
--> implement file preserving
 -> add other options applicable only to special devices (rpi): wifi settings, notifications
 -> group @config rules to top
 
 -> browser compatibility test
 -> requirements test
 
--> add a motion running status indicator (and maybe a start/stop button)
 -> other todos
index 88570b80e0b983b87b108fec3f3d69673840781d..aaea8ff27665ac8dc5d6d52d028a7ffb59a24388 100755 (executable)
@@ -134,14 +134,28 @@ def _start_motion():
             logging.info('motion started')
 
         ioloop = tornado.ioloop.IOLoop.instance()
-        ioloop.add_timeout(datetime.timedelta(seconds=10), checker)
+        ioloop.add_timeout(datetime.timedelta(seconds=settings.MOTION_CHECK_INTERVAL), checker)
     
     checker()
 
 
+def _start_cleanup():
+    import cleanup
+
+    def do_cleanup():
+        cleanup.cleanup_images()
+        cleanup.cleanup_movies()
+        
+        ioloop = tornado.ioloop.IOLoop.instance()
+        ioloop.add_timeout(datetime.timedelta(seconds=settings.CLEANUP_INTERVAL), do_cleanup)
+
+    do_cleanup()
+
+
 if __name__ == '__main__':
     _configure_settings()
     _configure_signals()
     _configure_logging()
     _start_motion()
+    _start_cleanup()
     _start_server()
index 6eeb272d01f2cb00af03a77e2574fddc4382f94b..3131e6ce5b0f44a3d92f90381dba8f90b8c6672d 100644 (file)
@@ -18,3 +18,6 @@ STATIC_URL = '/static/'
 
 LISTEN = '0.0.0.0'
 PORT = 8765
+
+MOTION_CHECK_INTERVAL = 10
+CLEANUP_INTERVAL = 10
diff --git a/src/cleanup.py b/src/cleanup.py
new file mode 100644 (file)
index 0000000..ed6d25e
--- /dev/null
@@ -0,0 +1,72 @@
+
+import datetime
+import logging
+import os
+
+import config
+
+
+def _remove_older_files(dir, moment):
+    for name in os.listdir(dir):
+        full_path = os.path.join(dir, name)
+        if not os.path.isfile(full_path):
+            continue
+        
+        file_moment = datetime.datetime.fromtimestamp(os.path.getmtime(file))
+        if file_moment < moment:
+            logging.debug('removing file %(path)s...' % {
+                    'path': full_path})
+            
+            #os.remove(full_path)
+
+
+def cleanup_images():
+    logging.debug('cleaning up images...')
+    
+    for camera_id in config.get_camera_ids():
+        camera_config = config.get_camera(camera_id)
+        if camera_config.get('@proto') != 'v4l2':
+            continue
+        
+        preserve_images = camera_config.get('@preserve_images')
+        if preserve_images == 0:
+            return # preserve forever
+        
+        preserve_moment = datetime.datetime.now() - datetime.timedelta(days=preserve_images)
+            
+        target_dir = camera_config.get('target_dir')
+        snapshot_filename = camera_config.get('snapshot_filename')
+        jpeg_filename = camera_config.get('snapshot_jpeg')
+        
+        if snapshot_filename:
+            snapshot_path = os.path.join(target_dir, snapshot_filename)
+            snapshot_path = os.path.dirname(snapshot_path)
+            _remove_older_files(dir, preserve_moment)
+    
+        if jpeg_filename:
+            snapshot_path = os.path.join(target_dir, jpeg_filename)
+            snapshot_path = os.path.dirname(snapshot_path)
+            _remove_older_files(dir, preserve_moment)
+
+
+def cleanup_movies():
+    logging.debug('cleaning up movies...')
+    
+    for camera_id in config.get_camera_ids():
+        camera_config = config.get_camera(camera_id)
+        if camera_config.get('@proto') != 'v4l2':
+            continue
+        
+        preserve_movies = camera_config.get('@preserve_movies')
+        if preserve_movies == 0:
+            return # preserve forever
+        
+        preserve_moment = datetime.datetime.now() - datetime.timedelta(days=preserve_movies)
+            
+        target_dir = camera_config.get('target_dir')
+        movie_filename = camera_config.get('movie_filename')
+        
+        if movie_filename:
+            snapshot_path = os.path.join(target_dir, movie_filename)
+            snapshot_path = os.path.dirname(snapshot_path)
+            _remove_older_files(dir, preserve_moment)
index d1db8e215dfde9acbe2536eaba42ad220804c0c9..3fdbaedcdf869ff32ad8750ac9151e1a54e2f651 100644 (file)
@@ -22,7 +22,7 @@ _camera_ids_cache = None
 def get_main(as_lines=False):
     global _main_config_cache
     
-    if not as_lines and _main_config_cache:
+    if not as_lines and _main_config_cache is not None:
         return _main_config_cache
     
     config_file_path = os.path.join(settings.PROJECT_PATH, _MAIN_CONFIG_FILE_PATH)
@@ -119,7 +119,7 @@ def set_main(data):
 def get_camera_ids():
     global _camera_ids_cache
     
-    if _camera_ids_cache:
+    if _camera_ids_cache is not None:
         return _camera_ids_cache
 
     config_path = settings.CONF_PATH
@@ -166,7 +166,7 @@ def has_enabled_cameras():
 def get_camera(camera_id, as_lines=False):
     global _camera_config_cache
     
-    if not as_lines and _camera_config_cache and camera_id in _camera_config_cache:
+    if not as_lines and _camera_config_cache is not None and camera_id in _camera_config_cache:
         return _camera_config_cache[camera_id]
     
     camera_config_path = _CAMERA_CONFIG_FILE_PATH % {'id': camera_id}
index 04c959fa421ec11d1f63955762fa8166766e9070..6980c8686a9f0b9e703ab2c12627def7d44c57b8 100644 (file)
@@ -757,7 +757,7 @@ class ConfigHandler(BaseHandler):
 
 
 class SnapshotHandler(BaseHandler):
-    #@asynchronous TODO don't forget about me
+    @asynchronous
     def get(self, camera_id, op, filename=None):
         if camera_id is not None:
             camera_id = int(camera_id)
index 4de18ceb25221087956530a2222b0267f9b96721..6fd6d42280b507ebf91182d9a90ec2fe0313ee47 100644 (file)
@@ -160,9 +160,7 @@ function initUI() {
     
     /* text validators */
     makeTextValidator($('#adminUsernameEntry'), true);
-    makeTextValidator($('#adminPasswordEntry'), true);
     makeTextValidator($('#normalUsernameEntry'), true);
-    makeTextValidator($('#normalPasswordEntry'), true);
     makeTextValidator($('#deviceNameEntry'), true);
     makeTextValidator($('#networkServerEntry'), true);
     makeTextValidator($('#networkShareNameEntry'), true);