]> www.vanbest.org Git - motioneye-debian/commitdiff
implemented media files cleanup
authorCalin Crisan <ccrisan@gmail.com>
Sat, 12 Oct 2013 18:44:35 +0000 (21:44 +0300)
committerCalin Crisan <ccrisan@gmail.com>
Sat, 12 Oct 2013 18:44:35 +0000 (21:44 +0300)
doc/todo.txt
motioneye.py
settings.py
src/cleanup.py

index a127156c9ebf5f11f5946ffbb1a96a3635a930c9..8b723474d9a29f974af763ca5868aab33efa7401 100644 (file)
@@ -1,6 +1,4 @@
 
--> implement file preserving
-
 -> style scroll bars
 -> hint text next to section titles
 -> clickable hints
index aaea8ff27665ac8dc5d6d52d028a7ffb59a24388..e6a962c9a55f853207024bcc2587ad9e71807840 100755 (executable)
@@ -143,9 +143,14 @@ def _start_cleanup():
     import cleanup
 
     def do_cleanup():
-        cleanup.cleanup_images()
-        cleanup.cleanup_movies()
-        
+        try:
+            cleanup.cleanup_images()
+            cleanup.cleanup_movies()
+            
+        except Exception as e:
+            logging.error('failed to cleanup media files: %(msg)s' % {
+                    'msg': unicode(e)})
+
         ioloop = tornado.ioloop.IOLoop.instance()
         ioloop.add_timeout(datetime.timedelta(seconds=settings.CLEANUP_INTERVAL), do_cleanup)
 
index 3131e6ce5b0f44a3d92f90381dba8f90b8c6672d..3b003668d949ea20230e1de5d38b6673a187af2f 100644 (file)
@@ -20,4 +20,4 @@ LISTEN = '0.0.0.0'
 PORT = 8765
 
 MOTION_CHECK_INTERVAL = 10
-CLEANUP_INTERVAL = 10
+CLEANUP_INTERVAL = 3
index ed6d25e07027d7b4369b6574b72be9d28e1a833f..75e9890eab42062c1abd8a47453bb1a4c119cec9 100644 (file)
@@ -6,18 +6,22 @@ import os
 import config
 
 
-def _remove_older_files(dir, moment):
+def _remove_older_files(dir, moment, exts):
     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))
+        full_path_lower = full_path.lower()
+        if not [e for e in exts if full_path_lower.endswith(e)]:
+            continue
+        
+        file_moment = datetime.datetime.fromtimestamp(os.path.getmtime(full_path))
         if file_moment < moment:
             logging.debug('removing file %(path)s...' % {
                     'path': full_path})
             
-            #os.remove(full_path)
+            os.remove(full_path)
 
 
 def cleanup_images():
@@ -46,7 +50,7 @@ def cleanup_images():
         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)
+            _remove_older_files(snapshot_path, preserve_moment, exts=['.jpg', '.png'])
 
 
 def cleanup_movies():
@@ -69,4 +73,4 @@ def cleanup_movies():
         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)
+            _remove_older_files(snapshot_path, preserve_moment, exts=['.avi'])