mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
Python path setting (#2409)
* Add python package * Add python path backend config * Add python path to system settings page * Apply python path to script scrapers and plugins
This commit is contained in:
44
pkg/python/exec.go
Normal file
44
pkg/python/exec.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package python
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os/exec"
|
||||
|
||||
stashExec "github.com/stashapp/stash/pkg/exec"
|
||||
)
|
||||
|
||||
type Python string
|
||||
|
||||
func (p *Python) Command(ctx context.Context, args []string) *exec.Cmd {
|
||||
return stashExec.CommandContext(ctx, string(*p), args...)
|
||||
}
|
||||
|
||||
// New returns a new Python instance at the given path.
|
||||
func New(path string) *Python {
|
||||
ret := Python(path)
|
||||
return &ret
|
||||
}
|
||||
|
||||
// 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")
|
||||
|
||||
if err != nil {
|
||||
_, err = exec.LookPath("python")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret := Python("python")
|
||||
return &ret, nil
|
||||
}
|
||||
|
||||
ret := Python("python3")
|
||||
return &ret, nil
|
||||
}
|
||||
|
||||
// IsPythonCommand returns true if arg is "python" or "python3"
|
||||
func IsPythonCommand(arg string) bool {
|
||||
return arg == "python" || arg == "python3"
|
||||
}
|
||||
Reference in New Issue
Block a user