Пример #1
0
func init() {
	wd, err := os.Getwd()
	if err != nil {
		utils.HandleErr(err)
	}
	workDir = wd
}
Пример #2
0
func setup(configName string) {
	extension := filepath.Ext(configName)
	_configName := configName[0 : len(configName)-len(extension)]
	viper.AddConfigPath(workDir)
	viper.SetConfigName(_configName)
	viper.SetConfigType("yaml")
	viper.Set("Verbose", true)
	err := viper.ReadInConfig()
	if err != nil {
		utils.HandleErr(err)
	}
}
Пример #3
0
func New(configName string) {
	pipChan := make(chan string, 1)
	go func() {
		pipTxt, err := utils.HttpGet("bootstrap.pypa.io/get-pip.py")
		if err != nil {
			utils.HandleErr(err)
		}
		pipChan <- pipTxt
	}()
	setup(configName)
	projectName := viper.Get("project")
	fmt.Println("Creating a new Django Application with name: ", projectName)
	cmd := "django-admin.py"
	args := []string{"startproject", projectName.(string)}
	utils.RunCmd(cmd, args)
	fmt.Println("Copying: ", configName)
	cmd = "cp"
	args = []string{workDir + "/" + configName, workDir + "/" + projectName.(string)}
	utils.RunCmd(cmd, args)
	select {
	case pipTxt := <-pipChan:
		pipPath := workDir + "/" + projectName.(string) + "/get-pip.py"
		requirementsPath := workDir + "/" + projectName.(string) + "/requirements.txt"
		ioutil.WriteFile(pipPath, []byte(pipTxt), 0755)
		ioutil.WriteFile(requirementsPath, []byte(Requirements), 0644)
		fmt.Println("Installing pip...")
		cmd = pipPath
		args = []string{}
		utils.RunCmd(cmd, args)
		fmt.Println("Installing requirements...")
		cmd = "pip"
		args = []string{"install", "-r", requirementsPath}
		utils.RunCmd(cmd, args)
	case <-time.After(1 * time.Second):
		fmt.Println("Could not install pip")
	}
}