YAMLLoader.py 652 B

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