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

}
示例#4
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")
}
示例#5
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")
}
示例#6
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")

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

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

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

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

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

}
示例#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...")
	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
		}
	}
}
示例#14
0
func TestRunDevice(t *testing.T) {
	logging.SetLoggingLevel(logging.LOG_DEBUG)
	logging.Info("Starting Test")
	RunScript("test.nut")
	logging.Info("Ending Test")
}