예제 #1
0
func TestMe(cmd *Command, args []string) {
	logging.Info("Attempting to find test scripts...")
	test_files, err := FindTestFiles()
	if err != nil {
		os.Exit(1)
	}

	for _, input_file := range test_files {
		split_file := strings.Split(input_file, ".")
		// Remove test, and add .o
		split_file = append(split_file[:len(split_file)-2], split_file[len(split_file)-1], "o")
		output_file := strings.Join(split_file, ".")
		logging.Info("Processing target: %s as output: %s", input_file, output_file)
		err = PreProcessFile(output_file, input_file, cmd.settings.LibraryDirs)
		if err != nil {
			logging.Warn("Could not processes output file %s, got error: ", output_file, err.Error())
			continue
		}
		logging.Info("Running target: %s", output_file)
		err = ExecuteSqrl(output_file)
		if err != nil {
			logging.Warn("Could not run output_file %s, got error: ", output_file, err.Error())
			continue
		}
	}

	logging.Debug("All Files Found: %s", test_files)
	logging.Info("Script finished")
}
예제 #2
0
func ExampleCreateUpdateDeleteModel() {
	logging.SetLoggingLevel(logging.LOG_DEBUG)
	logging.Info("Starting Test")
	client := NewBuildClient(API_KEY)
	new_model := new(Model)
	new_model.Name = "Wrench Test Model"
	model, err := client.CreateModel(new_model)
	if err != nil {
		logging.Fatal("Example Failed %s", err.Error())
		return
	}

	new_model.Name = "Wrench Test Model Again"
	update_model, err := client.UpdateModel(model.Id, new_model)
	if err != nil {
		logging.Fatal("Example Failed %s", err.Error())
		return
	}

	if update_model.Id != model.Id {
		logging.Fatal("Example Failed, Model Ids don't match")
		return
	}

	err = client.DeleteModel(model.Id)
	if err != nil {
		logging.Fatal("Example Failed %s", err.Error())
		return
	}
	logging.Info("Succesfully created model: %s with Id: %s", model.Name, model.Id)
	logging.Info("Ending Test")

}
예제 #3
0
func ProcessSettings(settings_file string) ProjectSettings {
	if _, err := os.Stat(settings_file); err != nil {
		logging.Info("Did not find the settings file %s", settings_file)
		if settings_file != DEFAULT_PROJECT_FILE {
			logging.Fatal("Could not load non default settings file...")
			os.Exit(1)
		}
		logging.Info("Generating default settings file...")
		var settings ProjectSettings
		settings.AgentFileInPath = DEFAULT_AGENT_IN_FILE
		settings.AgentFileOutPath = DEFAULT_AGENT_OUT_FILE
		settings.DeviceFileInPath = DEFAULT_DEVICE_IN_FILE
		settings.DeviceFileOutPath = DEFAULT_DEVICE_OUT_FILE
		settings.LibraryDirs = append(settings.LibraryDirs, DEFAULT_LIB_DIR)
		settings_data, err := json.Marshal(settings)
		if err != nil {
			logging.Warn("Failed to generate default settings json data")
		} else {
			err = ioutil.WriteFile(settings_file, settings_data, 777)
			if err != nil {
				logging.Warn("Failed to write new defaults...")
			}
		}

		return settings
	}

	return LoadSettings(settings_file)
}
예제 #4
0
파일: run.go 프로젝트: jamesbjackson/wrench
func RunMe(cmd *Command, args []string) {
	logging.Info("Attempting to run script...")
	if len(args) < 2 {
		logging.Fatal("run requires file name")
		os.Exit(1)
	}
	ExecuteSqrl(args[1])
	logging.Info("Script finished")
}
예제 #5
0
func ExampleUploadCode() {
	logging.SetLoggingLevel(logging.LOG_DEBUG)
	logging.Info("Starting Test")
	request := new(CodeRevisionLong)
	client := NewBuildClient(API_KEY)
	request.AgentCode = `server.log("More Agent Code!")`
	request.DeviceCode = `server.log("More Device Code!")`
	client.UpdateCodeRevision(MODEL_KEY, request)
	logging.Info("Ending Test")

}
예제 #6
0
func ExampleRestartDevice() {
	logging.SetLoggingLevel(logging.LOG_INFO)
	logging.Info("Starting Test")
	client := NewBuildClient(API_KEY)
	err := client.RestartDevice(TEST_DEVICE_ID)
	if err != nil {
		logging.Fatal("Failed to get device! %s", err.Error())
		return
	}
	fmt.Printf("Device Reset")
	logging.Info("Ending Test")
}
예제 #7
0
func ExampleGetDevice() {
	logging.SetLoggingLevel(logging.LOG_INFO)
	logging.Info("Starting Test")
	client := NewBuildClient(API_KEY)
	device, err := client.GetDevice(TEST_DEVICE_ID)
	if err != nil {
		logging.Fatal("Failed to get device! %s", err.Error())
		return
	}
	fmt.Printf("Name: %s Id: %s\n", device.Name, device.Id)
	logging.Info("Ending Test")
}
예제 #8
0
func ExampleUpdateDevice() {
	logging.SetLoggingLevel(logging.LOG_INFO)
	logging.Info("Starting Test")
	client := NewBuildClient(API_KEY)
	new_device := new(Device)
	new_device.Name = "Wiggy Whacky - hamburg-2"
	dev, err := client.UpdateDevice(new_device, TEST_DEVICE_ID)
	if err != nil {
		logging.Fatal("Failed to update device! %s", err.Error())
		return
	}
	fmt.Printf("Device Updated: %s", dev.Name)
	logging.Info("Ending Test")
}
예제 #9
0
func ExampleRestartModelDevices() {
	logging.SetLoggingLevel(logging.LOG_DEBUG)
	logging.Info("Starting Example")
	client := NewBuildClient(API_KEY)
	err := client.RestartModelDevices(MODEL_KEY)
	if err != nil {
		logging.Fatal("Example Failed %s", err.Error())
		return
	}

	logging.Info("Succesfully restarted model: %s", MODEL_KEY)
	logging.Info("Ending Example")

}
예제 #10
0
func ExampleGetDeviceLogs() {
	logging.SetLoggingLevel(logging.LOG_INFO)
	logging.Info("Starting Test")
	client := NewBuildClient(API_KEY)
	logs, err := client.GetDeviceLogs(TEST_DEVICE_ID)
	if err != nil {
		logging.Fatal("Failed to get device list! %s", err.Error())
		return
	}
	for _, log := range logs {
		fmt.Printf("%s %s:%s\n", log.Timestamp, log.Type, log.Message)
	}
	logging.Info("Ending Test")

}
예제 #11
0
func ExampleDeviceList() {
	logging.SetLoggingLevel(logging.LOG_INFO)
	logging.Info("Starting Test")
	client := NewBuildClient(API_KEY)
	list, err := client.GetDeviceList()
	if err != nil {
		logging.Fatal("Failed to get device list! %s", err.Error())
		return
	}
	for _, device := range list {
		logging.Info("Name: %s, Id: %s, Model: %s", device.Name, device.Id, device.ModelId)
	}
	logging.Info("Ending Test")

}
예제 #12
0
func BuildMe(cmd *Command, args []string) {
	logging.Info("Starting Build Process...")
	err := PreProcessFile(cmd.settings.AgentFileOutPath,
		cmd.settings.AgentFileInPath, cmd.settings.LibraryDirs)
	if err != nil {
		os.Exit(1)
	}

	err = PreProcessFile(cmd.settings.DeviceFileOutPath,
		cmd.settings.DeviceFileInPath, cmd.settings.LibraryDirs)
	if err != nil {
		os.Exit(1)
	}
	logging.Info("Succesfully built...")
}
예제 #13
0
func main() {
	logging_int := flag.Int("l", int(logging.LOG_INFO),
		"Levels 0-4 0 == None, 4 == Debug")
	log_colors_flag := flag.Bool("log_color", false, "-log_color enables log coloring(mingw/linux only)")
	settings_file := flag.String("settings", DEFAULT_PROJECT_FILE,
		"Set the settings file to a non standard file...")

	flag.Parse()
	err, log_value := logging.IntToLogLevel(*logging_int)
	if err == nil {
		logging.SetLoggingLevel(log_value)
	} else {
		PrintHelp()
		os.Exit(1)
		return
	}

	logging.SetColorEnabled(*log_colors_flag)

	args := flag.Args()

	if len(args) < 1 {
		logging.Info("Need a subcommand")
		PrintHelp()
		os.Exit(1)
		return
	}

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)
	go func() {
		for {
			select {
			case <-c:
				os.Exit(0)
			}
		}
	}()

	logging.Debug("Using settings file: %s", *settings_file)
	projectSettings := ProcessSettings(*settings_file)
	logging.Debug("Settings found: %s", projectSettings)
	for _, cmd := range commands {
		if cmd.Name() == args[0] && cmd.Runnable() {
			cmd.Flag.Usage = func() { cmd.Usage() }
			for i, s := range args {
				logging.Debug("Left Args: %d:%s", i, s)
			}
			if cmd.CustomFlags {
				args = args[0:]
			} else if len(args) > 2 {
				cmd.Flag.Parse(args[0:])
				args = cmd.Flag.Args()
			}
			cmd.settings = projectSettings
			cmd.Run(cmd, args)
			return
		}
	}
}
예제 #14
0
func ExampleGetModel() {
	logging.SetLoggingLevel(logging.LOG_DEBUG)
	logging.Info("Starting Test")
	client := NewBuildClient(API_KEY)
	model_list, err := client.ListModels()
	if err != nil {
		logging.Fatal("Test Failed %s", err.Error())
		return
	}

	for _, model := range model_list.Models {
		logging.Info("Id: %s, Name: %s", model.Id, model.Name)
	}
	logging.Info("Ending Test")

}
예제 #15
0
func UploadFiles(cmd *Command, args []string) {
	logging.Info("Attempting to upload...")
	keyfile_data, err := ioutil.ReadFile(cmd.settings.ApiKeyFile)
	if err != nil {
		logging.Fatal("Could not open the keyfile: %s", cmd.settings.ApiKeyFile)
		os.Exit(1)
		return
	}

	keyfile := new(ApiKeyFile)
	err = json.Unmarshal(keyfile_data, keyfile)
	if err != nil {
		logging.Fatal("Could not parse keyfile: %s", cmd.settings.ApiKeyFile)
		os.Exit(1)
		return
	}

	agent_code, err := ioutil.ReadFile(cmd.settings.AgentFileOutPath)
	if err != nil {
		logging.Fatal("Could not open the agent code: %s", cmd.settings.AgentFileOutPath)
		os.Exit(1)
		return
	}

	device_code, err := ioutil.ReadFile(cmd.settings.DeviceFileOutPath)
	if err != nil {
		logging.Fatal("Could not open the device code %s", cmd.settings.DeviceFileOutPath)
		os.Exit(1)
		return
	}

	request := new(ei.CodeRevisionLong)
	client := ei.NewBuildClient(keyfile.Key)
	request.AgentCode = string(agent_code)
	request.DeviceCode = string(device_code)
	response, err := client.UpdateCodeRevision(cmd.settings.ModelKey, request)
	if err != nil {
		logging.Fatal("Failed to upload code to model %s, Error: %s", cmd.settings.ModelKey, err.Error())
		os.Exit(1)
		return
	}
	logging.Info("Succesfully uploaded version %d", response.Version)
}
예제 #16
0
func PreProcessFile(outputFile string, inputFile string, libraryDirs []string) error {
	if _, err := os.Stat(inputFile); err != nil {
		logging.Fatal("Did not find input file %s", inputFile)
		return errors.New("Input file not found")
	}
	gppCmdName := PREPROCESSOR_CMD_BIN
	gppArgs := []string{"-o", outputFile, inputFile}
	var s []string
	for _, dir := range libraryDirs {
		s = []string{"-I", dir}
		gppArgs = append(gppArgs, strings.Join(s, ""))
	}
	gppArgs = append(gppArgs, "-C")
	logging.Debug("gppArgs: %s", gppArgs)
	gppCmd := exec.Command(gppCmdName, gppArgs...)
	cmdReader, err := gppCmd.StdoutPipe()
	if err != nil {
		logging.Fatal("Failed to get stdout pipe Error: %s\n", err.Error())
		os.Exit(1)
	}

	cmdErrorReader, err := gppCmd.StderrPipe()
	if err != nil {
		logging.Fatal("Failed to get stderr pipe Error: %s\n", err.Error())
		os.Exit(1)
	}

	scanner := bufio.NewScanner(cmdReader)
	go func() {
		for scanner.Scan() {
			logging.Info("%s", scanner.Text())
		}
	}()

	errScanner := bufio.NewScanner(cmdErrorReader)
	go func() {
		for errScanner.Scan() {
			logging.Warn("%s", errScanner.Text())
		}
	}()

	err = gppCmd.Start()
	if err != nil {
		logging.Fatal("Error starting gpp", err)
		os.Exit(1)
	}

	err = gppCmd.Wait()
	if err != nil {
		logging.Fatal("Error waiting for gpp", err)
		os.Exit(1)
	}

	return nil
}
예제 #17
0
func ExampleGetCodeRevisions() {
	logging.SetLoggingLevel(logging.LOG_DEBUG)
	logging.Info("Starting Test")
	client := NewBuildClient(API_KEY)
	revisions, err := client.GetCodeRevisionList(MODEL_KEY)
	if err != nil {
		logging.Fatal("Test Failed %s", err.Error())
		return
	}

	for _, revision := range revisions {
		logging.Info(string(revision.CreatedAt))
		logging.Info(`Version: %d
  	              CreatedAt: %s,
	  	          ReleaseNotes: %s,`,
			revision.Version,
			revision.CreatedAt,
			revision.ReleaseNotes)
	}
	logging.Info("Ending Test")

}
예제 #18
0
func ExampleGetCodeRevision() {
	logging.SetLoggingLevel(logging.LOG_DEBUG)
	logging.Info("Starting Test")
	client := NewBuildClient(API_KEY)
	revision, err := client.GetCodeRevision(MODEL_KEY, "1")
	if err != nil {
		logging.Fatal("Test Failed %s", err.Error())
		return
	}

	logging.Info(string(revision.CreatedAt))
	logging.Info(`Version: %d
  	            CreatedAt: %s,
  	            ReleaseNotes: %s,
  	            AgentCode: %s,
  	            DeviceCode: %s,`,
		revision.Version,
		revision.CreatedAt,
		revision.ReleaseNotes,
		revision.AgentCode,
		revision.DeviceCode)
	logging.Info("Ending Test")

}
예제 #19
0
파일: wrench.go 프로젝트: nightrune/wrench
func GenerateDefaultSettingsFile(settings_file string) (ProjectSettings, error) {
	logging.Info("Generating default settings file...")
	var settings ProjectSettings
	settings.AgentFileInPath = DEFAULT_AGENT_IN_FILE
	settings.AgentFileOutPath = DEFAULT_AGENT_OUT_FILE
	settings.DeviceFileInPath = DEFAULT_DEVICE_IN_FILE
	settings.DeviceFileOutPath = DEFAULT_DEVICE_OUT_FILE
	settings.ApiKeyFile = DEFAULT_API_KEY_FILE
	settings.LibraryDirs = append(settings.LibraryDirs, DEFAULT_LIB_DIR)
	settings_data, err := json.Marshal(settings)
	if err != nil {
		logging.Warn("Failed to generate default settings json data")
		return settings, err
	} else {
		err = ioutil.WriteFile(settings_file, settings_data, 777)
		if err != nil {
			logging.Warn("Failed to write new defaults...")
			return settings, err
		}
	}
	return settings, nil
}
예제 #20
0
파일: upload.go 프로젝트: nightrune/wrench
func UploadFiles(cmd *Command, args []string) {
	// Create our flags
	flag_set := flag.NewFlagSet("UploadFlagSet", flag.ExitOnError)
	restart_device := flag_set.Bool("r", false, "-r restarts the server on a successful model upload")
	flag_set.Parse(args[1:])

	logging.Info("Attempting to upload...")
	keyfile_data, err := ioutil.ReadFile(cmd.settings.ApiKeyFile)
	if err != nil {
		logging.Fatal("Could not open the keyfile: %s", cmd.settings.ApiKeyFile)
		os.Exit(1)
		return
	}

	keyfile := new(ApiKeyFile)
	err = json.Unmarshal(keyfile_data, keyfile)
	if err != nil {
		logging.Fatal("Could not parse keyfile: %s", cmd.settings.ApiKeyFile)
		os.Exit(1)
		return
	}

	agent_code, err := ioutil.ReadFile(cmd.settings.AgentFileOutPath)
	if err != nil {
		logging.Fatal("Could not open the agent code: %s", cmd.settings.AgentFileOutPath)
		os.Exit(1)
		return
	}

	device_code, err := ioutil.ReadFile(cmd.settings.DeviceFileOutPath)
	if err != nil {
		logging.Fatal("Could not open the device code %s", cmd.settings.DeviceFileOutPath)
		os.Exit(1)
		return
	}

	request := new(ei.CodeRevisionLong)
	client := ei.NewBuildClient(keyfile.Key)
	request.AgentCode = string(agent_code)
	request.DeviceCode = string(device_code)
	response, err := client.UpdateCodeRevision(cmd.settings.ModelKey, request)
	if err != nil {
		logging.Fatal("Failed to upload code to model %s, Error: %s", cmd.settings.ModelKey, err.Error())
		os.Exit(1)
		return
	}

	if response.Success == false {
		fmt.Println("There were errors in the build:")
		fmt.Printf("Error Code: %s \n", response.Error.Code)
		fmt.Printf("Message: %s \n", response.Error.FullMessage)
		return
	}

	logging.Info("Succesfully uploaded version %d", response.Revisions.Version)

	if *restart_device == true {
		err := client.RestartModelDevices(cmd.settings.ModelKey)
		if err != nil {
			logging.Fatal("Failed to restart devices after upload, Error: %s", err.Error())
			os.Exit(1)
		}

		model, err := client.GetModel(cmd.settings.ModelKey)
		if err != nil {
			fmt.Printf("Model: %s devices restarted.\n", cmd.settings.ModelKey)
			return
		} else {
			fmt.Printf("Model: %s restarted.\n", model.Name)
		}
	}
}
예제 #21
0
파일: wrench.go 프로젝트: nightrune/wrench
func main() {
	logging_int := flag.Int("l", int(logging.LOG_INFO),
		"Levels 0-4 0 == None, 4 == Debug")
	log_colors_flag := flag.Bool("log_color", false, "-log_color enables log coloring(mingw/linux only)")
	settings_file := flag.String("settings", DEFAULT_PROJECT_FILE,
		"Set the settings file to a non standard file...")
	gen_settings_flag := flag.Bool("g", false, "-g generates a default settings file if one is not found")

	flag.Parse()
	err, log_value := logging.IntToLogLevel(*logging_int)
	if err == nil {
		logging.SetLoggingLevel(log_value)
	} else {
		PrintHelp()
		os.Exit(1)
		return
	}

	logging.SetColorEnabled(*log_colors_flag)

	args := flag.Args()

	if len(args) < 1 {
		logging.Info("Need a subcommand")
		PrintHelp()
		os.Exit(1)
		return
	}

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)
	go func() {
		for {
			select {
			case <-c:
				os.Exit(0)
			}
		}
	}()

	var projectSettings ProjectSettings
	logging.Debug("Using settings file: %s", *settings_file)
	if _, err := os.Stat(*settings_file); err != nil {
		logging.Info("Did not find the settings file %s", *settings_file)
		if *settings_file != DEFAULT_PROJECT_FILE {
			logging.Fatal("Could not load non default settings file...")
			os.Exit(1)
		}

		if *gen_settings_flag {
			projectSettings, err = GenerateDefaultSettingsFile(*settings_file)
			if err != nil {
				os.Exit(1)
			}
		} else {
			os.Exit(1)
		}
	} else {
		projectSettings, err = LoadSettings(*settings_file)
		if err != nil {
			logging.Info("Failed to load settings file: %s", *settings_file)
			os.Exit(1)
		}
	}

	logging.Debug("Settings found: %s", projectSettings)
	for _, cmd := range commands {
		if cmd.Name() == args[0] && cmd.Runnable() {
			cmd.Flag.Usage = func() { cmd.Usage() }
			for i, s := range args {
				logging.Debug("Left Args: %d:%s", i, s)
			}
			if cmd.CustomFlags {
				args = args[0:]
			} else if len(args) > 2 {
				cmd.Flag.Parse(args[0:])
				args = cmd.Flag.Args()
			}
			cmd.settings = projectSettings
			cmd.Run(cmd, args)
			return
		}
	}
}
예제 #22
0
func TestRunDevice(t *testing.T) {
	logging.SetLoggingLevel(logging.LOG_DEBUG)
	logging.Info("Starting Test")
	RunScript("test.nut")
	logging.Info("Ending Test")
}