mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
Log more when resolving Python (#4185)
* Log more when resolving Python Users often have problems configuring their Python installations * Convert if-else ladder to switch statement * Consolidate Python resolution Adds additional logging to plugin tasks to align with the logging that scrapers output.
This commit is contained in:
@@ -2,9 +2,12 @@ package python
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
|
||||
stashExec "github.com/stashapp/stash/pkg/exec"
|
||||
"github.com/stashapp/stash/pkg/fsutil"
|
||||
"github.com/stashapp/stash/pkg/logger"
|
||||
)
|
||||
|
||||
type Python string
|
||||
@@ -22,19 +25,32 @@ func New(path string) *Python {
|
||||
// Resolve tries to find the python executable in the system.
|
||||
// It first checks for python3, then python.
|
||||
// Returns nil and an exec.ErrNotFound error if not found.
|
||||
func Resolve() (*Python, error) {
|
||||
_, err := exec.LookPath("python3")
|
||||
func Resolve(configuredPythonPath string) (*Python, error) {
|
||||
if configuredPythonPath != "" {
|
||||
isFile, err := fsutil.FileExists(configuredPythonPath)
|
||||
switch {
|
||||
case err == nil && isFile:
|
||||
logger.Tracef("using configured python path: %s", configuredPythonPath)
|
||||
return New(configuredPythonPath), nil
|
||||
case err == nil && !isFile:
|
||||
logger.Warnf("configured python path is not a file: %s", configuredPythonPath)
|
||||
case err != nil:
|
||||
logger.Warnf("unable to use configured python path: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
python3, err := exec.LookPath("python3")
|
||||
|
||||
if err != nil {
|
||||
_, err = exec.LookPath("python")
|
||||
python, err := exec.LookPath("python")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("python executable not in PATH: %s", err)
|
||||
}
|
||||
ret := Python("python")
|
||||
ret := Python(python)
|
||||
return &ret, nil
|
||||
}
|
||||
|
||||
ret := Python("python3")
|
||||
ret := Python(python3)
|
||||
return &ret, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user