]> www.vanbest.org Git - motioneye-debian/commitdiff
removing media files now cleans up the empty dirs
authorCalin Crisan <ccrisan@gmail.com>
Fri, 7 Mar 2014 20:11:06 +0000 (22:11 +0200)
committerCalin Crisan <ccrisan@gmail.com>
Fri, 7 Mar 2014 20:11:06 +0000 (22:11 +0200)
src/mediafiles.py

index a77083430bf5c4ae49185281b92d47d57091511c..4a046b1872dcf63b188c7dd26dd275c9084b7c8b 100644 (file)
@@ -102,10 +102,13 @@ def _remove_older_files(dir, moment, exts):
     for (full_path, st) in _list_media_files(dir, exts):
         file_moment = datetime.datetime.fromtimestamp(st.st_mtime)
         if file_moment < moment:
-            logging.debug('removing file %(path)s...' % {
-                    'path': full_path})
+            logging.debug('removing file %(path)s...' % {'path': full_path})
             
             os.remove(full_path)
+            dir_path = os.path.dirname(full_path)
+            if not os.listdir(dir_path):
+                logging.debug('removing directory %(path)s...' % {'path': dir_path})
+                os.removedirs(dir_path)
 
 
 def find_ffmpeg():