12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- # -*- coding: utf-8-*-
- #
- # This file is part of stdd, the simple time display daemon,
- # written by Helmut Pozimski <helmut@pozimski.eu>,
- # licensed under the 3-clause BSD license
- import datetime
- import json
- class Conf(object):
- def __init__(self):
- """creates the object prepopulated with some reasonable default
- values
- """
- self.__values = {
- "hw_address": "",
- "blink_colon": "0",
- "brightness_high": "15",
- "brightness_low": "2",
- "set_brightness_low": "00:00",
- "set_brightness_high": "00:00",
- "syslog_level": "info",
- "syslog_facility": "user"
- }
- """ declare empty variables to write the checked values into """
- self.hw_address = 0
- self.blink_colon = False
- self.brightness_high = 0
- self.brightness_low = 0
- self.set_brightness_low = None
- self.set_brightness_high = None
- self.syslog_level = ""
- self.syslog_facility = ""
- def Read(self, file_path="/etc/stdd.json"):
- """reads the configuration file from the path given to the function,
- default to /etc/stdd.conf if empty"""
- self.__conffile = open(file_path, "r")
- config_read = json.load(self.__conffile)
- for value in config_read:
- if value:
- self.__values[value] = config_read[value]
- self.__conffile.close()
- def Analyze(self):
- """takes the values from the list, converts them to the needed data
- types and writes them into the prepared attributes
- """
- self.hw_address = int(self.__values["hw_address"], 16)
- self.blink_colon = self.__values["blink_colon"]
- self.brightness_high = self.__values["brightness_high"]
- self.brightness_low = self.__values["brightness_low"]
- self.__timetemp = self.__values["set_brightness_high"].split(":")
- self.set_brightness_high = datetime.time(int(self.__timetemp[0]),
- int(self.__timetemp[1]))
- self.__timetemp = self.__values["set_brightness_low"].split(":")
- self.set_brightness_low = datetime.time(int(self.__timetemp[0]),
- int(self.__timetemp[1]))
- self.syslog_level = self.__values["syslog_level"]
- self.syslog_facility = self.__values["syslog_facility"]
- del self.__values
|