From 551c699a9f6a0c2757a50645a79b08c732ab2bb2 Mon Sep 17 00:00:00 2001 From: chrys Date: Tue, 13 Mar 2018 23:43:22 +0100 Subject: [PATCH] add rudimentary tools to add/remove the current session to ignorefile --- tools/addScreenToIgnoreList.py | 26 ++++++++++++++++++++++++++ tools/removeScreenFromIgnoreList.py | 26 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100755 tools/addScreenToIgnoreList.py create mode 100755 tools/removeScreenFromIgnoreList.py diff --git a/tools/addScreenToIgnoreList.py b/tools/addScreenToIgnoreList.py new file mode 100755 index 00000000..57aa9f37 --- /dev/null +++ b/tools/addScreenToIgnoreList.py @@ -0,0 +1,26 @@ +#!/bin/python +import os + +def addScreenToIgnoreList(ignoreFileName = '/tmp/fenrirSuspend', screen = '1', useCurrentScreen = True): + if useCurrentScreen: + tty = open('/sys/devices/virtual/tty/tty0/active','r') + screen = str(tty.read()[3:-1]) + ignoreScreens = [] + ignoreScreensStr = '' + if ignoreFileName != '': + if os.access(ignoreFileName, os.R_OK): + with open(ignoreFileName, 'r') as fp: + try: + ignoreScreens = fp.read().split(',')#.replace('\n','').split(',') + except Exception as e: + print(e) + + if not screen in ignoreScreens: + ignoreScreens.extend(screen) + ignoreScreensStr = ','.join(ignoreScreens) + + with open(ignoreFileName, 'w') as fp: + fp.write(ignoreScreensStr) + +if __name__ == "__main__": + addScreenToIgnoreList() diff --git a/tools/removeScreenFromIgnoreList.py b/tools/removeScreenFromIgnoreList.py new file mode 100755 index 00000000..163c5928 --- /dev/null +++ b/tools/removeScreenFromIgnoreList.py @@ -0,0 +1,26 @@ +#!/bin/python +import os + +def addScreenToIgnoreList(ignoreFileName = '/tmp/fenrirSuspend', screen = '1', useCurrentScreen = True): + if useCurrentScreen: + tty = open('/sys/devices/virtual/tty/tty0/active','r') + screen = str(tty.read()[3:-1]) + ignoreScreens = [] + ignoreScreensStr = '' + if ignoreFileName != '': + if os.access(ignoreFileName, os.R_OK): + with open(ignoreFileName, 'r') as fp: + try: + ignoreScreens = fp.read().split(',')#.replace('\n','').split(',') + except Exception as e: + print(e) + + if screen in ignoreScreens: + ignoreScreens.remove(screen) + ignoreScreensStr = ','.join(ignoreScreens) + + with open(ignoreFileName, 'w') as fp: + fp.write(ignoreScreensStr) + +if __name__ == "__main__": + addScreenToIgnoreList()