79 lines
2.0 KiB
Python
79 lines
2.0 KiB
Python
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:
|
|
if method == "2 прохода":
|
|
method_ = self.__erasing_2
|
|
elif method == "Случайные данные":
|
|
method = self.__erasing_random
|
|
t = Thread(target=method_, args=(progress,))
|
|
t.start()
|
|
return t
|
|
|
|
def __erasing_2(self, progress):
|
|
len_write = 0
|
|
with open(self.path, "wb") as drive:
|
|
while len_write < self.capacity:
|
|
# drive.write(b"\x00"*self.block_size)
|
|
len_write += self.block_size*64
|
|
progress["value"] = int(len_write/self.capacity * 100)
|
|
|
|
def __erasing_2(self, progress):
|
|
len_write = 0
|
|
with open(self.path, "wb") as drive:
|
|
while len_write < self.capacity:
|
|
# drive.write(b"\x00"*self.block_size)
|
|
len_write += self.block_size*64
|
|
progress["value"] = int(len_write/self.capacity * 100)
|