configuration.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # This file is part of jwmud, written by Helmut Pozimski in 2014.
  2. #
  3. # jwmud is free software: you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation, version 2 of the License.
  6. #
  7. # jwmud is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License
  13. # along with jwmud. If not, see <http://www.gnu.org/licenses/>.
  14. # -*- coding: utf8 -*-
  15. from jwmudlib import jwmu_exceptions
  16. class conf(object):
  17. def __init__(self, file_path="/etc/jwmud.conf"):
  18. """Constructor, creates the object and prepopulates the dictionary
  19. that stores the configuration values.
  20. """
  21. self.values = {
  22. "syslog_level": "info",
  23. "syslog_facility": "user",
  24. "alarm_script": None
  25. }
  26. self.__file_path = file_path
  27. def Read(self):
  28. """Reads the configuration file and puts the data into the
  29. dictionary.
  30. """
  31. try:
  32. conf_file = open(self.__file_path, "r")
  33. except FileNotFoundError:
  34. raise jwmu_exceptions.ConfigurationFileMissing()
  35. except PermissionError:
  36. raise jwmu_exceptions.ConfigurationFileAccessDenied()
  37. else:
  38. for line in conf_file:
  39. if "#" in line:
  40. continue
  41. else:
  42. line_stripped = line.strip()
  43. if line_stripped != "":
  44. tmp_value = line_stripped.split("=")
  45. self.values[tmp_value[0].lower()] = tmp_value[1]
  46. conf_file.close()