fix: playbook 支持 python 脚本
This commit is contained in:
@@ -10,6 +10,7 @@ import net.geedge.common.RCode;
|
||||
import net.geedge.common.T;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
@@ -901,11 +902,32 @@ public class AdbUtil {
|
||||
}
|
||||
|
||||
|
||||
public CommandResult execPlaybook(String playbookPath, String tid, String packageName, File logFile) {
|
||||
public CommandResult execPlaybook(String scriptPath, String tid, String packageName, String type, File logFile) {
|
||||
log.info("[execPlaybook] [begin!] [serial:{}]", this.getSerial());
|
||||
List<String> command = new AdbCommandBuilder("python")
|
||||
.buildRunPlaybook(ANDROID_LAUNCHER, playbookPath, tid, packageName, this.getSerial())
|
||||
.build();
|
||||
List<String> command;
|
||||
File environment = null;
|
||||
if (T.StrUtil.equals(type, "python")){
|
||||
// check requirements.txt
|
||||
Path parent = Paths.get(scriptPath).getParent();
|
||||
Path resolve = parent.resolve("requirements.txt");
|
||||
command = new PythonCommandBuilder("python")
|
||||
.buildRunPythonScript(scriptPath, tid, packageName, this.getSerial())
|
||||
.build();
|
||||
if (T.FileUtil.exist(resolve.toString())){
|
||||
// create venv
|
||||
environment = T.FileUtil.file(parent.toString(), "environment");
|
||||
commandExec.exec(new PythonCommandBuilder("python").buildCreateVenv(environment.getAbsolutePath()).build());
|
||||
commandExec.exec(new PythonCommandBuilder(T.StrUtil.concat(true, environment.getAbsolutePath(), "/bin/pip")).buildUpgradePip().build());
|
||||
commandExec.exec(new PythonCommandBuilder(T.StrUtil.concat(true, environment.getAbsolutePath(), "/bin/pip")).buildInstallRequirements(resolve.toString()).build());
|
||||
command = new PythonCommandBuilder(T.StrUtil.concat(true, environment.getAbsolutePath(), "/bin/python"))
|
||||
.buildRunPythonScript(scriptPath, tid, packageName, this.getSerial())
|
||||
.build();
|
||||
}
|
||||
}else {
|
||||
command = new PythonCommandBuilder("python")
|
||||
.buildRunAirScript(ANDROID_LAUNCHER, scriptPath, tid, packageName, this.getSerial())
|
||||
.build();
|
||||
}
|
||||
Process process = commandExec.execForProcess(command);
|
||||
|
||||
T.FileUtil.appendString(T.StrUtil.concat(true, "$ ", command.stream().collect(Collectors.joining(" ")), "\n"), logFile, "UTF-8");
|
||||
@@ -929,6 +951,7 @@ public class AdbUtil {
|
||||
process.destroyForcibly();
|
||||
throw new APIException(RCode.ERROR);
|
||||
}finally {
|
||||
T.FileUtil.del(environment);
|
||||
T.IoUtil.close(inputStreamReader);
|
||||
T.IoUtil.close(bufferedReader);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user