adding the codes of systemd-boot api

This commit is contained in:
misano sads 2025-01-30 02:10:20 +03:30
parent b41bb56e32
commit 77bf094879

View file

@ -1,4 +1,6 @@
from typing import List from typing import List
from os import execv, listdir, path
import subprocess
class Entry: class Entry:
@ -7,17 +9,37 @@ class Entry:
self.entry = entry self.entry = entry
def get_icon(self) -> str: def get_icon(self) -> str:
pass # Return an icon based on the OS name
if "arch" in self.name.lower():
return "" # Arch Linux icon (using Font Awesome)
elif "ubuntu" in self.name.lower():
return "" # Ubuntu icon
elif "windows" in self.name.lower():
return "" # Windows icon
else:
return "" # Generic Linux icon
def get_os_list() -> List[Entry] : def get_os_list() -> List[Entry]:
# TODO: return a List of items entries_dir = "/boot/loader/entries/"
return [Entry("test", "test")] entries = []
if path.exists(entries_dir):
for entry_file in listdir(entries_dir):
if entry_file.endswith(".conf"):
with open(path.join(entries_dir, entry_file), 'r') as f:
first_line = f.readline().strip()
if first_line.startswith("title"):
name = first_line.split(" ", 1)[1]
entries.append(Entry(name, entry_file))
return entries
def set_boot_entry(entry: Entry): def set_boot_entry(entry: Entry):
# TODO: set a entry for next boot # Set the default boot entry using bootctl
... subprocess.run(["bootctl", "set-default", entry.entry], check=True)
def reboot(): def reboot():
# TODO: reboot system # Reboot the system
... subprocess.run(["systemctl", "reboot"], check=True)