您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

54 行
1.5 KiB

  1. #!/usr/bin/env python3
  2. # Kosmorro - Compute The Next Ephemerides
  3. # Copyright (C) 2019 Jérôme Deuchnord <jerome@deuchnord.fr>
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU Affero General Public License as
  7. # published by the Free Software Foundation, either version 3 of the
  8. # License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU Affero General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Affero General Public License
  16. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. import os
  18. import re
  19. from pathlib import Path
  20. CACHE_FOLDER = str(Path.home()) + "/.kosmorro-cache"
  21. class Environment:
  22. def __init__(self):
  23. self._vars = {}
  24. def __set__(self, key, value):
  25. self._vars[key] = value
  26. def __getattr__(self, key):
  27. return self._vars[key] if key in self._vars else None
  28. def __str__(self):
  29. return self._vars.__str__()
  30. def __len__(self):
  31. return len(self._vars)
  32. def get_env_vars() -> Environment:
  33. environment = Environment()
  34. for var in os.environ:
  35. if not re.search("^KOSMORRO_", var):
  36. continue
  37. [_, env] = var.split("_", 1)
  38. environment.__set__(env.lower(), os.getenv(var))
  39. return environment