from threading import * erasing_methods = { "2 прохода": { "num_passes": 2, "data": [b"\x00", "random"] }, "Случайные данные": { "num_passes": 1, "data": ["random"] }, "Гутмана": { "num_passes": 35, "data": [] }, "3 прохода": { "num_passes": 3, "data": [b"\x00", b"\xff", "random"] }, "7 проходов": { "num_passes": 7, "data": [b"\x00", b"\xff", "random", "random", b"\x00", b"\x01", "random"] } } class Drive(): index: int = None path: str total_sectors: str disk_type = None name: str block_size: int = 512 capacity: int serial_num = None def __init__(self, name, path, disk_type, block_size, capacity, dev_id, index): self.name = name self.disk_type = disk_type self.path = path if block_size is not None: self.block_size = block_size self.capacity = capacity self.serial_num = dev_id self.index = index def erase(self, method, progress=0) -> Thread: t = Thread(target=self.__erasing, args=(progress,)) t.start() return t def __erasing(self, progress): len_write = 0 write_size = self.block_size*256 with open(self.path, "wb") as drive: while len_write < self.capacity: # drive.write(b"\x00"*self.block_size) len_write += write_size progress.set(len_write/self.capacity)