change: build python plugin

This commit is contained in:
debugtalk
2022-05-29 00:24:27 +08:00
parent 6d08f13a70
commit da608db9bb
16 changed files with 99 additions and 37 deletions

View File

@@ -5,7 +5,6 @@ import (
"os"
"os/signal"
"path/filepath"
"strings"
"syscall"
"github.com/httprunner/funplugin"
@@ -35,21 +34,6 @@ func initPlugin(path string, logOn bool) (plugin funplugin.IPlugin, pluginDir st
// TODO: move pluginDir to funplugin
pluginDir = filepath.Dir(pluginPath)
// compatible the format of debugtalk.py with v2/v3
ext := filepath.Ext(pluginPath)
if ext == ".py" {
// skip if only debugtalk_gen.py exists
if !strings.HasSuffix(pluginPath, "debugtalk_gen.py") {
genPyPluginPath := filepath.Join(pluginDir, "debugtalk_gen.py")
err = build.Run(pluginPath, genPyPluginPath)
if err != nil {
log.Error().Err(err).Msgf(fmt.Sprintf("failed to build %s", pluginPath))
return
}
pluginPath = genPyPluginPath
}
}
// found plugin file
plugin, err = funplugin.Init(pluginPath, funplugin.WithLogOn(logOn))
if err != nil {
@@ -80,7 +64,7 @@ func initPlugin(path string, logOn bool) (plugin funplugin.IPlugin, pluginDir st
}
func locatePlugin(path string) (pluginPath string, err error) {
// priority: hashicorp plugin (debugtalk.bin > debugtalk.py > debugtalk_gen.py) > go plugin (debugtalk.so)
// priority: hashicorp plugin (debugtalk.bin > debugtalk.py) > go plugin (debugtalk.so)
pluginPath, err = locateFile(path, hashicorpGoPluginFile)
if err == nil {
@@ -89,12 +73,15 @@ func locatePlugin(path string) (pluginPath string, err error) {
pluginPath, err = locateFile(path, debugtalkPyFile)
if err == nil {
return
}
pluginPath, err = locateFile(path, hashicorpPyPluginFile)
if err == nil {
return
// convert debugtalk.py to debugtalk_gen.py
// register funppy plugin
genPyPluginPath := filepath.Join(filepath.Dir(pluginPath), hashicorpPyPluginFile)
err = build.Run(pluginPath, genPyPluginPath)
if err != nil {
log.Error().Err(err).Str("path", pluginPath).Msg("build plugin failed")
return
}
return genPyPluginPath, nil
}
pluginPath, err = locateFile(path, goPluginFile)