Update partitioning.py
This commit is contained in:
@@ -54,14 +54,7 @@ def get_total_memory() -> int:
|
||||
return int(parts[1]) * 1024
|
||||
return 0
|
||||
|
||||
|
||||
def calculate_auto_partitions(disk_device):
|
||||
"""
|
||||
Generates an automatic partition layout.
|
||||
- 2GB EFI (or 1GB if disk < required)
|
||||
- Root (Rest)
|
||||
- RAM + 2GB Swap (at end) (or 0 if disk < required)
|
||||
"""
|
||||
disk_size = 0
|
||||
try:
|
||||
# Get disk size in bytes
|
||||
@@ -126,11 +119,12 @@ def get_total_memory() -> int:
|
||||
"size": f"{root_size / (1024**3):.1f} GB",
|
||||
"bytes": root_size,
|
||||
"style_class": "part-root",
|
||||
}
|
||||
},
|
||||
]
|
||||
|
||||
if use_swap:
|
||||
partitions.append({
|
||||
partitions.append(
|
||||
{
|
||||
"type": "partition",
|
||||
"name": "Swap",
|
||||
"filesystem": "swap",
|
||||
@@ -138,7 +132,8 @@ def get_total_memory() -> int:
|
||||
"size": f"{swap_size / (1024**3):.1f} GB",
|
||||
"bytes": swap_size,
|
||||
"style_class": "part-swap",
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
return partitions
|
||||
|
||||
@@ -464,22 +459,41 @@ class PartitioningPage(Adw.Bin):
|
||||
menu_box.append(btn)
|
||||
|
||||
if data.get("type") == "partition":
|
||||
add_menu_item("Select Mount Point", "folder-open-symbolic",
|
||||
lambda: self.select_mount_point(data))
|
||||
add_menu_item(
|
||||
"Select Mount Point",
|
||||
"folder-open-symbolic",
|
||||
lambda: self.select_mount_point(data),
|
||||
)
|
||||
separator = Gtk.Separator()
|
||||
menu_box.append(separator)
|
||||
add_menu_item("Delete", "user-trash-symbolic",
|
||||
lambda: self.delete_part(data), destructive=True)
|
||||
add_menu_item(
|
||||
"Delete",
|
||||
"user-trash-symbolic",
|
||||
lambda: self.delete_part(data),
|
||||
destructive=True,
|
||||
)
|
||||
|
||||
elif data.get("type") == "empty":
|
||||
add_menu_item("Create Partition", "list-add-symbolic",
|
||||
lambda: self.create_part_dialog(data))
|
||||
add_menu_item(
|
||||
"Create Partition",
|
||||
"list-add-symbolic",
|
||||
lambda: self.create_part_dialog(data),
|
||||
)
|
||||
|
||||
popover.popup()
|
||||
|
||||
def select_mount_point(self, data):
|
||||
win = Adw.Window(title="Select Mount Point", modal=True, transient_for=self.get_root())
|
||||
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=12, margin_top=24, margin_bottom=24, margin_start=24, margin_end=24)
|
||||
win = Adw.Window(
|
||||
title="Select Mount Point", modal=True, transient_for=self.get_root()
|
||||
)
|
||||
box = Gtk.Box(
|
||||
orientation=Gtk.Orientation.VERTICAL,
|
||||
spacing=12,
|
||||
margin_top=24,
|
||||
margin_bottom=24,
|
||||
margin_start=24,
|
||||
margin_end=24,
|
||||
)
|
||||
win.set_content(box)
|
||||
|
||||
options = ["/", "/boot/efi", "[SWAP]", "None"]
|
||||
@@ -511,9 +525,11 @@ class PartitioningPage(Adw.Bin):
|
||||
win.present()
|
||||
|
||||
def delete_part(self, data):
|
||||
from ...backend.disk import delete_partition
|
||||
# Extract partition number from name (e.g., nvme0n1p3 -> 3)
|
||||
import re
|
||||
|
||||
from ...backend.disk import delete_partition
|
||||
|
||||
match = re.search(r"(\d+)$", data["name"])
|
||||
if match:
|
||||
part_num = int(match.group(1))
|
||||
@@ -521,8 +537,17 @@ class PartitioningPage(Adw.Bin):
|
||||
self.load_partitions(self.current_disk_path)
|
||||
|
||||
def create_part_dialog(self, data):
|
||||
win = Adw.Window(title="Create Partition", modal=True, transient_for=self.get_root())
|
||||
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=12, margin_top=24, margin_bottom=24, margin_start=24, margin_end=24)
|
||||
win = Adw.Window(
|
||||
title="Create Partition", modal=True, transient_for=self.get_root()
|
||||
)
|
||||
box = Gtk.Box(
|
||||
orientation=Gtk.Orientation.VERTICAL,
|
||||
spacing=12,
|
||||
margin_top=24,
|
||||
margin_bottom=24,
|
||||
margin_start=24,
|
||||
margin_end=24,
|
||||
)
|
||||
win.set_content(box)
|
||||
|
||||
# Type dropdown
|
||||
@@ -547,6 +572,7 @@ class PartitioningPage(Adw.Bin):
|
||||
|
||||
def on_create(b):
|
||||
from ...backend.disk import create_partition
|
||||
|
||||
selected_type = type_names[type_dropdown.get_selected()]
|
||||
|
||||
# Default name and fstype based on type
|
||||
@@ -573,7 +599,9 @@ class PartitioningPage(Adw.Bin):
|
||||
type_code = types[selected_type]
|
||||
|
||||
try:
|
||||
create_partition(self.current_disk_path, size_mb, type_code, name, fstype)
|
||||
create_partition(
|
||||
self.current_disk_path, size_mb, type_code, name, fstype
|
||||
)
|
||||
win.close()
|
||||
self.load_partitions(self.current_disk_path)
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user