Actual disk names
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import json
|
||||
import subprocess
|
||||
|
||||
import gi
|
||||
|
||||
gi.require_version("Gtk", "4.0")
|
||||
@@ -32,21 +35,25 @@ class StoragePage(Adw.Bin):
|
||||
box.append(descr)
|
||||
|
||||
# Disk List
|
||||
group = Adw.PreferencesGroup()
|
||||
group.set_title("Available Disks")
|
||||
box.append(group)
|
||||
self.disk_group = Adw.PreferencesGroup()
|
||||
self.disk_group.set_title("Available Disks")
|
||||
box.append(self.disk_group)
|
||||
|
||||
# Mock Disks
|
||||
disks = [
|
||||
(
|
||||
"NVMe Samsung 970 EVO (500GB)",
|
||||
"nvme0n1",
|
||||
"icon-drive-harddisk-solidstate-symbolic",
|
||||
),
|
||||
("SATA Seagate Barracuda (1TB)", "sda", "icon-drive-harddisk-symbolic"),
|
||||
]
|
||||
# Fetch real disks or fallback to mock
|
||||
disks = self.get_disks()
|
||||
if not disks:
|
||||
disks = [
|
||||
(
|
||||
"NVMe Samsung 970 EVO (500GB)",
|
||||
"nvme0n1",
|
||||
"icon-drive-harddisk-solidstate-symbolic",
|
||||
),
|
||||
("SATA Seagate Barracuda (1TB)", "sda", "icon-drive-harddisk-symbolic"),
|
||||
]
|
||||
|
||||
self.disk_rows = []
|
||||
self.first_radio = None
|
||||
|
||||
for name, dev, icon in disks:
|
||||
row = Adw.ActionRow()
|
||||
row.set_title(name)
|
||||
@@ -54,7 +61,7 @@ class StoragePage(Adw.Bin):
|
||||
row.set_icon_name(icon)
|
||||
|
||||
# Radio button for selection
|
||||
if not self.disk_rows:
|
||||
if not self.first_radio:
|
||||
radio = Gtk.CheckButton()
|
||||
self.first_radio = radio
|
||||
else:
|
||||
@@ -65,19 +72,41 @@ class StoragePage(Adw.Bin):
|
||||
row.add_suffix(radio)
|
||||
row.set_activatable_widget(radio)
|
||||
|
||||
group.add(row)
|
||||
self.disk_group.add(row)
|
||||
self.disk_rows.append(row)
|
||||
|
||||
# Partitioning Options
|
||||
part_group = Adw.PreferencesGroup()
|
||||
part_group.set_title("Configuration")
|
||||
box.append(part_group)
|
||||
def get_disks(self):
|
||||
try:
|
||||
# lsblk -J -o NAME,SIZE,MODEL,TYPE,TRAN
|
||||
result = subprocess.run(
|
||||
["lsblk", "-J", "-o", "NAME,SIZE,MODEL,TYPE,TRAN"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
if result.returncode != 0:
|
||||
print(f"lsblk failed with code {result.returncode}: {result.stderr}")
|
||||
return []
|
||||
|
||||
auto_row = Adw.ActionRow()
|
||||
auto_row.set_title("Automatic Partitioning")
|
||||
auto_row.set_subtitle("Erase disk and install Iridium")
|
||||
part_switch = Gtk.Switch()
|
||||
part_switch.set_active(True)
|
||||
part_switch.set_valign(Gtk.Align.CENTER)
|
||||
auto_row.add_suffix(part_switch)
|
||||
part_group.add(auto_row)
|
||||
data = json.loads(result.stdout)
|
||||
disks = []
|
||||
for device in data.get("blockdevices", []):
|
||||
# Filter for physical disks usually
|
||||
if device.get("type") == "disk":
|
||||
model = device.get("model")
|
||||
size = device.get("size")
|
||||
name = f"{model} ({size})" if model else f"Unknown Drive ({size})"
|
||||
dev = device.get("name")
|
||||
|
||||
tran = device.get("tran", "").lower() if device.get("tran") else ""
|
||||
if "usb" in tran:
|
||||
icon = "drive-removable-media-symbolic"
|
||||
elif "nvme" in dev:
|
||||
icon = "drive-harddisk-solidstate-symbolic"
|
||||
else:
|
||||
icon = "drive-harddisk-symbolic"
|
||||
|
||||
disks.append((name, dev, icon))
|
||||
return disks
|
||||
except Exception as e:
|
||||
print(f"Error getting disks: {e}")
|
||||
return []
|
||||
|
||||
Reference in New Issue
Block a user