Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] virtual environment #262

Merged
merged 1 commit into from
Mar 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cli/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ func delRepo(repos []Repository, Vendor string, Name string) []Repository {
func runRepo(Vendor string, Name string, Solver string, Port string) {
repos := readRepos()
existed := false
for _, existed_repo := range repos {
if existed_repo.Name == Name && existed_repo.Vendor == Vendor {
files, _ := ioutil.ReadDir(existed_repo.LocalFolder)
for _, existedRepo := range repos {
if existedRepo.Name == Name && existedRepo.Vendor == Vendor {
files, _ := ioutil.ReadDir(existedRepo.LocalFolder)
for _, file := range files {
if file.Name() == "runner_"+Solver+".py" {
existed = true
RunningRepos = append(RunningRepos, Repository{Vendor, Name, Solver, Port, ""})
RunningSolvers = append(RunningSolvers, RepoSolver{Vendor: Vendor, Package: Name, SolverName: Solver, Port: Port})
runfileFullPath := filepath.Join(existed_repo.LocalFolder, file.Name())
runfileFullPath := filepath.Join(existedRepo.LocalFolder, file.Name())
python([]string{runfileFullPath, Port})
}
}
Expand Down
17 changes: 13 additions & 4 deletions cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func isRoot() bool {
}

func getDirSizeMB(path string) float64 {
var dirSize int64 = 0
var dirSize int64
readSize := func(path string, file os.FileInfo, err error) error {
if !file.IsDir() {
dirSize += file.Size()
Expand All @@ -71,7 +71,7 @@ func isPortOpen(port string, timeout time.Duration) bool {
}

func findNextOpenPort(port int) string {
var hasFound bool = false
var hasFound = false
var strPort string
for ; !hasFound; port++ {
strPort = strconv.Itoa(port)
Expand All @@ -84,11 +84,20 @@ func findNextOpenPort(port int) string {

func readFileContent(filename string) string {
var content string
byte_content, err := ioutil.ReadFile(filename)
byteContent, err := ioutil.ReadFile(filename)
if err != nil {
content = "Read " + filename + "Failed!"
} else {
content = string(byte_content)
content = string(byteContent)
}
return content
}

func isStringInSlice(a string, list []string) bool {
for _, b := range list {
if b == a {
return true
}
}
return false
}
31 changes: 30 additions & 1 deletion cli/virtual.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,35 @@
* This file handles virtual environment for engine to use.
* It is designed to support different virtual environment frameworks, for now,
* it support:
* Venv & Docker
* Venv, Supported
* Docker, Planned but not supported yet.
*/
package main

// Constants
// SUPPORTEDVIRTUALENV declares all supported virtual environment method
var SUPPORTEDVIRTUALENV = []string{"venv"}

// VirtualEnv defines how a Virtual Environment works.
type VirtualEnv struct {
Name string // Name can be 'venv'
RelativePythonPath string
RelativePipPath string
IsEnabled bool
RepositoryFolder string
}

func (virtualenv VirtualEnv) validate() bool {
if isStringInSlice(virtualenv.Name, SUPPORTEDVIRTUALENV) {
return true
}
return false
}

func (virtualenv VirtualEnv) initiate() {
python([]string{"-m", "venv", virtualenv.RepositoryFolder})
}

func (virtualenv VirtualEnv) triggerEnable() {

}