Apply python path resolution to plugins (#1990)

* Symlink python3 to python
* Apply path resolution to plugins
This commit is contained in:
kermieisinthehouse 2021-11-11 14:21:52 -08:00 committed by GitHub
parent a7ed0a7004
commit 2c7e0f0571
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -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

View File

@ -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()