mirror of
https://github.com/jessfraz/dockerfiles.git
synced 2024-11-30 13:28:30 +01:00
d639673cf6
Signed-off-by: Jess Frazelle <acidburn@google.com>
29 lines
886 B
Python
Executable File
29 lines
886 B
Python
Executable File
#!/usr/bin/env python
|
|
|
|
# Shamelessly pasted from:
|
|
# https://serverfault.com/questions/573379/system-suspend-dbus-upower-signals-are-not-seen
|
|
|
|
from datetime import datetime
|
|
import dbus
|
|
import gobject
|
|
from dbus.mainloop.glib import DBusGMainLoop
|
|
import os
|
|
|
|
def handle_sleep(*args):
|
|
print "%s PrepareForSleep%s" % (datetime.now().ctime(), args)
|
|
if len(args)>0 and args[0]:
|
|
os.system("/buttslock.sh")
|
|
|
|
DBusGMainLoop(set_as_default=True) # integrate into gobject main loop
|
|
bus = dbus.SystemBus() # connect to system wide dbus
|
|
bus.add_signal_receiver( # define the signal to listen to
|
|
handle_sleep, # callback function
|
|
'PrepareForSleep', # signal name
|
|
'org.freedesktop.login1.Manager', # interface
|
|
'org.freedesktop.login1' # bus name
|
|
)
|
|
|
|
loop = gobject.MainLoop()
|
|
loop.run()
|
|
|