示例#1
0
文件: init.go 项目: kien8995/judger
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()
}
示例#2
0
文件: fis.go 项目: dw250100785/blog-1
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)
		}
	}
}
示例#3
0
文件: config.go 项目: elago/elapen
func initConfig() {
	customConfigExist := com.FileExist("custom/app.ini")
	if customConfigExist {
		ela.SetConfig("custom/app.ini")
		global.Install = false
	} else {
		global.Install = true
		configForInstall()
	}

	global.Config = ela.GetConfig()
}
示例#4
0
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
}
示例#5
0
func (this *InstallController) Get() {
	o := orm.NewOrm()

	if com.FileExist("install.lock") {
		this.Abort("404")
	} else {
		sqls := com.ReadFile("etc/blog.sql")
		sqlArr := strings.Split(sqls, ";")
		for index, element := range sqlArr {
			this.Ctx.WriteString(fmt.Sprintf("[%d] ", index) + element)
			_, err := o.Raw(element).Exec()
			if err != nil {
				this.Ctx.WriteString(" ~~ ERROR!\n")
			}
		}
		utils.WriteFile("install.lock", " ")
	}
}
示例#6
0
文件: sql.go 项目: dw250100785/blog-1
func InitSql() {
	user := beego.AppConfig.String("mysqluser")
	passwd := beego.AppConfig.String("mysqlpass")
	host := beego.AppConfig.String("mysqlurls")
	port, err := beego.AppConfig.Int("mysqlport")
	dbname := beego.AppConfig.String("mysqldb")
	if nil != err {
		port = 3306
	}

	orm.Debug = true

	if com.FileExist("install.lock") {
		orm.RegisterDataBase("default", "mysql", fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8", user, passwd, host, port, dbname))
	} else {
		orm.RegisterDataBase("default", "mysql", fmt.Sprintf("%s:%s@tcp(%s:%d)/?charset=utf8", user, passwd, host, port))
	}

}
示例#7
0
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)
	}

}
示例#8
0
文件: template.go 项目: elago/ela
func SetTemplateDir(dir string) {
	exist := com.FileExist(dir)
	if exist {
		templatefolder = dir
	}
}