From 671756fdb925978749b1c803d7b8f0da851501f5 Mon Sep 17 00:00:00 2001 From: Calin Crisan <ccrisan@gmail.com> Date: Sat, 12 Oct 2013 22:10:43 +0300 Subject: [PATCH] fixed media file cleanup --- src/cleanup.py | 49 +++++++++++++++++-------------------------------- src/config.py | 4 +++- 2 files changed, 20 insertions(+), 33 deletions(-) diff --git a/src/cleanup.py b/src/cleanup.py index 75e9890..dd45651 100644 --- a/src/cleanup.py +++ b/src/cleanup.py @@ -7,21 +7,22 @@ import config 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 - - 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}) + for root, dirs, files in os.walk(dir): # @UnusedVariable + for name in files: + full_path = os.path.join(root, name) + if not os.path.isfile(full_path): + continue - os.remove(full_path) + 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) def cleanup_images(): @@ -39,18 +40,7 @@ def cleanup_images(): 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(snapshot_path, preserve_moment, exts=['.jpg', '.png']) + _remove_older_files(target_dir, preserve_moment, exts=['.jpg', '.png']) def cleanup_movies(): @@ -68,9 +58,4 @@ def cleanup_movies(): 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(snapshot_path, preserve_moment, exts=['.avi']) + _remove_older_files(target_dir, preserve_moment, exts=['.avi']) diff --git a/src/config.py b/src/config.py index 3fdbaed..fab798c 100644 --- a/src/config.py +++ b/src/config.py @@ -67,7 +67,7 @@ def get_main(as_lines=False): _main_config_cache = data return data - + def set_main(data): global _main_config_cache @@ -198,6 +198,8 @@ def get_camera(camera_id, as_lines=False): data = _conf_to_dict(lines) + data.setdefault('@proto', 'v4l2') + # determine the enabled status if data['@proto'] == 'v4l2': main_config = get_main() -- 2.39.5