def preflight_check():
    logging.debug("pre-flight-check")
    if not check_database_environment():
        raise Exception("Missing environment variables")

    mx_version_str = runtime.get_version(BUILD_DIR)
    logging.info("Preflight check on version %s", mx_version_str)
    mx_version = MXVersion(str(mx_version_str))
    if not runtime.check_deprecation(mx_version):
        raise Exception("Version {} is deprecated.".format(mx_version_str))
def preflight_check():
    if not check_database_environment():
        raise ValueError("Missing environment variables")

    mx_version_str = runtime.get_version(BUILD_DIR)
    stack = os.getenv("CF_STACK")
    logging.info(
        "Preflight check on Mendix runtime version [%s] and stack [%s]...",
        mx_version_str,
        stack,
    )
    mx_version = MXVersion(str(mx_version_str))

    if not stack in SUPPORTED_STACKS:
        raise NotImplementedError("Stack [{}] is not supported".format(stack))
    if not runtime.check_deprecation(mx_version):
        raise NotImplementedError(
            "Mendix runtime version [{}] is not supported".format(
                mx_version_str))
    logging.info("Preflight check completed")
if __name__ == "__main__":
    logging.basicConfig(
        level=util.get_buildpack_loglevel(),
        stream=sys.stdout,
        format="%(levelname)s: %(message)s",
    )

    try:
        preflight_check()
    except (ValueError, NotImplementedError) as error:
        logging.error(error)
        exit(1)

    if is_source_push():
        logging.info("Source push detected, starting MxBuild...")
        runtime_version = runtime.get_version(BUILD_DIR)
        try:
            mxbuild.stage(
                BUILD_DIR,
                CACHE_DIR,
                DOT_LOCAL_LOCATION,
                runtime_version,
                runtime.get_java_version(runtime_version),
            )
        except RuntimeError as error:
            logging.error(error)
            exit(1)
        finally:
            for folder in ("mxbuild", "mono"):
                path = os.path.join(DOT_LOCAL_LOCATION, folder)
                shutil.rmtree(path, ignore_errors=True)