25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

environment.py 1.5 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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