Skip to content

Instantly share code, notes, and snippets.

@DavidAntliff
Created August 13, 2020 23:45
Show Gist options
  • Save DavidAntliff/0861470f4d9f1253740e444c76be8f85 to your computer and use it in GitHub Desktop.
Save DavidAntliff/0861470f4d9f1253740e444c76be8f85 to your computer and use it in GitHub Desktop.
Deactivate ACPI devices that may cause hibernation to fail
#!/usr/bin/env python
"""
Deactivate ACPI devices that may cause hibernation to fail
"""
from dataclasses import dataclass
import subprocess
@dataclass
class Entry:
device: str
sstate: str
status: bool
sysfs_node: str
def is_enabled(x):
return x.status
def disable_entry(device):
subprocess.call(f"/usr/bin/sudo -s /bin/bash -c 'echo {device} > /proc/acpi/wakeup'", shell=True)
def main():
with open("/proc/acpi/wakeup", "r") as f:
wakeup = f.readlines()
entries = []
for line in wakeup[1:]:
device, sstate, status_sysfs_node = map(str.strip, line.split('\t'))
t = status_sysfs_node.split()
if len(t) == 2:
status, sysfs_node = t
else:
status = status_sysfs_node
sysfs_node = None
entries.append(Entry(device, sstate, status == "*enabled", sysfs_node))
enabled = filter(is_enabled, entries)
print("Enabled entries:")
for entry in enabled:
if entry.device:
print(entry)
disable_entry(entry.device)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment