Skip to content

Commit

Permalink
Merge pull request #2 from rootifera/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
rootifera authored Jul 15, 2024
2 parents f1c04a7 + 1e1acf0 commit 3d445d0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
44 changes: 42 additions & 2 deletions diskforge.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,48 @@ def identify_disks():
return disk_list


def unmount_disks_partitions(disks):
for disk in disks:
try:
partitions_output = subprocess.check_output(
f"lsblk -ln -o NAME {disk}",
shell=True,
universal_newlines=True
).strip()

partitions = [f"/dev/{part}" for part in partitions_output.split('\n') if part]

if not partitions:
continue

unmounted = False

for partition in partitions:
try:
mount_points = subprocess.check_output(
f"findmnt -rno TARGET -S {partition}",
shell=True,
universal_newlines=True
).strip().split('\n')

for mount_point in mount_points:
if mount_point:
subprocess.run(
f"sudo umount -f {mount_point}",
shell=True,
check=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
)
print(f"Unmounted {mount_point}")
unmounted = True
except subprocess.CalledProcessError:
pass

except subprocess.CalledProcessError:
pass # outout gets too verbose if I print this one or the one above.


def verify_disk_partitions(disk):
try:
output = subprocess.check_output(['lsblk', '-o', 'NAME,SIZE,TYPE', disk]).decode()
Expand Down Expand Up @@ -379,5 +421,3 @@ def check_disk_health(disks):
f"{status_color}{disk_numbered:<20} Size: {disk_size:<8} Status: {health_status:<8} Serial: {serial_number:<20} Issues: {issues}{Style.RESET_ALL}")
else:
print(f"{Fore.RED}Failed to retrieve S.M.A.R.T. data for {disk}{Style.RESET_ALL}")


2 changes: 2 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def signal_handler(sig, frame):
diskforge.check_disk_health(disks)
print(f"{Fore.BLUE}=========== Disk Size ==============")
diskforge.visualize_disk_sizes(disks)
print(f"{Fore.BLUE}=========== Umount Partitions ======")
diskforge.unmount_disks_partitions(disks)
print(f"{Fore.BLUE}=========== Confirmation ===========")
diskforge.confirm_action(disks)
print(f"{Fore.BLUE}====================================")
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="diskforge",
version="1.1",
version="1.2",
author="Omur Ozbahceliler",
author_email="[email protected]",
description="Multi-threaded disk formatter",
Expand Down

0 comments on commit 3d445d0

Please sign in to comment.