#!/usr/bin/env bash

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PYTHON_SCRIPT="${SCRIPT_DIR}/convert_json_to_json.py"
DEFAULT_DEV_PYTHON="/deeplearning_team/ydong/dongying/miniconda/envs/dev/bin/python"
PYTHON_BIN="${PYTHON_BIN:-}"

if [[ -z "${PYTHON_BIN}" ]]; then
    if [[ -x "${DEFAULT_DEV_PYTHON}" ]]; then
        PYTHON_BIN="${DEFAULT_DEV_PYTHON}"
    else
        PYTHON_BIN="python3"
    fi
fi

if [[ $# -lt 1 ]]; then
    echo "Usage: $0 <json_root> [extra args...]"
    echo "Example: $0 /data1/dongying/Mono3d/G1M3/Testdata_0129/"
    exit 1
fi

JSON_ROOT="$1"
shift

"${PYTHON_BIN}" "${PYTHON_SCRIPT}" --json-root "${JSON_ROOT}" "$@"
