# This file is part of jwmud, written by Helmut Pozimski in 2014. # # jwmud is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, version 2 of the License. # # jwmud is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with jwmud. If not, see . # -*- coding: utf8 -*- from jwmudlib import jwmu_exceptions class conf(object): def __init__(self, file_path="/etc/jwmud.conf"): """Constructor, creates the object and prepopulates the dictionary that stores the configuration values. """ self.values = { "syslog_level": "info", "syslog_facility": "user", "alarm_script": None } self.__file_path = file_path def Read(self): """Reads the configuration file and puts the data into the dictionary. """ try: conf_file = open(self.__file_path, "r") except FileNotFoundError: raise jwmu_exceptions.ConfigurationFileMissing() except PermissionError: raise jwmu_exceptions.ConfigurationFileAccessDenied() else: for line in conf_file: if "#" in line: continue else: line_stripped = line.strip() if line_stripped != "": tmp_value = line_stripped.split("=") self.values[tmp_value[0].lower()] = tmp_value[1] conf_file.close()