microsoft/hve-core
Publicmirrored from https://github.com/microsoft/hve-coreAvailable
.github/skills/experimental/powerpoint/scripts/export-svg.sh
74lines · modecode
| 1 | #!/usr/bin/env bash |
| 2 | # Copyright (c) Microsoft Corporation. |
| 3 | # SPDX-License-Identifier: MIT |
| 4 | # |
| 5 | # export-svg.sh |
| 6 | # Export PowerPoint slides to SVG images. |
| 7 | |
| 8 | set -euo pipefail |
| 9 | |
| 10 | SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 11 | SKILL_ROOT="$(dirname "${SCRIPT_DIR}")" |
| 12 | VENV_DIR="${SKILL_ROOT}/.venv" |
| 13 | |
| 14 | SKIP_VENV_SETUP=false |
| 15 | VERBOSE=false |
| 16 | |
| 17 | err() { |
| 18 | printf "ERROR: %s\n" "$1" >&2 |
| 19 | exit 1 |
| 20 | } |
| 21 | |
| 22 | usage() { |
| 23 | cat <<EOF |
| 24 | Usage: $(basename "$0") [OPTIONS] |
| 25 | |
| 26 | Options: |
| 27 | --input <path> Input PPTX file path (required) |
| 28 | --output-dir <path> Output directory for SVG files (required) |
| 29 | --slides <list> Comma-separated slide numbers (optional) |
| 30 | --skip-venv-setup Skip virtual environment setup |
| 31 | -v, --verbose Enable verbose output |
| 32 | -h, --help Show this help message |
| 33 | EOF |
| 34 | exit 0 |
| 35 | } |
| 36 | |
| 37 | get_venv_python_path() { |
| 38 | if [[ -f "${VENV_DIR}/Scripts/python.exe" ]]; then |
| 39 | echo "${VENV_DIR}/Scripts/python.exe" |
| 40 | elif [[ -f "${VENV_DIR}/bin/python" ]]; then |
| 41 | echo "${VENV_DIR}/bin/python" |
| 42 | else |
| 43 | err "Python interpreter not found in venv. Run: uv sync --directory \"${SKILL_ROOT}\"" |
| 44 | fi |
| 45 | } |
| 46 | |
| 47 | main() { |
| 48 | local -a pass_through=() |
| 49 | |
| 50 | while (( $# > 0 )); do |
| 51 | case "$1" in |
| 52 | --skip-venv-setup) SKIP_VENV_SETUP=true; shift ;; |
| 53 | -v|--verbose) VERBOSE=true; shift ;; |
| 54 | -h|--help) usage ;; |
| 55 | *) pass_through+=("$1"); shift ;; |
| 56 | esac |
| 57 | done |
| 58 | |
| 59 | if [[ "${SKIP_VENV_SETUP}" == "false" ]]; then |
| 60 | if ! command -v uv &>/dev/null; then |
| 61 | err "uv is required but was not found on PATH." |
| 62 | fi |
| 63 | uv sync --directory "${SKILL_ROOT}" |
| 64 | fi |
| 65 | |
| 66 | local python |
| 67 | python="$(get_venv_python_path)" |
| 68 | |
| 69 | [[ "${VERBOSE:-false}" == "true" ]] && pass_through+=("-v") |
| 70 | |
| 71 | "${python}" "${SCRIPT_DIR}/export_svg.py" "${pass_through[@]}" |
| 72 | } |
| 73 | |
| 74 | main "$@" |
| 75 | |