Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove submit logs #42

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions easypackages/pypi/watch_update_source/src/remove_submit_logs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import os
import re
import shutil
from datetime import datetime


def remove_logs_dirs(log_dir='.'):
# 获取当前日期
current_date = datetime.now()
max_day = 2
# print("remove_submit_logs start")
# 遍历目录下的所有文件
for filename in os.listdir(log_dir):
if filename.startswith('submit-log'): # 确保文件名长度正确
print(filename)
try:
date_match = re.search(r'\d{8}', filename)
if date_match:
date_str = date_match.group(0)
else:
continue
file_datetime = datetime.strptime(date_str, '%Y%m%d')
except ValueError:
print(f'Filename {filename} does not match, skipping.')
continue

# 计算文件日期与当前日期的差值
delta = current_date - file_datetime
print(delta.days)
# 如果文件日期超过max_day天,则删除该文件
if delta.days > max_day:
file_path = os.path.join(log_dir, filename)
# print(f'Deleting {filename} older than {max_day} days.')
try:
shutil.rmtree(file_path)
except Exception as e:
# 捕获其他异常
print(f"删除 {file_path} 时发生错误: {e}")
continue


if __name__ == "__main__":
remove_submit_logs()
3 changes: 3 additions & 0 deletions easypackages/pypi/watch_update_source/src/schedule_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import time
import schedule
import get_update_pypi
import remove_submit_logs

# 全局标志位
task_running = False
Expand Down Expand Up @@ -95,6 +96,8 @@ def run_update_task():
if list_file:
exec_submit_build_job(list_file)

remove_submit_logs.remove_logs_dirs()

task_running = False


Expand Down
Loading