Skip to content

Commit

Permalink
optimize for dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
xzyaoi committed Dec 10, 2018
1 parent 94d7d6a commit ef486b5
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
12 changes: 12 additions & 0 deletions cli/config.go
Expand Up @@ -105,6 +105,18 @@ func validateConfig() {
log.Fatal(err)
}
}
// create logs folder
logsFolder := filepath.Join(cvpmPath, "logs")
exist, err = isPathExists(logsFolder)
if err != nil {
log.Fatal(err)
}
if !exist {
err = os.Mkdir(logsFolder, os.ModePerm)
if err != nil {
log.Fatal(err)
}
}
// check if system log file exists
cvpmLogPath := filepath.Join(cvpmPath, "logs", "system.log")
exist, err = isPathExists(cvpmLogPath)
Expand Down
18 changes: 10 additions & 8 deletions cli/daemon.go
Expand Up @@ -69,16 +69,18 @@ func GetRunningSolversByPackageHandler(c *gin.Context) {
}

// Handle Post Repos Request -> Install Package
type addRepoRequest struct {
RepoType string `json:type`
URL string `json:url`
type AddRepoRequest struct {
RepoType string `json:"type"`
URL string `json:"url"`
}

func PostReposHandler(c *gin.Context) {
config := readConfig()
var _addRepoRequest addRepoRequest
c.BindJSON(&_addRepoRequest)
if (_addRepoRequest.RepoType == "git") {
InstallFromGit(_addRepoRequest.URL)
var addRepoRequest AddRepoRequest
c.BindJSON(&addRepoRequest)
log.Println(addRepoRequest.RepoType)
if addRepoRequest.RepoType == "git" {
InstallFromGit(addRepoRequest.URL)
c.JSON(http.StatusOK, config.Repositories)
} else {
c.JSON(http.StatusBadRequest, config.Repositories)
Expand Down Expand Up @@ -173,7 +175,7 @@ func runServer(port string) {
r.POST("/repo/running", PostRunningRepoHandler)
r.GET("/repos", GetReposHandler)
r.GET("/repos/running", GetRunningReposHandler)

r.POST("/repos", PostReposHandler)
// Solver Related Routers
r.GET("/solvers/running", GetRunningSolversHandler)
r.GET("/solvers/running/:vendor/:package", GetRunningSolversByPackageHandler)
Expand Down
4 changes: 2 additions & 2 deletions cli/handler.go
Expand Up @@ -50,9 +50,9 @@ func InstallHandler(c *cli.Context) {
config := readConfig()
localFolder := config.Local.LocalFolder
remoteURL := c.Args().Get(0)
if remoteURL == "cvpm:test" {
if remoteURL == "cvpm:py" {
color.Cyan("Installing... Please wait patiently")
pip([]string{"install", "--index-url", "https://test.pypi.org/simple/", "cvpm", "--user"})
pip([]string{"install", "cvpm", "--user"})
return
} else {
color.Cyan("Installing to " + localFolder)
Expand Down
17 changes: 16 additions & 1 deletion cli/repository.go
Expand Up @@ -133,6 +133,20 @@ func GeneratingRunners(localFolder string) {
}

// After Installation
func PostInstallation(repoFolder string) {
// Create pretrained folder
preTrainedFolder := filepath.Join(repoFolder, "pretrained")
exist, err := isPathExists(preTrainedFolder)
if err != nil {
log.Fatal(err)
}
if !exist {
err = os.Mkdir(preTrainedFolder, os.ModePerm)
if err != nil {
log.Fatal(err)
}
}
}

// Return Repository Meta Info: Dependency, Config, Disk Size and Readme
func GetMetaInfo(Vendor string, Name string) RepositoryMetaInfo {
Expand Down Expand Up @@ -170,10 +184,11 @@ func GetMetaInfo(Vendor string, Name string) RepositoryMetaInfo {
func InstallFromGit(remoteURL string) {
config := readConfig()
var repo Repository
repo = CloneFromGit(remoteURL, config.Local.LocalFolder)
repo = CloneFromGit(remoteURL, config.Local.LocalFolder)
repoFolder := repo.LocalFolder
InstallDependencies(repoFolder)
GeneratingRunners(repoFolder)
config.Repositories = addRepo(config.Repositories, repo)
writeConfig(config)
PostInstallation(repoFolder)
}

0 comments on commit ef486b5

Please sign in to comment.