提交 d5f654d0 authored 作者: 吕本才's avatar 吕本才

增加python3脚本

上级 d217e568
......@@ -40,7 +40,12 @@ public class BuildCommand {
List<String> cmdArr = new ArrayList<>();
if(System.getProperty("os.name").toLowerCase().contains("linux") ||
System.getProperty("os.name").toLowerCase().contains("mac")){
cmdArr.add("python");
// 检测是否有python3 优先使用python3
if (SystemUtils.isCommandAvailable("python3")) {
cmdArr.add("python3");
} else {
cmdArr.add("python");
}
}else{
cmdArr.add("C:\\Python27\\python.exe");
}
......@@ -71,7 +76,9 @@ public class BuildCommand {
if (incrementType != null && replaceParam != null) {
if (IncrementTypeEnum.TIME.getCode() == incrementType) {
if (doc.length() > 0) doc.append(DataXConstant.SPLIT_SPACE);
if (doc.length() > 0) {
doc.append(DataXConstant.SPLIT_SPACE);
}
String replaceParamType = tgParam.getReplaceParamType();
if (StringUtils.isBlank(replaceParamType) || replaceParamType.equals("Timestamp")) {
......@@ -90,7 +97,9 @@ public class BuildCommand {
} else if (IncrementTypeEnum.ID.getCode() == incrementType) {
long startId = tgParam.getStartId();
long endId = tgParam.getEndId();
if (doc.length() > 0) doc.append(DataXConstant.SPLIT_SPACE);
if (doc.length() > 0){
doc.append(DataXConstant.SPLIT_SPACE);
}
doc.append(DataXConstant.PARAMS_CM).append(DataXConstant.TRANSFORM_QUOTES).append(String.format(replaceParam, startId, endId));
doc.append(DataXConstant.TRANSFORM_QUOTES);
}
......@@ -99,7 +108,9 @@ public class BuildCommand {
if (incrementType != null && IncrementTypeEnum.PARTITION.getCode() == incrementType) {
if (StringUtils.isNotBlank(partitionStr)) {
List<String> partitionInfo = Arrays.asList(partitionStr.split(SPLIT_COMMA));
if (doc.length() > 0) doc.append(DataXConstant.SPLIT_SPACE);
if (doc.length() > 0) {
doc.append(DataXConstant.SPLIT_SPACE);
}
doc.append(DataXConstant.PARAMS_CM).append(DataXConstant.TRANSFORM_QUOTES).append(String.format(DataXConstant.PARAMS_CM_V_PT, buildPartition(partitionInfo))).append(DataXConstant.TRANSFORM_QUOTES);
}
}
......
......@@ -6,6 +6,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
/**
* @author maokeluo
......@@ -38,4 +39,16 @@ public class SystemUtils {
LOGGER.info("DATAX_HOME:{}", DATAX_HOME);
return DATAX_HOME;
}
public static boolean isCommandAvailable(String python3) {
try {
return new ProcessBuilder(python3, "-c", "\"\"\"\"")
.redirectErrorStream(true).start().waitFor() == 0;
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论