// 创建编译环境的目录结构 func (this *Compile) createDirs(id int, sid string) error { var err error err = nil this.userBuildPath = filepath.Join(this.buildPath, sid) if !com.PathExist(this.userBuildPath) { err = com.Mkdir(this.userBuildPath) } this.itemBuildPath = filepath.Join(this.userBuildPath, fmt.Sprintf("%d", id)) if !com.PathExist(this.itemBuildPath) { err = com.Mkdir(this.itemBuildPath) } return err }
func createDirs(path string) { createPath := "" pathArr := strings.Split(path, "/") for i := 0; i < len(pathArr); i++ { createPath = createPath + pathArr[i] + "/" if !com.FileExist(createPath) { com.Mkdir(createPath) } } }
func createBuildDir() error { var err error err = nil buildPath := filepath.Join(C.Get(runtime.GOOS, "buildpath")) if !com.PathExist(buildPath) { err = com.Mkdir(buildPath) } return err }
func Judger() { parseArg() dataPath := "data.db" if Mode == "docker" { log.Blueln("[mode]", "docker") if !com.FileExist("/data") { if err := com.Mkdir("/data"); err != nil { log.Warnln("[Warn]", "create dir /data failed") } else { log.Blueln("[info]", "create dir /data") } } if !com.FileExist("/data/config_docker.ini") { com.CopyFile("/data/config_docker.ini", "conf/config_docker.ini") } if !com.FileExist("/data/executer.json") { com.CopyFile("/data/executer.json", "sandbox/c/build/executer.json") } dataPath = "/data/data.db" } if configFile == "" { configFile = "conf/config.ini" } if !com.FileExist(configFile) { log.Dangerln("[Error]", configFile, "does not exist!") os.Exit(-1) } log.Blueln("[config]") log.Blueln(configFile) C = &Config{} C.NewConfig(configFile) GenScript() log.Blueln("[data]") log.Blueln(dataPath) DB = &Sqlite{} DB.NewSqlite(dataPath) createBuildDir() go TcpStart() HttpStart() }
func githubStat() error { if !com.FileExist("static") { com.Mkdir("static") } else { if com.FileExist("static/upload") { com.Mkdir("static/upload") } } token := beego.AppConfig.String("github_token") user := beego.AppConfig.String("github_user") json, err := statistics.GetRepos(user, token) if err != nil { return err } stat := beego.AppConfig.String("github_statistics") err = com.WriteFile(stat, json) return err }
func TestSession(t *testing.T) { Convey("Test Session sections", t, func() { com.Mkdir("tmp") sess := NewSession("tmp") path := sess.getPath("ABCDEFGHIJKLMNOPQRST") So(path, ShouldEqual, filepath.Join("tmp", "A", "BC", "DEFGHIJKLMNOPQRST")) sess.Set("ABCDEFGHIJKLMNOPQRST", "key", "ABCDEFGHIJKLMNOPQRST") sess.Set("ABCDEFGHIJKLMNOPQRST", "number", 123456) obj, _ := sess.Get("ABCDEFGHIJKLMNOPQRST", "key") number, _ := sess.Get("ABCDEFGHIJKLMNOPQRST", "number") So(obj.(string), ShouldEqual, "ABCDEFGHIJKLMNOPQRST") So(number.(int), ShouldEqual, 123456) }) }
func GenScript() { currentPath, _ := os.Getwd() gccWin := `"%s\bin\%s.exe" %%1 -g3 -I"%s\include" -L"%s\lib" -g3 1> BUILD.LOG 2>&1 echo %%ERRORLEVEL%% > BUILDRESULT` gccNix := `%s $1 1> BUILD.LOG 2>&1 echo $? > BUILDRESULT` var gccScript string var gppScript string if !com.FileExist("script") { com.Mkdir("script") } if runtime.GOOS == "windows" { gccWinPath := C.Get(runtime.GOOS, "gcc_path") gccScript = fmt.Sprintf(gccWin, gccWinPath, "gcc", gccWinPath, gccWinPath) gppScript = fmt.Sprintf(gccWin, gccWinPath, "g++", gccWinPath, gccWinPath) runWin := `"` + filepath.Join(currentPath, C.Get(runtime.GOOS, "executer_path")) + `" -t=%1 -m=%2 %3` com.WriteFile(C.Get(runtime.GOOS, "compiler_c"), gccScript) com.WriteFile(C.Get(runtime.GOOS, "compiler_cpp"), gppScript) com.WriteFile(C.Get(runtime.GOOS, "run_script"), runWin) } else { gccScript = fmt.Sprintf(gccNix, "gcc") gppScript = fmt.Sprintf(gccNix, "g++") runNix := filepath.Join(currentPath, C.Get(runtime.GOOS, "executer_path")) + ` -t=$1 -m=$2 $3 -c=` + C.Get(runtime.GOOS, "executer_config") com.WriteFile(C.Get(runtime.GOOS, "compiler_c"), gccScript) com.WriteFile(C.Get(runtime.GOOS, "compiler_cpp"), gppScript) com.WriteFile(C.Get(runtime.GOOS, "run_script"), runNix) os.Chmod(C.Get(runtime.GOOS, "compiler_c"), 0755) os.Chmod(C.Get(runtime.GOOS, "compiler_cpp"), 0755) os.Chmod(C.Get(runtime.GOOS, "run_script"), 0755) } }