From d92033c979ddbfd97d3edbe1aed67f030e252a8a Mon Sep 17 00:00:00 2001 From: chrys Date: Mon, 4 Jun 2018 07:53:24 +0200 Subject: [PATCH] make ignorescreen more useable --- tools/addScreenToIgnoreList.py | 26 ----------------- tools/fenrir-ignore-screen.py | 43 +++++++++++++++++++++++++++++ tools/fenrir-unignore-screen.py | 43 +++++++++++++++++++++++++++++ tools/removeScreenFromIgnoreList.py | 26 ----------------- 4 files changed, 86 insertions(+), 52 deletions(-) delete mode 100755 tools/addScreenToIgnoreList.py create mode 100755 tools/fenrir-ignore-screen.py create mode 100755 tools/fenrir-unignore-screen.py delete mode 100755 tools/removeScreenFromIgnoreList.py diff --git a/tools/addScreenToIgnoreList.py b/tools/addScreenToIgnoreList.py deleted file mode 100755 index 57aa9f37..00000000 --- a/tools/addScreenToIgnoreList.py +++ /dev/null @@ -1,26 +0,0 @@ -#!/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/fenrir-ignore-screen.py b/tools/fenrir-ignore-screen.py new file mode 100755 index 00000000..c70a4e36 --- /dev/null +++ b/tools/fenrir-ignore-screen.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 +import os, argparse + +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]) + if not screen: + print('No screen given.') + 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__": + parser = argparse.ArgumentParser(description='Ignore screens in fenrir. If no screen is given use current screen.') + parser.add_argument('-s', '--screen', metavar='SCREEN', default=None, help='Ignore a given screen. Use current screen as default.') + parser.add_argument('-f', '--file', metavar='File', default='/tmp/fenrirSuspend', help='Specify the suspendingScreenFile') + try: + args = parser.parse_args() + ignoreFileName = args.file + useCurrentScreen = False + screen = None + print(args.file) + if args.screen: + screen = args.screen + else: + useCurrentScreen = True + addScreenToIgnoreList(ignoreFileName, screen, useCurrentScreen) + except Exception as e: + parser.print_help() diff --git a/tools/fenrir-unignore-screen.py b/tools/fenrir-unignore-screen.py new file mode 100755 index 00000000..be3faee2 --- /dev/null +++ b/tools/fenrir-unignore-screen.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 +import os, argparse + +def removeScreenFromIgnoreList(ignoreFileName = '/tmp/fenrirSuspend', screen = '1', useCurrentScreen = True): + if useCurrentScreen: + tty = open('/sys/devices/virtual/tty/tty0/active','r') + screen = str(tty.read()[3:-1]) + if not screen: + print('No screen given.') + 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__": + parser = argparse.ArgumentParser(description='Unignore screens in fenrir to make it active again. If no screen is given use current screen.') + parser.add_argument('-s', '--screen', metavar='SCREEN', default=None, help='Ignore a given screen. Use current screen as default.') + parser.add_argument('-f', '--file', metavar='File', default='/tmp/fenrirSuspend', help='Specify the suspendingScreenFile') + try: + args = parser.parse_args() + ignoreFileName = args.file + useCurrentScreen = False + screen = None + print(args.file) + if args.screen: + screen = args.screen + else: + useCurrentScreen = True + removeScreenFromIgnoreList(ignoreFileName, screen, useCurrentScreen) + except Exception as e: + parser.print_help() diff --git a/tools/removeScreenFromIgnoreList.py b/tools/removeScreenFromIgnoreList.py deleted file mode 100755 index c755246d..00000000 --- a/tools/removeScreenFromIgnoreList.py +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/python -import os - -def removeScreenFromIgnoreList(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__": - removeScreenFromIgnoreList()