nixos/scripts/format-disk.py

60 lines
1.2 KiB
Python
Raw Normal View History

2021-12-19 18:41:03 +01:00
#!/usr/bin/env python3
2021-12-19 18:58:31 +01:00
import os
2021-12-19 18:41:03 +01:00
import subprocess
def _run_command(command):
result = subprocess.run(command,
capture_output=True,
text=True,
check=True)
return result
2021-12-19 18:58:31 +01:00
def _get_system_memory():
mem_bytes = os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES')
mem_gib = mem_bytes / (1024.**3)
return round(mem_gib)
2021-12-19 18:47:36 +01:00
def read_disks():
2021-12-19 18:41:03 +01:00
output = _run_command(["lsblk", "-dpno", "name"])
disks = []
for disk in output.stdout.splitlines():
if "loop" in disk:
continue
disks.append(disk)
return disks
2021-12-19 18:47:36 +01:00
def create_menu(disks):
2021-12-19 18:41:03 +01:00
for id, disk in enumerate(disks):
print("{}: {}".format(id, disk))
2021-12-19 18:47:36 +01:00
def get_disk_to_format():
2021-12-19 18:41:03 +01:00
disk_to_format = input("Which disk dou you want to format?: ")
return int(disk_to_format)
2021-12-19 18:41:03 +01:00
2021-12-19 18:47:36 +01:00
def format_disk(disk_to_format):
2021-12-19 18:41:03 +01:00
print("Formatting disk: {}.".format(disk_to_format))
pass
2021-12-19 18:47:36 +01:00
def encrypt_disk():
2021-12-19 18:41:03 +01:00
print("Encrypting disk.")
pass
def main():
2021-12-19 18:47:36 +01:00
disks = read_disks()
2021-12-19 18:48:18 +01:00
create_menu(disks)
disk_to_format = disks[get_disk_to_format()]
format_disk(disk_to_format)
2021-12-19 18:58:31 +01:00
print(_get_system_memory())
2021-12-19 18:41:03 +01:00
if __name__ == "__main__":
main()