/
dbus_replaylocks.py
42 lines (36 loc) · 1.21 KB
/
dbus_replaylocks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
# This program reacts on "Replaying" dbus messages of the dbus2vdr plugin for VDR.
# If a recording on a different filesystem than the VDRDIR's filesystem is played,
# the index file of this recording is opened until replay has been stopped.
# This prevents unwanted umounts by autofs inacitivty timeouts, if the replay
# is paused too long.
import dbus
import dbus2vdr
import os
from gi.repository import GObject
from dbus.mainloop.glib import DBusGMainLoop
last_file = None
vdrdir = '/srv/vdr/video'
def on_Replay(*args, **kwargs):
name, path, status, *_ = args
global last_file
if status:
if not os.lstat(path).st_dev == os.lstat(vdrdir).st_dev:
last_file = open(os.path.join(path, "index"), 'r')
else:
cleanup()
def cleanup(*args, **kwargs):
global last_file
try:
last_file.close()
except:
pass
finally:
last_file = None
if __name__ == '__main__':
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
DBusGMainLoop(set_as_default=True)
vdr = dbus2vdr.DBus2VDR(dbus.SystemBus(), watchdog=True)
vdr.onSignal("Replaying", on_Replay)
vdr.onSignal("Stop", cleanup)
GObject.MainLoop().run()