Skip to content

Commit

Permalink
[DeviceManager]
Browse files Browse the repository at this point in the history
* add new setting to show/hide unknown devices
* refactor disable/activate devices
* fix swapon typo
* improve details
  • Loading branch information
jbleyel committed Jan 11, 2025
1 parent 4faefcf commit 476a362
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 38 deletions.
1 change: 1 addition & 0 deletions data/setup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@
<item level="0" text="Hard disk standby after" description="Configure the hard disk drive to go to standby after the specified idle time.">config.usage.hdd_standby</item>
<item level="0" text="Hard disk standby in box standby after" description="Configure the hard disk drive to go to standby after the specified idle time when the box is in standby.">config.usage.hdd_standby_in_standby</item>
<item level="0" text="Use Harddisk Hardware Standby Timer" description="Option to enable the Hardware Standby Timer.">config.usage.hdd_timer</item>
<item level="2" text="Show unknown devices" description="Enable this option to show unknown storage devices in device manager.">config.usage.showUnknownDevices</item>
</setup>
<setup key="HDMICEC" title="HDMI-CEC Settings">
<item level="0" text="Enabled" description="Enable or disable using HDMI-CEC.">config.hdmicec.enabled</item>
Expand Down
1 change: 1 addition & 0 deletions lib/python/Components/UsageConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ def showsecondinfobarChanged(configElement):
config.usage.hdd_standby = ConfigSelection(default="300", choices=choiceList)
config.usage.hdd_standby_in_standby = ConfigSelection(default="-1", choices=[("-1", _("Same as in active"))] + choiceList)
config.usage.hdd_timer = ConfigYesNo(default=False)
config.usage.showUnknownDevices = ConfigYesNo(default=False)
config.usage.output_12V = ConfigSelection(default="do not change", choices=[
("do not change", _("Do not change")),
("off", _("Off")),
Expand Down
94 changes: 56 additions & 38 deletions lib/python/Screens/DeviceManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class StorageDeviceAction(Setup):
ACTION_WIPE = 4
ACTION_FORMAT = 5
ACTION_LABEL = 6
ACTION_IGNORE = 7
ACTION_ACTIVATE = 8

def __init__(self, session, storageDevice, action, actionText):
self.storageDevice = storageDevice
Expand Down Expand Up @@ -290,7 +292,7 @@ def alphanumKey(s):
unknownList.append(deviceData)
if config.crash.debugStorage.value:
print(f"[DeviceManager] DEBUG deviceList:\n{deviceList}\nunknownList:\n{unknownList}")
return deviceList, unknownList
return deviceList, unknownList if config.usage.showUnknownDevices.value else []

def createDevice(self, device, isPartition, mounts, swapDevices, partitions, knownDevices, fstab):
def getDeviceTypeModel():
Expand Down Expand Up @@ -388,10 +390,12 @@ def getDeviceTypeModel():
fstabMountPoint = fstabData[0]

description = []
if not isPartition:
if isPartition:
description.append(f"{_("Mount point")}: {mountP}\t{_("File system")}: {fsType}")
else:
description.append(f"{_("Path")}: {physdev}")
if deviceLocation:
description.append(f"{_("Position")}: {deviceLocation}")
if deviceLocation:
description.append(f"{_("Position")}: {deviceLocation}")
description = "\n".join(description)
deviceData = {
"name": model,
Expand Down Expand Up @@ -443,7 +447,7 @@ class DeviceManager(Screen):

MOUNT = "/bin/mount"
UMOUNT = "/bin/umount"
SWAPON = "/sbin/swapom"
SWAPON = "/sbin/swapon"
SWAPOFF = "/sbin/swapoff"

LIST_SELECTION = 0
Expand Down Expand Up @@ -531,7 +535,9 @@ def __init__(self, session):
"menu": (self.keyMenu, _("Hard Disk Settings")),
"red": (self.close, _("Close the Device Manager screen")),
"green": (self.keyActions, _("Select an action for the current device")),
"yellow": (self.keyMountPoints, _("Select a permanent mount point for all devices")),
"yellow": (self.keyMountPoints, _("Select a permanent mount point for all devices"))
}, prio=0, description=_("Device Manager Actions"))
self["blueActions"] = HelpableActionMap(self, ["ColorActions"], {
"blue": (self.keyBlue, _("Toggle a temporary mount for the current device"))
}, prio=0, description=_("Device Manager Actions"))
self.needReboot = False
Expand Down Expand Up @@ -610,21 +616,22 @@ def selectionChanged(self):
description = ""
self["key_green"].setText(_("Action"))
if storageDevice.get("FlashExpander"):
self["key_blue"].setText("")
blueText = ""
elif storageDevice.get("fsType") == "swap":
self["key_blue"].setText(_("Off") if storageDevice.get("swapState") else _("On"))
blueText = _("Off") if storageDevice.get("swapState") else _("On")
elif storageDevice.get("isPartition"):
if storageDevice.get("fstabMountPoint"):
self["key_blue"].setText("")
elif ":None" in storageDevice.get("knownDevice"):
self["key_blue"].setText(_("Activate"))
if storageDevice.get("fstabMountPoint") or ":None" in storageDevice.get("knownDevice"):
blueText = ""
else:
self["key_blue"].setText(_("Unmount") if storageDevice.get("isMounted") else _("Mount"))
blueText = _("Unmount") if storageDevice.get("isMounted") else _("Mount")
elif storageDevice.get("isUnknown"):
self["key_blue"].setText("")
blueText = ""
self["key_green"].setText(_("Remove"))
else:
self["key_blue"].setText("")
blueText = ""

self["blueActions"].setEnabled(blueText != "")
self["key_blue"].setText(blueText)

for callback in self.onChangedEntry:
if callback and callable(callback):
Expand Down Expand Up @@ -700,6 +707,7 @@ def checkMount(data, retVal, extraArgs):
current = self["devicelist"].getCurrent()
if current:
storageDevice = current[self.LIST_DATA]
knownDevice = storageDevice.get("knownDevice")
if storageDevice.get("fsType") == "swap":
def swapCallback(data, retVal, extraArgs):
if retVal:
Expand All @@ -709,29 +717,22 @@ def swapCallback(data, retVal, extraArgs):
self.updateDevices()
command = self.SWAPOFF if storageDevice.get("swapState") else self.SWAPON
self.console.ePopen([command, command, storageDevice.get("devicePoint")], swapCallback)
elif storageDevice.get("isPartition") and not storageDevice.get("fstabMountPoint"):
knownDevice = storageDevice.get("knownDevice")
if ":None" in knownDevice:
knownDevices = fileReadLines("/etc/udev/known_devices", [], source=MODULE_NAME)
if knownDevice in knownDevices:
knownDevices.remove(knownDevice)
fileWriteLines("/etc/udev/known_devices", knownDevices, source=MODULE_NAME)
elif storageDevice.get("isPartition") and not (storageDevice.get("fstabMountPoint") or ":None" in knownDevice):
devicePoint = storageDevice.get("devicePoint")
if storageDevice.get("isMounted"):
self.console.ePopen([self.UMOUNT, self.UMOUNT, storageDevice.get("mountPoint")])
mounts = getProcMountsNew()
for parts in mounts:
if parts[1] == storageDevice.get("mountPoint"):
self.session.open(MessageBox, _("Can't unmount partition, make sure it is not being used for swap or record/time shift paths"), MessageBox.TYPE_INFO)
cleanMediaDirs()
else:
devicePoint = storageDevice.get("devicePoint")
if storageDevice.get("isMounted"):
self.console.ePopen([self.UMOUNT, self.UMOUNT, storageDevice.get("mountPoint")])
mounts = getProcMountsNew()
for parts in mounts:
if parts[1] == storageDevice.get("mountPoint"):
self.session.open(MessageBox, _("Can't unmount partition, make sure it is not being used for swap or record/time shift paths"), MessageBox.TYPE_INFO)
cleanMediaDirs()
else:
title = _("Select the new mount point for: '%s'") % storageDevice.get("model")
fstab = fileReadLines("/etc/fstab", default=[], source=MODULE_NAME)
label = storageDevice.get("label")
device = storageDevice.get("device")
choiceList = [(f"/media/{x}", f"/media/{x}") for x in self.storageDevices.getMountPoints(storageDevice.get("deviceType"), fstab, onlyPossible=True) + [device, label]]
self.session.openWithCallback(keyBlueCallback, ChoiceBox, choiceList=choiceList, buttonList=[], windowTitle=title)
title = _("Select the new mount point for: '%s'") % storageDevice.get("model")
fstab = fileReadLines("/etc/fstab", default=[], source=MODULE_NAME)
label = storageDevice.get("label")
device = storageDevice.get("device")
choiceList = [(f"/media/{x}", f"/media/{x}") for x in self.storageDevices.getMountPoints(storageDevice.get("deviceType"), fstab, onlyPossible=True) + [device, label]]
self.session.openWithCallback(keyBlueCallback, ChoiceBox, choiceList=choiceList, buttonList=[], windowTitle=title)
self.updateDevices()

def updateDevices(self):
Expand Down Expand Up @@ -825,7 +826,18 @@ def keyActionsCallback(action):
self.currentAction = action
options = {"debug": True} if config.crash.debugStorage.value else {}
if action:
if action == StorageDeviceAction.ACTION_LABEL:
if action == StorageDeviceAction.ACTION_IGNORE:
knownDevices = fileReadLines("/etc/udev/known_devices", [], source=MODULE_NAME)
knownDevices = [item for item in knownDevices if storageDevice.UUID not in item]
knownDevices.append(f"{storageDevice.UUID}:None")
fileWriteLines("/etc/udev/known_devices", knownDevices, source=MODULE_NAME)
self.updateDevices()
elif action == StorageDeviceAction.ACTION_ACTIVATE:
knownDevices = fileReadLines("/etc/udev/known_devices", [], source=MODULE_NAME)
knownDevices = [item for item in knownDevices if storageDevice.UUID not in item]
fileWriteLines("/etc/udev/known_devices", knownDevices, source=MODULE_NAME)
self.updateDevices()
elif action == StorageDeviceAction.ACTION_LABEL:
self.session.openWithCallback(renameCallback, VirtualKeyBoard, title=_("Please enter the new name:"), text=storageDevice.label)
elif action in (StorageDeviceAction.ACTION_FORMAT, StorageDeviceAction.ACTION_INITIALIZE):
self.session.openWithCallback(keyActionsSetupCallback, StorageDeviceAction, storageDevice, action, _("Format Storage Device"))
Expand Down Expand Up @@ -883,6 +895,12 @@ def keyActionsCallback(action):
choiceList.append((_("Convert file system ext3 to ext4"), StorageDeviceAction.ACTION_EXT4CONVERSION))
if "ntfs" not in storageDevice.fsType and storageDevice.fsType in fileSystems: # NTFS not supported yet becaue you need to unmount
choiceList.append((_("Rename"), StorageDeviceAction.ACTION_LABEL))

if storageDevice.UUID:
if ":None" in storageDevice.knownDevice:
choiceList.append((_("Activate this device"), StorageDeviceAction.ACTION_ACTIVATE))
else:
choiceList.append((_("Permanently ignore this device"), StorageDeviceAction.ACTION_IGNORE))
else:
choiceList = [
(_("Cancel"), 0),
Expand Down

0 comments on commit 476a362

Please sign in to comment.