adding the codes of systemd-boot api
This commit is contained in:
parent
b41bb56e32
commit
77bf094879
1 changed files with 30 additions and 8 deletions
|
@ -1,4 +1,6 @@
|
|||
from typing import List
|
||||
from os import execv, listdir, path
|
||||
import subprocess
|
||||
|
||||
|
||||
class Entry:
|
||||
|
@ -7,17 +9,37 @@ class Entry:
|
|||
self.entry = entry
|
||||
|
||||
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] :
|
||||
# TODO: return a List of items
|
||||
return [Entry("test", "test")]
|
||||
def get_os_list() -> List[Entry]:
|
||||
entries_dir = "/boot/loader/entries/"
|
||||
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):
|
||||
# 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():
|
||||
# TODO: reboot system
|
||||
...
|
||||
# Reboot the system
|
||||
subprocess.run(["systemctl", "reboot"], check=True)
|
||||
|
|
Loading…
Add table
Reference in a new issue