Skip to content

Commit

Permalink
Merge branch 'dashboard' of https://github.com/unarxiv/cvpm into dash…
Browse files Browse the repository at this point in the history
…board
  • Loading branch information
xzyaoi committed Dec 10, 2018
2 parents b586e7d + 94d7d6a commit 4003720
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 12 deletions.
24 changes: 24 additions & 0 deletions cli/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,23 @@ func GetRunningSolversByPackageHandler(c *gin.Context) {
c.JSON(http.StatusOK, runningSolversInPackage)
}

// Handle Post Repos Request -> Install Package
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)
c.JSON(http.StatusOK, config.Repositories)
} else {
c.JSON(http.StatusBadRequest, config.Repositories)
}
}

// Handle Get Request -> Get All Repos
func GetReposHandler(c *gin.Context) {
config := readConfig()
Expand All @@ -81,6 +98,11 @@ func GetRepoMetaHandler(c *gin.Context) {
c.JSON(http.StatusOK, GetMetaInfo(vendor, name))
}

// Handle Get System Information
func GetSystemHandler(c *gin.Context) {
c.JSON(http.StatusOK, getSystemInfo())
}

// Handle Socket Request
func socketHandler(c *gin.Context) {
socketServer.On("connection", func(so socketio.Socket) {
Expand Down Expand Up @@ -144,6 +166,8 @@ func runServer(port string) {
"daemon": "running",
})
})
// System Related Handlers
r.GET("/system", GetSystemHandler)
// Repo Related Routes
r.GET("/repo/meta/:vendor/:name", GetRepoMetaHandler)
r.POST("/repo/running", PostRunningRepoHandler)
Expand Down
13 changes: 1 addition & 12 deletions cli/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,10 @@ func InstallHandler(c *cli.Context) {
} else {
color.Cyan("Installing to " + localFolder)
}
var repoFolder string
var repo Repository
// Download Codebase
if strings.HasPrefix(remoteURL, "https://github.com") {
repo = CloneFromGit(remoteURL, localFolder)
InstallFromGit(remoteURL)
}
repoFolder = repo.LocalFolder
// Install Dependencies
color.Cyan("Installing Dependencies... please wait patiently")
InstallDependencies(repoFolder)
color.Blue("Generating Runners")
GeneratingRunners(repoFolder)
color.Cyan("Adding to Local Configuration")
config.Repositories = addRepo(config.Repositories, repo)
writeConfig(config)
}

// Handle List
Expand Down
12 changes: 12 additions & 0 deletions cli/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,15 @@ func GetMetaInfo(Vendor string, Name string) RepositoryMetaInfo {
}
return repositoryMeta
}

// Install Repository from Git
func InstallFromGit(remoteURL string) {
config := readConfig()
var repo Repository
repo = CloneFromGit(remoteURL, config.Local.LocalFolder)
repoFolder := repo.LocalFolder
InstallDependencies(repoFolder)
GeneratingRunners(repoFolder)
config.Repositories = addRepo(config.Repositories, repo)
writeConfig(config)
}
30 changes: 30 additions & 0 deletions cli/system.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import (
"github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/host"
"github.com/shirou/gopsutil/mem"
)

type SystemInfo struct {
CpuName string `json:"cpu"`
Memory uint64 `json:"memory"`
Platform string `json:"platform"`
Os string `json:"os"`
PlatformVersion string `json:"platformVersion"`
}

func getSystemInfo() SystemInfo {
var systemInfo SystemInfo
v, _ := mem.VirtualMemory()
systemInfo.Memory = v.Total
platform, _ := host.Info()
systemInfo.Platform = platform.Platform
systemInfo.PlatformVersion = platform.PlatformVersion
systemInfo.Os = platform.OS

// Handle CPU
cpuInfo, _ := cpu.Info()
systemInfo.CpuName = cpuInfo[0].ModelName
return systemInfo
}

0 comments on commit 4003720

Please sign in to comment.