Created
November 11, 2018 09:16
-
-
Save vigliag/9e5428eaadd5e1418526f65b3f26ccb3 to your computer and use it in GitHub Desktop.
This script simulates user activity, preventing automated suspension, if any file is begin accessed through samba server. Works on Plasma 5.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python3 | |
# This script simulates user activity, preventing automated suspension, if any file is begin accessed through samba server. | |
# works on Plasma 5, and, AFAIK, not Gnome | |
# based on https://bbs.archlinux.org/viewtopic.php?pid=1797228#p1797228 | |
# | |
# Uses smbstatus (which requires root permissions) to find if samba is locking some file or directory. | |
# Do not run with sudo (wouldn't be able to connect to the SessionBus), instead | |
# add smbstatus to the sudoers file, to allow running it without password, for example: | |
# username ALL = (ALL) NOPASSWD: /usr/bin/smbstatus | |
# | |
# Put this script in $HOME/bin/ and add it to KDE's startup applications | |
import os | |
import subprocess | |
from dbus import SessionBus | |
import time | |
import sys | |
POLL_LOCKED_FILES_INTERVAL = 15 #minutes | |
def smb_locked(): | |
p = subprocess.run(["sudo", "smbstatus", "-nbL"], check=True, capture_output=True) | |
out = p.stdout.decode("utf-8") | |
smb_clients = filter(None,out.split("\n")[3:]) | |
return list(smb_clients) | |
def keep_active(): | |
print("keeping active") | |
session = SessionBus() | |
screensaver = session.get_object('org.freedesktop.ScreenSaver', '/org/freedesktop/ScreenSaver') | |
screensaver.SimulateUserActivity() | |
def main(): | |
print("keep-active started") | |
try: | |
while True: | |
if smb_locked(): | |
keep_active() | |
time.sleep(60* POLL_LOCKED_FILES_INTERVAL) | |
except KeyboardInterrupt: | |
sys.exit() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment