#!/usr/bin/python

# -*- coding: utf-8 -*-
# @Author : moshell
# @Date : 2020/4/3

import os
import random
import logging
import toml
from concurrent.futures import ThreadPoolExecutor

class DeleteData(object):
def __init__(self):
self.basicConfig=logging.basicConfig(
level=logging.INFO,
format='%(levelname)s[%(asctime)s]:%(message)s',
filemode='r',
)
self.path="/data66/v1/queue/{}"
def go(self):
with open("./config.toml","r",encoding="utf-8") as f:
toml_file_tmp = toml.load(f)
threads=toml_file_tmp.get("threads").get("threads")
pool = ThreadPoolExecutor(threads)
#input_date = input("请输入需要删除日期(格式:20200101)>>>:").strip()
with open("./config.toml", "r", encoding="utf-8") as f:
toml_file = toml.load(f)
dates_list=toml_file.get("dates").get("dates")
for input_date in dates_list:
dir_list = os.listdir(self.path.format(input_date))
for dirs in dir_list:
dirs_path=os.path.join(self.path.format(input_date),dirs)
for gob_file in os.listdir(dirs_path):
num = random.randint(36, 82)
del_file_name = os.path.join("/data{}/v1/queue/{}/{}/{}".format(
num,input_date, dirs, gob_file
))
self.handle(del_file_name)
pool.submit(self.handle,del_file_name)

def handle(self,del_file):
logging.info("开始删除{}...".format(del_file))
os.system("rm -rf {}".format(del_file))
logging.info("{}已删除...".format(del_file))

if __name__=="__main__":
node=DeleteData()
node.go()