12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- # -*- 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
- 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.conf"):
- """reads the configuration file from the path given to the function,
- default to /etc/stdd.conf if empty"""
- self.__conffile = open(file_path, "r")
- for line in self.__conffile:
- if "#" in line:
- continue
- else:
- self.__line_stripped = line.strip()
- if self.__line_stripped != "":
- self.__tmpvalue = self.__line_stripped.split("=")
- self.__values[self.__tmpvalue[0].lower()] = self.__tmpvalue[1]
- 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)
- if self.__values["blink_colon"] == "1":
- self.blink_colon = True
- else:
- self.blink_colon = False
- self.brightness_high = int(self.__values["brightness_high"])
- self.brightness_low = int(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
|