fix: playbook 支持 python 脚本
This commit is contained in:
@@ -268,11 +268,12 @@ public class APIController {
|
||||
public R execPlaybook(@RequestParam("file") MultipartFile file,
|
||||
@RequestParam("packageName") String packageName,
|
||||
@RequestParam("id") String id,
|
||||
@RequestParam("type") String type,
|
||||
@RequestParam("reInstall") Boolean reInstall,
|
||||
@RequestParam("clearCache") Boolean clearCache,
|
||||
@RequestParam("unInstall") Boolean unInstall) {
|
||||
File apkFile = null;
|
||||
File playbookAirDir = null;
|
||||
File scriptPath = null;
|
||||
File destination = null;
|
||||
try {
|
||||
File playbookDir = T.FileUtil.file(Constant.TEMP_PATH, id);
|
||||
@@ -299,14 +300,24 @@ public class APIController {
|
||||
})).findFirst().get();
|
||||
|
||||
// unzip playbook zip
|
||||
T.ZipUtil.unzip(playbook, playbookDir);
|
||||
playbookAirDir = Arrays.stream(playbookDir.listFiles(new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(File pathname) {
|
||||
return pathname.getName().endsWith(".air");
|
||||
}
|
||||
})).findFirst().get();
|
||||
|
||||
if (T.StrUtil.equals(type, "python")){
|
||||
playbookDir = T.FileUtil.file(Constant.TEMP_PATH, id, "main");
|
||||
T.ZipUtil.unzip(playbook, playbookDir);
|
||||
scriptPath = Arrays.stream(playbookDir.listFiles(new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(File pathname) {
|
||||
return pathname.getName().equals("main.py");
|
||||
}
|
||||
})).findFirst().get();
|
||||
}else {
|
||||
T.ZipUtil.unzip(playbook, playbookDir);
|
||||
scriptPath = Arrays.stream(playbookDir.listFiles(new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(File pathname) {
|
||||
return pathname.getName().endsWith(".air");
|
||||
}
|
||||
})).findFirst().get();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
throw new APIException(RCode.ERROR);
|
||||
@@ -314,7 +325,7 @@ public class APIController {
|
||||
T.FileUtil.del(destination);
|
||||
}
|
||||
|
||||
PlaybookRunnable playbookRunnable = new PlaybookRunnable(apiYml, apkFile, playbookAirDir, id, packageName, reInstall, clearCache, unInstall);
|
||||
PlaybookRunnable playbookRunnable = new PlaybookRunnable(apiYml, apkFile, scriptPath, id, packageName, type, reInstall, clearCache, unInstall);
|
||||
ThreadUtil.execAsync(playbookRunnable);
|
||||
return R.ok();
|
||||
}
|
||||
@@ -391,7 +402,7 @@ public class APIController {
|
||||
File playbookDir = Arrays.stream(jobResult.listFiles(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return name.endsWith(".air");
|
||||
return name.endsWith(".air") || name.equals("main");
|
||||
}
|
||||
})).toList().getFirst();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user