#!/usr/bin/env python # -*- coding: utf-8 -*- import os import subprocess import sys from logging import DEBUG, INFO, WARNING from doodbalib import logger, which # Call this file linked from another file called `build` or `entrypoint` mode = os.path.basename(__file__) dir_odoo = "/opt/odoo" dir_common = os.path.join(dir_odoo, "common", "%s.d" % mode) dir_custom = os.path.join(dir_odoo, "custom", "%s.d" % mode) # Find scripts files = [(d, dir_common) for d in os.listdir(dir_common)] try: files += [(d, dir_custom) for d in os.listdir(dir_custom)] except OSError: pass # Run scripts for executable, folder in sorted(files): command = os.path.join(folder, executable) if os.access(command, os.X_OK): logger.debug("Executing %s", command) subprocess.check_call(command) # Allow to omit 1st command and default to `odoo` extra_command = sys.argv[1:] if extra_command: if extra_command[0] == "shell" or extra_command[0].startswith("-"): extra_command.insert(0, "odoo") # Set the DB creation language, if needed if extra_command[0] in {"odoo", "/usr/local/bin/odoo"}: if os.environ.get("INITIAL_LANG"): from psycopg2 import OperationalError, connect try: connection = connect(dbname=os.environ.get("PGDATABASE")) connection.close() except OperationalError: # No DB exists, set initial language extra_command += ["--load-language", os.environ["INITIAL_LANG"]] if os.environ.get("PTVSD_ENABLE") == "1": # Warn deprecation logger.log( WARNING, "ptvsd has beed deprecated for python debugging. " "Please use debugpy (see https://github.com/Tecnativa/doodba#debugpy)", ) # See `python -m ptvsd -h` to understand this extra_command[0] = os.path.realpath(which(extra_command[0])) extra_command = ( ["python", "-m", "ptvsd"] + os.environ.get("PTVSD_ARGS", "").split() + extra_command ) elif os.environ["DEBUGPY_ENABLE"] == "1": # See `python -m debugpy -h` to understand this extra_command[0] = os.path.realpath(which(extra_command[0])) extra_command = ( ["python", "-m", "debugpy"] + os.environ["DEBUGPY_ARGS"].split() + extra_command ) logger.log( DEBUG if extra_command[0] == "/qa/insider" else INFO, "Executing %s", " ".join(extra_command), ) os.execvp(extra_command[0], extra_command)