System.py 929 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env python
  2. import configparser
  3. import sys
  4. from aman.config.Server import Server
  5. from aman.config.Weather import Weather
  6. class System:
  7. def __init__(self, filepath : str):
  8. config = configparser.ConfigParser()
  9. config.read(filepath)
  10. # search the required sections
  11. serverSectionAvailable = False
  12. for key in config:
  13. if 'SERVER' == key:
  14. serverSectionAvailable = True
  15. elif 'WEATHER' == key:
  16. weatherSectionAvailable = True
  17. if not serverSectionAvailable:
  18. sys.stderr.write('No server-configuration section found!')
  19. sys.exit(-1)
  20. if not weatherSectionAvailable:
  21. sys.stderr.write('No weather-configuration section found!')
  22. sys.exit(1)
  23. self.Server = Server(config['SERVER'])
  24. self.Weather = Weather(config['WEATHER'])