Skip to content

Commit

Permalink
remove submit logs (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlcoo authored Nov 8, 2024
1 parent 1493196 commit 281db76
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
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

0 comments on commit 281db76

Please sign in to comment.