Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import re
- import time
- import subprocess
- import syslog
- def log(msg):
- syslog.syslog('lidfix: ' + msg)
- def is_open():
- with open('/proc/acpi/button/lid/LID0/state', 'r') as f:
- state = f.readline()
- f.close()
- m = re.match(r'state:\s+([a-z]+)', state)
- return m.group(1) == 'open'
- while True:
- if not is_open():
- time.sleep(5)
- if not is_open():
- log('Forcing suspend...')
- subprocess.call(['/usr/sbin/pm-suspend'])
- log('Done with pm-suspend.')
- else:
- log('Lid was open the second time.')
- time.sleep(5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement