Utils.py 859 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import yaml
  2. import os
  3. def get_settings():
  4. """
  5. Load settings.yml file
  6. :return:
  7. """
  8. filename = "settings.yml"
  9. return _load_yaml_file(filename)
  10. def get_brain():
  11. """
  12. Load brain.yml file
  13. :return:
  14. """
  15. filename = "../brain.yml"
  16. return _load_yaml_file(filename)
  17. def _load_yaml_file(file_to_load):
  18. """
  19. Load settings file
  20. :return:
  21. """
  22. # Load settings. Will be used to convert slot number into GPIO pin number
  23. __location__ = os.path.realpath(
  24. os.path.join(os.getcwd(), os.path.dirname(__file__)))
  25. with open(os.path.join(__location__, file_to_load)) as ymlfile:
  26. cfg = yaml.load(ymlfile)
  27. return cfg
  28. def my_import(name):
  29. components = name.split('.')
  30. mod = __import__(components[0])
  31. for comp in components[1:]:
  32. mod = getattr(mod, comp)
  33. return mod