YAMLLoader.py 653 B

1234567891011121314151617181920212223242526
  1. import os
  2. import yaml
  3. class YAMLFileNotFound(Exception):
  4. pass
  5. class YAMLLoader:
  6. def __init__(self, yaml_file):
  7. self.file = yaml_file
  8. def get_config(self):
  9. """
  10. Load settings file
  11. :return: cfg : the configuration file
  12. """
  13. # Load settings.
  14. __location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
  15. try:
  16. with open(os.path.join(__location__, self.file)) as ymlfile:
  17. cfg = yaml.load(ymlfile)
  18. return cfg
  19. except IOError:
  20. raise YAMLFileNotFound("The file path %s does not exist" % self.file)