Guest User

Untitled

a guest
Dec 13th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #!/usr/bin/python3
  2. import tty
  3. import termios
  4. import sys
  5. import subprocess
  6. out = subprocess.check_output('loginctl').decode('utf8')
  7. users = {}
  8. for line in out.splitlines():
  9. session = line[8:13].strip()
  10. user = line[22:30].strip()
  11. seat = line[39:].strip()
  12. if not user in users:
  13. users[user] = []
  14. users[user].append({'session':session, 'seat':seat})
  15. session = None
  16. for row in users['username']:
  17. if row['seat']: session = row['session']
  18. def getchar():
  19. #Returns a single character from standard input
  20. fd = sys.stdin.fileno()
  21. old_settings = termios.tcgetattr(fd)
  22. try:
  23. tty.setraw(sys.stdin.fileno())
  24. ch = sys.stdin.read(1)
  25. finally:
  26. termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
  27. return ch
  28.  
  29. print("UNLOCK <=== SWIPE ===> LOCK")
  30. while 1:
  31. c = getchar()
  32. if c == "\x01":
  33. ctrla = True
  34. elif ctrla and c == "p":
  35. subprocess.check_call("loginctl unlock-session "+session, shell=True)
  36. ctrla = False
  37. elif ctrla and c == "n":
  38. print(session)
  39. subprocess.check_call("loginctl lock-session "+session, shell=True)
  40. ctrla = False
  41. elif ctrla and c == "q":
  42. sys.exit()
  43. else:
  44. ctrla = False
Add Comment
Please, Sign In to add comment