- Get devices from /dev/disc/ (udev symlinks) - Also check direct devices: /dev/sr0, /dev/cdrom, /dev/dvd - Use udevadm to detect device type (cd/dvd/bluray) - Extract model and serial for better identification
This commit is contained in:
+44
-1
@@ -136,6 +136,7 @@ async def get_devices():
|
||||
devices = []
|
||||
|
||||
try:
|
||||
# 1. Zuerst Symlinks in /dev/disc/ prüfen
|
||||
result = subprocess.run(
|
||||
["ls", "-la", "/dev/disc/"],
|
||||
capture_output=True,
|
||||
@@ -155,7 +156,49 @@ async def get_devices():
|
||||
path=f"/dev/disc/{name}",
|
||||
status="ready"
|
||||
))
|
||||
except Exception:
|
||||
|
||||
# 2. Direkte Geräte /dev/sr0, /dev/cdrom prüfen
|
||||
import os
|
||||
direct_devices = ['/dev/sr0', '/dev/cdrom', '/dev/dvd']
|
||||
for device_path in direct_devices:
|
||||
if os.path.exists(device_path):
|
||||
# Prüfen ob es ein block device ist
|
||||
import stat
|
||||
mode = os.stat(device_path).st_mode
|
||||
if stat.S_ISBLK(mode):
|
||||
# Geräte-Info aus udevadm holen
|
||||
result = subprocess.run(
|
||||
["udevadm", "info", "-q", "property", "-n", device_path],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=5
|
||||
)
|
||||
info = {}
|
||||
for line in result.stdout.strip().split('\n'):
|
||||
if '=' in line:
|
||||
key, value = line.split('=', 1)
|
||||
info[key] = value
|
||||
|
||||
device_type = "dvd"
|
||||
if info.get("ID_CDROM_BD") == "1":
|
||||
device_type = "bluray"
|
||||
elif info.get("ID_CDROM_CD") == "1":
|
||||
device_type = "cd"
|
||||
|
||||
model = info.get("ID_MODEL", "Laufwerk")
|
||||
serial = info.get("ID_SERIAL", "unknown")
|
||||
|
||||
devices.append(Device(
|
||||
id=f"{model}_{serial}".replace(" ", "_"),
|
||||
name=model,
|
||||
type=device_type,
|
||||
path=device_path,
|
||||
status="ready",
|
||||
serial=serial,
|
||||
model=model
|
||||
))
|
||||
except Exception as e:
|
||||
print(f"Fehler beim Lesen der Geräte: {e}")
|
||||
pass
|
||||
|
||||
return devices
|
||||
|
||||
Reference in New Issue
Block a user