Exemplo n.º 1
0
func (a *Analyzer) findWSGIFile() (bool, string) {
	var found []string
	WSGIPattern := regexp.MustCompile("^(wsgi\\.py|.*\\.wsgi)$")
	filepath.Walk(a.RootDir, func(path string, info os.FileInfo, err error) error {
		if err != nil {
			return nil
		}
		if WSGIPattern.MatchString(filepath.Base(path)) {
			found = append(found, path)
		}
		return nil
	})

	wsgi := ""
	if len(found) == 1 && common.AskYesOrNo(fmt.Sprintf("Found WSGI file %s, confirm?", found[0]), true, a.ShouldPrompt) {
		wsgi = found[0]
	} else if len(found) > 1 && a.ShouldPrompt {
		answer := common.AskMultipleChoices("Found several potential WSGI files. Please choose one:", append(found, "Other"))
		if answer != "Other" {
			wsgi = answer
		}
	}

	if wsgi == "" && a.ShouldPrompt {
		wsgi = common.AskUser("Enter WSGI file path")
	}
	return wsgi != "", wsgi
}
Exemplo n.º 2
0
func (a *Analyzer) findSettingsPy() (hasFound bool, path string) {
	hasFound, settingsModule := a.djangoSettingsModule()

	message := "Enter production settings file path"
	if hasFound {
		return true, filepath.Join(a.RootDir, common.AskUserWithDefault(message, a.module2File(settingsModule), a.ShouldPrompt))
	}
	if a.ShouldPrompt {
		return true, filepath.Join(a.RootDir, common.AskUser(message+" (e.g 'yourapp/settings.py')"))
	}
	return false, ""
}
Exemplo n.º 3
0
func (a *AnalyzerBase) FindPort(hasFoundServer bool, server WebServer, command *string) (string, error) {
	if hasFoundServer {
		return server.Port(command), nil
	}

	withoutPortEnvVar := common.RemovePortIfEnvVar(*command)
	hasFound, port := common.ParsePort(withoutPortEnvVar)
	if hasFound {
		*command = withoutPortEnvVar
		return port, nil
	}

	if !a.ShouldPrompt {
		return "", fmt.Errorf("Could not find port to open corresponding to command '%s'", *command)
	}
	return common.AskUser(fmt.Sprintf("Which port to open to run web service with command '%s'?", *command)), nil
}