You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.6 KiB

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import os
  4. import subprocess
  5. import sys
  6. from logging import DEBUG, INFO, WARNING
  7. from doodbalib import logger, which
  8. # Call this file linked from another file called `build` or `entrypoint`
  9. mode = os.path.basename(__file__)
  10. dir_odoo = "/opt/odoo"
  11. dir_common = os.path.join(dir_odoo, "common", "%s.d" % mode)
  12. dir_custom = os.path.join(dir_odoo, "custom", "%s.d" % mode)
  13. # Find scripts
  14. files = [(d, dir_common) for d in os.listdir(dir_common)]
  15. try:
  16. files += [(d, dir_custom) for d in os.listdir(dir_custom)]
  17. except OSError:
  18. pass
  19. # Run scripts
  20. for executable, folder in sorted(files):
  21. command = os.path.join(folder, executable)
  22. if os.access(command, os.X_OK):
  23. logger.debug("Executing %s", command)
  24. subprocess.check_call(command)
  25. # Allow to omit 1st command and default to `odoo`
  26. extra_command = sys.argv[1:]
  27. if extra_command:
  28. if extra_command[0] == "shell" or extra_command[0].startswith("-"):
  29. extra_command.insert(0, "odoo")
  30. # Set the DB creation language, if needed
  31. if extra_command[0] in {"odoo", "/usr/local/bin/odoo"}:
  32. if os.environ.get("INITIAL_LANG"):
  33. from psycopg2 import OperationalError, connect
  34. try:
  35. connection = connect(dbname=os.environ.get("PGDATABASE"))
  36. connection.close()
  37. except OperationalError:
  38. # No DB exists, set initial language
  39. extra_command += ["--load-language", os.environ["INITIAL_LANG"]]
  40. if os.environ.get("PTVSD_ENABLE") == "1":
  41. # Warn deprecation
  42. logger.log(
  43. WARNING,
  44. "ptvsd has beed deprecated for python debugging. "
  45. "Please use debugpy (see https://github.com/Tecnativa/doodba#debugpy)",
  46. )
  47. # See `python -m ptvsd -h` to understand this
  48. extra_command[0] = os.path.realpath(which(extra_command[0]))
  49. extra_command = (
  50. ["python", "-m", "ptvsd"]
  51. + os.environ.get("PTVSD_ARGS", "").split()
  52. + extra_command
  53. )
  54. elif os.environ["DEBUGPY_ENABLE"] == "1":
  55. # See `python -m debugpy -h` to understand this
  56. extra_command[0] = os.path.realpath(which(extra_command[0]))
  57. extra_command = (
  58. ["python", "-m", "debugpy"]
  59. + os.environ["DEBUGPY_ARGS"].split()
  60. + extra_command
  61. )
  62. logger.log(
  63. DEBUG if extra_command[0] == "/qa/insider" else INFO,
  64. "Executing %s",
  65. " ".join(extra_command),
  66. )
  67. os.execvp(extra_command[0], extra_command)