Advertisement
Guest User

Script to re-suspend laptop that wakes wandomly

a guest
Mar 30th, 2014
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import re
  4. import time
  5. import subprocess
  6. import syslog
  7.  
  8. def log(msg):
  9. syslog.syslog('lidfix: ' + msg)
  10.  
  11. def is_open():
  12. with open('/proc/acpi/button/lid/LID0/state', 'r') as f:
  13. state = f.readline()
  14. f.close()
  15.  
  16. m = re.match(r'state:\s+([a-z]+)', state)
  17.  
  18. return m.group(1) == 'open'
  19.  
  20. while True:
  21. if not is_open():
  22. time.sleep(5)
  23. if not is_open():
  24. log('Forcing suspend...')
  25. subprocess.call(['/usr/sbin/pm-suspend'])
  26. log('Done with pm-suspend.')
  27. else:
  28. log('Lid was open the second time.')
  29.  
  30. time.sleep(5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement