dwipe 2.0.1__py3-none-any.whl → 2.0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dwipe/DeviceInfo.py +183 -52
- dwipe/DiskWipe.py +495 -180
- dwipe/DrivePreChecker.py +90 -0
- dwipe/FirmwareWipeTask.py +370 -0
- dwipe/LsblkMonitor.py +124 -0
- dwipe/PersistentState.py +26 -8
- dwipe/Prereqs.py +84 -0
- dwipe/StructuredLogger.py +643 -0
- dwipe/ToolManager.py +235 -254
- dwipe/Utils.py +108 -0
- dwipe/VerifyTask.py +410 -0
- dwipe/WipeJob.py +613 -165
- dwipe/WipeTask.py +148 -0
- dwipe/WriteTask.py +402 -0
- dwipe/main.py +14 -9
- {dwipe-2.0.1.dist-info → dwipe-2.0.2.dist-info}/METADATA +69 -33
- dwipe-2.0.2.dist-info/RECORD +21 -0
- dwipe/WipeJobFuture.py +0 -245
- dwipe-2.0.1.dist-info/RECORD +0 -14
- {dwipe-2.0.1.dist-info → dwipe-2.0.2.dist-info}/WHEEL +0 -0
- {dwipe-2.0.1.dist-info → dwipe-2.0.2.dist-info}/entry_points.txt +0 -0
- {dwipe-2.0.1.dist-info → dwipe-2.0.2.dist-info}/licenses/LICENSE +0 -0
dwipe/Prereqs.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
import shutil
|
|
3
|
+
import sys
|
|
4
|
+
import os
|
|
5
|
+
from typing import Optional, Dict, List
|
|
6
|
+
|
|
7
|
+
class Prereqs:
|
|
8
|
+
"""Manages tool dependencies and provides actionable install suggestions."""
|
|
9
|
+
|
|
10
|
+
# Mapping tool binary to the actual package name for different managers
|
|
11
|
+
TOOL_MAP = {
|
|
12
|
+
'lsblk': {
|
|
13
|
+
'apt': 'util-linux', 'dnf': 'util-linux', 'pacman': 'util-linux',
|
|
14
|
+
'zypper': 'util-linux', 'apk': 'util-linux'
|
|
15
|
+
},
|
|
16
|
+
'hdparm': {
|
|
17
|
+
'apt': 'hdparm', 'dnf': 'hdparm', 'pacman': 'hdparm',
|
|
18
|
+
'zypper': 'hdparm', 'apk': 'hdparm'
|
|
19
|
+
},
|
|
20
|
+
'nvme': {
|
|
21
|
+
'apt': 'nvme-cli', 'dnf': 'nvme-cli', 'pacman': 'nvme-cli',
|
|
22
|
+
'zypper': 'nvme-cli', 'apk': 'nvme-cli'
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
def __init__(self, verbose: bool = False):
|
|
27
|
+
self.verbose = verbose
|
|
28
|
+
self.pm = self._detect_package_manager()
|
|
29
|
+
# Track status of required tools
|
|
30
|
+
self.results = {}
|
|
31
|
+
|
|
32
|
+
def _detect_package_manager(self) -> Optional[str]:
|
|
33
|
+
managers = ['apt', 'dnf', 'yum', 'pacman', 'zypper', 'apk', 'brew']
|
|
34
|
+
for cmd in managers:
|
|
35
|
+
if shutil.which(cmd):
|
|
36
|
+
return cmd
|
|
37
|
+
return None
|
|
38
|
+
|
|
39
|
+
def check_all(self, tools: List[str]):
|
|
40
|
+
"""Runs the check for a list of tools."""
|
|
41
|
+
for tool in tools:
|
|
42
|
+
path = shutil.which(tool)
|
|
43
|
+
self.results[tool] = path is not None
|
|
44
|
+
return all(self.results.values())
|
|
45
|
+
|
|
46
|
+
def get_install_hint(self, tool: str) -> str:
|
|
47
|
+
"""Returns a string suggesting how to fix the missing tool."""
|
|
48
|
+
if not self.pm:
|
|
49
|
+
return "Please install via your system's package manager."
|
|
50
|
+
|
|
51
|
+
# Get package name (default to tool name if mapping missing)
|
|
52
|
+
pkg = self.TOOL_MAP.get(tool, {}).get(self.pm, tool)
|
|
53
|
+
|
|
54
|
+
commands = {
|
|
55
|
+
'apt': f"sudo apt update && sudo apt install {pkg}",
|
|
56
|
+
'dnf': f"sudo dnf install {pkg}",
|
|
57
|
+
'yum': f"sudo yum install {pkg}",
|
|
58
|
+
'pacman': f"sudo pacman -S {pkg}",
|
|
59
|
+
'zypper': f"sudo zypper install {pkg}",
|
|
60
|
+
'apk': f"apk add {pkg}",
|
|
61
|
+
'brew': f"brew install {pkg}"
|
|
62
|
+
}
|
|
63
|
+
return commands.get(self.pm, f"Use {self.pm} to install {pkg}")
|
|
64
|
+
|
|
65
|
+
def report_and_exit_if_failed(self):
|
|
66
|
+
"""Prints a clean summary to stdout. Exits if critical tools are missing."""
|
|
67
|
+
print("\n--- System Prerequisite Check ---")
|
|
68
|
+
failed = False
|
|
69
|
+
|
|
70
|
+
for tool, available in self.results.items():
|
|
71
|
+
mark = "✓" if available else "✗"
|
|
72
|
+
status = "FOUND" if available else "MISSING"
|
|
73
|
+
print(f" {mark} {tool:<10} : {status}")
|
|
74
|
+
|
|
75
|
+
if not available:
|
|
76
|
+
failed = True
|
|
77
|
+
print(f" └─ Suggestion: {self.get_install_hint(tool)}")
|
|
78
|
+
|
|
79
|
+
if failed:
|
|
80
|
+
print("\nERROR: Dwipe cannot start until all prerequisites are met.\n")
|
|
81
|
+
sys.exit(1)
|
|
82
|
+
|
|
83
|
+
if self.verbose:
|
|
84
|
+
print("All prerequisites satisfied.\n")
|