|
@@ -21,9 +21,6 @@ import argparse
|
|
|
import json
|
|
import json
|
|
|
import logging
|
|
import logging
|
|
|
|
|
|
|
|
-log = logging.getLogger("kbdLED")
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
class kbdLED_class:
|
|
class kbdLED_class:
|
|
|
|
|
|
|
@@ -38,7 +35,7 @@ class kbdLED_class:
|
|
|
sysfs_color_fp='/sys/devices/platform/tuxedo_keyboard/leds/rgb:kbd_backlight/multi_intensity',
|
|
sysfs_color_fp='/sys/devices/platform/tuxedo_keyboard/leds/rgb:kbd_backlight/multi_intensity',
|
|
|
sysfs_bri_fp='/sys/devices/platform/tuxedo_keyboard/leds/rgb:kbd_backlight/brightness'):
|
|
sysfs_bri_fp='/sys/devices/platform/tuxedo_keyboard/leds/rgb:kbd_backlight/brightness'):
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+ self.log = log
|
|
|
self.config = {"sysfs" :
|
|
self.config = {"sysfs" :
|
|
|
{
|
|
{
|
|
|
"color" : sysfs_color_fp ,
|
|
"color" : sysfs_color_fp ,
|
|
@@ -46,11 +43,11 @@ class kbdLED_class:
|
|
|
},
|
|
},
|
|
|
"state" : kbd_state_fp}
|
|
"state" : kbd_state_fp}
|
|
|
|
|
|
|
|
- #DEBUGprint("debug: " + str(self.config))
|
|
|
|
|
|
|
+ self.log.debug(str(self.config))
|
|
|
|
|
|
|
|
if cmd=="start":
|
|
if cmd=="start":
|
|
|
self.readStateFile(self.config['state'])
|
|
self.readStateFile(self.config['state'])
|
|
|
- #print("debug: " + str(self.config))
|
|
|
|
|
|
|
+ self.log.debug(str(self.config))
|
|
|
self.writeColor()
|
|
self.writeColor()
|
|
|
self.writeBrightness()
|
|
self.writeBrightness()
|
|
|
|
|
|
|
@@ -75,9 +72,9 @@ class kbdLED_class:
|
|
|
self.config = json.load(kbd_state_fh)
|
|
self.config = json.load(kbd_state_fh)
|
|
|
|
|
|
|
|
except FileNotFoundError:
|
|
except FileNotFoundError:
|
|
|
- print("keine Statusdatei gefunden, nutze Standardwerte")
|
|
|
|
|
|
|
+ self.log.error("keine Statusdatei gefunden, nutze Standardwerte")
|
|
|
except PermissionError:
|
|
except PermissionError:
|
|
|
- print("Fehler beim lesen")
|
|
|
|
|
|
|
+ self.log.error("Fehler beim lesen")
|
|
|
|
|
|
|
|
def writeStateFile(self,kbd_state_fp):
|
|
def writeStateFile(self,kbd_state_fp):
|
|
|
try:
|
|
try:
|
|
@@ -85,7 +82,7 @@ class kbdLED_class:
|
|
|
json.dump(self.config,kbd_state_fh)
|
|
json.dump(self.config,kbd_state_fh)
|
|
|
|
|
|
|
|
except FileNotFoundError:
|
|
except FileNotFoundError:
|
|
|
- print("Verzeichnis nicht gefunden")
|
|
|
|
|
|
|
+ self.log.error("Verzeichnis oder Datei nicht gefunden")
|
|
|
|
|
|
|
|
# color String nach Config Dict
|
|
# color String nach Config Dict
|
|
|
def color2dict(self,color_string):
|
|
def color2dict(self,color_string):
|
|
@@ -105,10 +102,10 @@ class kbdLED_class:
|
|
|
self.color2dict(fh.read())
|
|
self.color2dict(fh.read())
|
|
|
|
|
|
|
|
except FileNotFoundError:
|
|
except FileNotFoundError:
|
|
|
- print("- fehler beim Öffnen der Sysfs Datei " + self.config['sysfs']['color'])
|
|
|
|
|
|
|
+ self.log.error("fehler beim Öffnen der Sysfs Datei " + self.config['sysfs']['color'])
|
|
|
sys.exit(1)
|
|
sys.exit(1)
|
|
|
except PermissionError:
|
|
except PermissionError:
|
|
|
- print("- keine Rechte die Datei zu lesen " + self.config['sysfs']['color'])
|
|
|
|
|
|
|
+ self.log.error("keine Rechte die Datei zu lesen " + self.config['sysfs']['color'])
|
|
|
sys.exit(1)
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
@@ -122,11 +119,11 @@ class kbdLED_class:
|
|
|
fh.close()
|
|
fh.close()
|
|
|
|
|
|
|
|
except FileNotFoundError:
|
|
except FileNotFoundError:
|
|
|
- print("- fehler beim Schreiben der Sysfs Datei " + self.config['sysfs']['color'])
|
|
|
|
|
|
|
+ self.log.error("fehler beim Schreiben der Sysfs Datei " + self.config['sysfs']['color'])
|
|
|
sys.exit(1)
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
except PermissionError:
|
|
except PermissionError:
|
|
|
- print("- keine Rechte die Datei zu schreiben " + self.config['sysfs']['color'])
|
|
|
|
|
|
|
+ self.log.error("keine Rechte die Datei zu schreiben " + self.config['sysfs']['color'])
|
|
|
sys.exit(1)
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# reads Brightness from sysfs
|
|
# reads Brightness from sysfs
|
|
@@ -136,10 +133,10 @@ class kbdLED_class:
|
|
|
self.config['Brightness'] = int(fh.read())
|
|
self.config['Brightness'] = int(fh.read())
|
|
|
|
|
|
|
|
except FileNotFoundError:
|
|
except FileNotFoundError:
|
|
|
- print("- fehler beim Öffnen der Sysfs Datei " + self.config['sysfs']['bri'])
|
|
|
|
|
|
|
+ self.log.error("fehler beim Öffnen der Sysfs Datei " + self.config['sysfs']['bri'])
|
|
|
sys.exit(1)
|
|
sys.exit(1)
|
|
|
except PermissionError:
|
|
except PermissionError:
|
|
|
- print("- keine Rechte die Datei zu lesen " + self.config['sysfs']['bri'])
|
|
|
|
|
|
|
+ self.log.error("keine Rechte die Datei zu lesen " + self.config['sysfs']['bri'])
|
|
|
sys.exit(1)
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# writes Brightness to sysfs
|
|
# writes Brightness to sysfs
|
|
@@ -152,33 +149,42 @@ class kbdLED_class:
|
|
|
fh.close()
|
|
fh.close()
|
|
|
|
|
|
|
|
except FileNotFoundError:
|
|
except FileNotFoundError:
|
|
|
- print("- fehler beim Schreiben der Sysfs Datei " + self.config['sysfs']['bri'])
|
|
|
|
|
|
|
+ self.log.error("- fehler beim Schreiben der Sysfs Datei " + self.config['sysfs']['bri'])
|
|
|
sys.exit(1)
|
|
sys.exit(1)
|
|
|
except PermissionError:
|
|
except PermissionError:
|
|
|
- print("- keine Rechte die Datei zu schreiben " + self.config['sysfs']['bri'])
|
|
|
|
|
|
|
+ self.log.error("- keine Rechte die Datei zu schreiben " + self.config['sysfs']['bri'])
|
|
|
sys.exit(1)
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
# Press the green button in the gutter to run the script.
|
|
# Press the green button in the gutter to run the script.
|
|
|
|
|
+# noinspection aK
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
|
|
|
|
|
|
|
|
+ #https: // argparse.readthedocs.io
|
|
|
parser = argparse.ArgumentParser(
|
|
parser = argparse.ArgumentParser(
|
|
|
prog='T1500_KeyboardLED',
|
|
prog='T1500_KeyboardLED',
|
|
|
description='saves and restore LED Colors',
|
|
description='saves and restore LED Colors',
|
|
|
epilog='GPL')
|
|
epilog='GPL')
|
|
|
|
|
+ output = parser.add_mutually_exclusive_group(required=False)
|
|
|
|
|
+ output.add_argument('--verbose', action='store_true', help='extended logging', required=False)
|
|
|
|
|
+ output.add_argument('--debug', action='store_true', help='debug output', required=False)
|
|
|
|
|
+
|
|
|
startstop = parser.add_mutually_exclusive_group()
|
|
startstop = parser.add_mutually_exclusive_group()
|
|
|
startstop.add_argument('--start', action='store_true', help='will be used for system starts')
|
|
startstop.add_argument('--start', action='store_true', help='will be used for system starts')
|
|
|
startstop.add_argument('--stop', action='store_true', help='will be used for system shutdowns')
|
|
startstop.add_argument('--stop', action='store_true', help='will be used for system shutdowns')
|
|
|
- startstop.add_argument('--verbose', action='store_true', help='extended Logging')
|
|
|
|
|
- startstop.add_argument('--debug', action='store_true', help='debugging information')
|
|
|
|
|
startstop.add_argument('--version', action='version', version='%(prog)s ' + ver, default='d')
|
|
startstop.add_argument('--version', action='version', version='%(prog)s ' + ver, default='d')
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
if args.verbose:
|
|
if args.verbose:
|
|
|
- log.setLevel(logging.INFO)
|
|
|
|
|
- if args.debug:
|
|
|
|
|
- log.setLevel(logging.DEBUG)
|
|
|
|
|
|
|
+ logging.basicConfig(level=logging.INFO)
|
|
|
|
|
+ elif args.debug:
|
|
|
|
|
+ logging.basicConfig(level=logging.DEBUG)
|
|
|
|
|
+ else:
|
|
|
|
|
+ logging.basicConfig(level=logging.ERROR)
|
|
|
|
|
+
|
|
|
|
|
+ logging.basicConfig(format='%(asctime)s %(message)s')
|
|
|
|
|
+ log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
if args.start:
|
|
if args.start:
|
|
|
print("Keyboard: read and set Color and Brightness")
|
|
print("Keyboard: read and set Color and Brightness")
|