From 2c7e0f0571886ad995eba372da447a463085eb18 Mon Sep 17 00:00:00 2001 From: kermieisinthehouse Date: Thu, 11 Nov 2021 14:21:52 -0800 Subject: [PATCH] Apply python path resolution to plugins (#1990) * Symlink python3 to python * Apply path resolution to plugins --- docker/ci/x86_64/Dockerfile | 1 + pkg/plugin/raw.go | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/docker/ci/x86_64/Dockerfile b/docker/ci/x86_64/Dockerfile index 9fbe89e81..4a209d96c 100644 --- a/docker/ci/x86_64/Dockerfile +++ b/docker/ci/x86_64/Dockerfile @@ -12,6 +12,7 @@ RUN if [ "$TARGETPLATFORM" = "linux/arm/v6" ]; then BIN=stash-pi; \ FROM --platform=$TARGETPLATFORM alpine:latest AS app COPY --from=binary /stash /usr/bin/ RUN apk add --no-cache ca-certificates python3 py3-requests py3-requests-toolbelt py3-lxml py3-pip ffmpeg vips-tools && pip install --no-cache-dir mechanicalsoup cloudscraper +RUN ln -s /usr/bin/python3 /usr/bin/python ENV STASH_CONFIG_FILE=/root/.stash/config.yml EXPOSE 9999 diff --git a/pkg/plugin/raw.go b/pkg/plugin/raw.go index 780772d80..1fcc6ad87 100644 --- a/pkg/plugin/raw.go +++ b/pkg/plugin/raw.go @@ -29,6 +29,19 @@ type rawPluginTask struct { done chan bool } +func FindPythonExecutable() (string, error) { + _, err := exec.LookPath("python3") + + if err != nil { + _, err = exec.LookPath("python") + if err != nil { + return "", err + } + return "python", nil + } + return "python3", nil +} + func (t *rawPluginTask) Start() error { if t.started { return errors.New("task already started") @@ -39,6 +52,13 @@ func (t *rawPluginTask) Start() error { return fmt.Errorf("empty exec value in operation %s", t.operation.Name) } + if command[0] == "python" || command[0] == "python3" { + executable, err := FindPythonExecutable() + if err == nil { + command[0] = executable + } + } + cmd := exec.Command(command[0], command[1:]...) stdin, err := cmd.StdinPipe()