Ejemplo n.º 1
0
func WriteTempFile(c appengine.Context, code string, fileName string) (string, string, string) {
	if !user.IsCurrentUserCapable(c, NEPTUNE_API) {
		return "", "", NOT_ENABLED_MSG
	}

	var randNum int32
	binary.Read(rand.Reader, binary.LittleEndian, &randNum)
	neptuneDir := fmt.Sprintf("/tmp/neptune-%v", randNum)

	if err := os.MkdirAll(neptuneDir, 0777); err != nil {
		fmt.Printf("error seen creating directory %v: %v", neptuneDir, err)
		return "", "", fmt.Sprintf("%v", err)
	}

	fileLocation := fmt.Sprintf("%v/%v", neptuneDir, fileName)
	file, err := os.Create(fileLocation)

	if err != nil {
		fmt.Printf("error seen creating file %v: %v", fileLocation, err)
		return "", "", fmt.Sprintf("%v", err)
	}

	if _, err2 := file.WriteString(code); err2 != nil {
		fmt.Printf("error seen writing to file %v: %v", fileLocation, err2)
		return "", "", fmt.Sprintf("%v", err2)
	}

	if err3 := file.Close(); err3 != nil {
		fmt.Printf("error seen closing file %v: %v", fileLocation, err3)
		return "", "", fmt.Sprintf("%v", err3)
	}

	fmt.Printf("Wrote Neptune code to %v\n", fileLocation)
	return neptuneDir, fileName, ""
}
Ejemplo n.º 2
0
func WriteJobParams(c appengine.Context, params map[string]string) (string, string, string) {
	if !user.IsCurrentUserCapable(c, NEPTUNE_API) {
		return "", "", NOT_ENABLED_MSG
	}

	neptuneCode := fmt.Sprintf("puts neptune(:boo => 2,\n")

	for key, val := range params {
		neptuneCode += fmt.Sprintf("  %v => %v,\n", key, val)
	}

	neptuneCode += fmt.Sprintf("  :baz => 2).inspect\n\n")
	return WriteJobCode(c, neptuneCode)
}
Ejemplo n.º 3
0
func RunJob(c appengine.Context, fileLocation string) map[string]string {
	result := map[string]string{
		"out": "",
		"err": ""}

	if !user.IsCurrentUserCapable(c, NEPTUNE_API) {
		result["err"] = NOT_ENABLED_MSG
		return result
	}

	if _, err := os.Stat(fileLocation); err != nil {
		fmt.Printf("user requested to run a job on file %v, which doesn't exist\n", fileLocation)
		result["err"] = "file not found"
		return result
	}

	// 'which neptune' returns with a newline on the end, so chop it off
	neptuneCommand := strings.TrimSpace(runShellCommand([]string{"/usr/bin/which", "neptune"})["out"])
	return runShellCommand([]string{neptuneCommand, fileLocation})
}