#!/usr/bin/env python3 # # Copyright (C) 2024 Simon Quigley # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import os from datetime import datetime def clean_old_logs(log_dir, max_age_seconds=86400): now = datetime.utcnow() for file_name in os.listdir(log_dir): file_path = os.path.join(log_dir, file_name) if os.path.isfile(file_path): file_age = now - os.path.getmtime(file_path) if file_age > max_age_seconds: os.remove(file_path)