__init__.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import logging
  2. from os import environ, path
  3. from dotenv import load_dotenv
  4. env = load_dotenv()
  5. APP_ROOT = path.dirname(path.realpath(__file__))
  6. """
  7. SMTP server for sending email. For a dummy server that just echoes the
  8. messages, run: `python -m smtpd -n -c DebuggingServer localhost:1025`
  9. and set SMTP_HOST to "localhost".
  10. The default is None in which causes the feedback form to be disabled.
  11. """
  12. SMTP_HOST = environ.get("TXL_SMTP_HOST")
  13. with open(path.join(path.dirname(APP_ROOT), "VERSION")) as fh:
  14. version_info = fh.readlines()
  15. GIT_TAG = version_info[0].strip()
  16. GIT_COMMIT = version_info[1].strip()
  17. logging.basicConfig(
  18. # filename=environ.get("TXL_LOGFILE", "/dev/stdout"),
  19. level=environ.get("TXL_LOGLEVEL", logging.WARN))
  20. logger = logging.getLogger(__name__)
  21. if not env:
  22. logger.warn("No .env file found. Assuming env was passed externally.")
  23. if SMTP_HOST:
  24. try:
  25. SMTP_PORT = int(environ.get("TXL_SMTP_PORT", "1025"))
  26. except ValueError:
  27. raise SystemError("TXL_SMTP_PORT env var is not an integer.")
  28. EMAIL_FROM = environ["TXL_EMAIL_FROM"]
  29. EMAIL_TO = environ["TXL_EMAIL_TO"]
  30. else:
  31. logger.warn("No SMTP host defined. Feedback form won't be available.")
  32. SMTP_PORT = EMAIL_FROM = EMAIL_TO = None