Browse Source

加上dvc pull

dev-DXTZYK
fanshuai 1 year ago
parent
commit
67e4c9d6ae
3 changed files with 31 additions and 2 deletions
  1. +5
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java
  2. +5
    -2
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java
  3. +21
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/DVCUtils.java

+ 5
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ModelsServiceImpl.java View File

@@ -599,6 +599,8 @@ public class ModelsServiceImpl implements ModelsService {
String relatePath = ci4sUsername + "/model/" + gitlinIid + "/" + repositoryName+ "/model"; String relatePath = ci4sUsername + "/model/" + gitlinIid + "/" + repositoryName+ "/model";


dvcUtils.gitClone(rootPath, projectUrl, branchName, gitLinkUsername, gitLinkPassword); dvcUtils.gitClone(rootPath, projectUrl, branchName, gitLinkUsername, gitLinkPassword);
//干掉目标文件夹
dvcUtils.deleteDirectory(modelPath);
dvcUtils.moveFiles(sourcePath, modelPath); dvcUtils.moveFiles(sourcePath, modelPath);


//拼接生产的元数据后写入yaml文件 //拼接生产的元数据后写入yaml文件
@@ -701,7 +703,10 @@ public class ModelsServiceImpl implements ModelsService {
// 创建本地分支 // 创建本地分支
dvcUtils.createLocalBranchBasedOnMaster(rootPath, branchName); dvcUtils.createLocalBranchBasedOnMaster(rootPath, branchName);
//dvc checkout //dvc checkout
dvcUtils.dvcPull(rootPath);
dvcUtils.dvcCheckout(rootPath); dvcUtils.dvcCheckout(rootPath);
//干掉目标文件夹
dvcUtils.deleteDirectory(modelPath);
dvcUtils.moveFiles(sourcePath, modelPath); dvcUtils.moveFiles(sourcePath, modelPath);


//拼接生产的元数据后写入yaml文件 //拼接生产的元数据后写入yaml文件


+ 5
- 2
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/NewDatasetServiceImpl.java View File

@@ -117,7 +117,8 @@ public class NewDatasetServiceImpl implements NewDatasetService {
// 命令行操作 git clone 项目地址 // 命令行操作 git clone 项目地址
dvcUtils.gitClone(localPath, projectUrl, branchName, gitLinkUsername, gitLinkPassword); dvcUtils.gitClone(localPath, projectUrl, branchName, gitLinkUsername, gitLinkPassword);
String s3Path = "management-platform-files" + "/" + relatePath + "/" + branchName; String s3Path = "management-platform-files" + "/" + relatePath + "/" + branchName;

//干掉目标文件夹
dvcUtils.deleteDirectory(datasetPath);
dvcUtils.moveFiles(sourcePath, datasetPath); dvcUtils.moveFiles(sourcePath, datasetPath);
// 拼接生产的元数据后写入yaml文件 // 拼接生产的元数据后写入yaml文件
datasetVo.setCreateBy(String.valueOf(StringUtils.isNotEmpty((String) userInfo.get("nickname")) ? userInfo.get("nickname") : userInfo.get("login"))); datasetVo.setCreateBy(String.valueOf(StringUtils.isNotEmpty((String) userInfo.get("nickname")) ? userInfo.get("nickname") : userInfo.get("login")));
@@ -188,11 +189,13 @@ public class NewDatasetServiceImpl implements NewDatasetService {
dvcUtils.createLocalBranchBasedOnMaster(localPath, branchName); dvcUtils.createLocalBranchBasedOnMaster(localPath, branchName);


//dvc checkout //dvc checkout
dvcUtils.dvcPull(localPath);
dvcUtils.dvcCheckout(localPath); dvcUtils.dvcCheckout(localPath);


// 准备数据 // 准备数据
String s3Path = "management-platform-files" + "/" + relatePath + "/" + branchName; String s3Path = "management-platform-files" + "/" + relatePath + "/" + branchName;

//干掉目标文件夹
dvcUtils.deleteDirectory(datasetPath);
dvcUtils.moveFiles(sourcePath, datasetPath); dvcUtils.moveFiles(sourcePath, datasetPath);
// 拼接生产的元数据后写入yaml文件 // 拼接生产的元数据后写入yaml文件
datasetVo.setCreateBy(String.valueOf(StringUtils.isNotEmpty((String) userInfo.get("nickname")) ? userInfo.get("nickname") : userInfo.get("login"))); datasetVo.setCreateBy(String.valueOf(StringUtils.isNotEmpty((String) userInfo.get("nickname")) ? userInfo.get("nickname") : userInfo.get("login")));


+ 21
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/utils/DVCUtils.java View File

@@ -78,6 +78,26 @@ public class DVCUtils {
Files.move(sourceDir, targetDir, StandardCopyOption.REPLACE_EXISTING); Files.move(sourceDir, targetDir, StandardCopyOption.REPLACE_EXISTING);
} }


public void deleteDirectory(String dirPath) throws IOException {
Path directory = Paths.get(dirPath);

// 检查是否目录存在
if (Files.exists(directory)) {
// 使用Files.walk来删除目录及其内容
Files.walk(directory)
.sorted((path1, path2) -> path2.compareTo(path1)) // 先删除子文件夹,再删除父文件夹
.forEach(this::deletePath);
}
}

private void deletePath(Path path) {
try {
Files.delete(path);
} catch (IOException e) {
log.error("Unable to delete: " + path + " " + e.getMessage());
}
}

public void gitClone(String localPath, String repoUrl, String branch, String username, String password) throws GitAPIException { public void gitClone(String localPath, String repoUrl, String branch, String username, String password) throws GitAPIException {
CloneCommand cloneCommand = Git.cloneRepository() CloneCommand cloneCommand = Git.cloneRepository()
.setURI(repoUrl) .setURI(repoUrl)
@@ -419,6 +439,7 @@ public class DVCUtils {


// 切换分支 // 切换分支
gitCheckoutBranch(localPath, branch); gitCheckoutBranch(localPath, branch);
dvcPull(localPath);
dvcCheckout(localPath); dvcCheckout(localPath);
} }




Loading…
Cancel
Save