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:
@@ -28,6 +28,7 @@ type ServerConfig interface {
|
||||
GetConfigPath() string
|
||||
HasTLSConfig() bool
|
||||
GetPluginsPath() string
|
||||
GetPythonPath() string
|
||||
}
|
||||
|
||||
// Cache stores plugin details.
|
||||
@@ -167,11 +168,12 @@ func (c Cache) CreateTask(ctx context.Context, pluginID string, operationName st
|
||||
}
|
||||
|
||||
task := pluginTask{
|
||||
plugin: plugin,
|
||||
operation: operation,
|
||||
input: buildPluginInput(plugin, operation, serverConnection, args),
|
||||
progress: progress,
|
||||
gqlHandler: c.gqlHandler,
|
||||
plugin: plugin,
|
||||
operation: operation,
|
||||
input: buildPluginInput(plugin, operation, serverConnection, args),
|
||||
progress: progress,
|
||||
gqlHandler: c.gqlHandler,
|
||||
serverConfig: c.config,
|
||||
}
|
||||
return task.createTask(), nil
|
||||
}
|
||||
@@ -216,10 +218,11 @@ func (c Cache) executePostHooks(ctx context.Context, hookType HookTriggerEnum, h
|
||||
addHookContext(pluginInput.Args, hookContext)
|
||||
|
||||
pt := pluginTask{
|
||||
plugin: &p,
|
||||
operation: &h.OperationConfig,
|
||||
input: pluginInput,
|
||||
gqlHandler: c.gqlHandler,
|
||||
plugin: &p,
|
||||
operation: &h.OperationConfig,
|
||||
input: pluginInput,
|
||||
gqlHandler: c.gqlHandler,
|
||||
serverConfig: c.config,
|
||||
}
|
||||
|
||||
task := pt.createTask()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -11,6 +12,7 @@ import (
|
||||
stashExec "github.com/stashapp/stash/pkg/exec"
|
||||
"github.com/stashapp/stash/pkg/logger"
|
||||
"github.com/stashapp/stash/pkg/plugin/common"
|
||||
"github.com/stashapp/stash/pkg/python"
|
||||
)
|
||||
|
||||
type rawTaskBuilder struct{}
|
||||
@@ -30,19 +32,6 @@ 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")
|
||||
@@ -53,14 +42,26 @@ 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
|
||||
var cmd *exec.Cmd
|
||||
if python.IsPythonCommand(command[0]) {
|
||||
pythonPath := t.serverConfig.GetPythonPath()
|
||||
var p *python.Python
|
||||
if pythonPath != "" {
|
||||
p = python.New(pythonPath)
|
||||
} else {
|
||||
p, _ = python.Resolve()
|
||||
}
|
||||
|
||||
if p != nil {
|
||||
cmd = p.Command(context.TODO(), command[1:])
|
||||
}
|
||||
|
||||
// if could not find python, just use the command args as-is
|
||||
}
|
||||
|
||||
cmd := stashExec.Command(command[0], command[1:]...)
|
||||
if cmd == nil {
|
||||
cmd = stashExec.Command(command[0], command[1:]...)
|
||||
}
|
||||
|
||||
stdin, err := cmd.StdinPipe()
|
||||
if err != nil {
|
||||
|
||||
@@ -30,10 +30,11 @@ type taskBuilder interface {
|
||||
}
|
||||
|
||||
type pluginTask struct {
|
||||
plugin *Config
|
||||
operation *OperationConfig
|
||||
input common.PluginInput
|
||||
gqlHandler http.Handler
|
||||
plugin *Config
|
||||
operation *OperationConfig
|
||||
input common.PluginInput
|
||||
gqlHandler http.Handler
|
||||
serverConfig ServerConfig
|
||||
|
||||
progress chan float64
|
||||
result *common.PluginOutput
|
||||
|
||||
Reference in New Issue
Block a user