예제 #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 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)
}
예제 #3
0
파일: ei.go 프로젝트: jamesbjackson/wrench
func (m *BuildClient) UpdateDevice(new_device *Device, device_id string) (Device, error) {
	var url bytes.Buffer
	resp := new(DeviceResponse)
	url.WriteString(EI_URL)
	url.WriteString(DEVICES_ENDPOINT)
	url.WriteString("/")
	url.WriteString(device_id)

	req_bytes, err := json.Marshal(new_device)
	full_resp, err := m._complete_request("PUT", url.String(), req_bytes)
	if err != nil {
		logging.Debug("Failed to update device: %s", err.Error())
		return resp.Device, err
	}

	if err := json.Unmarshal(full_resp, resp); err != nil {
		logging.Warn("Failed to unmarshal data from device update.. %s", err.Error())
		return resp.Device, err
	}

	if resp.Success == false {
		return resp.Device, errors.New("Error when updating device")
	}
	return resp.Device, nil
}
예제 #4
0
파일: ei.go 프로젝트: jamesbjackson/wrench
func (m *BuildClient) RestartDevice(device_id string) error {
	var url bytes.Buffer
	resp := new(DeviceResponse)
	url.WriteString(EI_URL)
	url.WriteString(DEVICES_ENDPOINT)
	url.WriteString("/")
	url.WriteString(device_id)
	url.WriteString("/")
	url.WriteString(DEVICES_RESTART_ENDPOINT)

	full_resp, err := m._complete_request("POST", url.String(), nil)
	if err != nil {
		logging.Debug("Failed to get device list: %s", err.Error())
		return err
	}

	if err := json.Unmarshal(full_resp, resp); err != nil {
		logging.Warn("Failed to unmarshal data from code revision update.. %s", err.Error())
		return err
	}

	if resp.Success == false {
		return errors.New("Error When retriveing Code Revisions")
	}
	return nil
}
예제 #5
0
파일: ei.go 프로젝트: jamesbjackson/wrench
func (m *BuildClient) GetDeviceLogs(device_id string) ([]DeviceLogEntry, string, error) {
	var url bytes.Buffer
	resp := new(DeviceLogResponse)
	url.WriteString(EI_URL)
	url.WriteString(DEVICES_ENDPOINT)
	url.WriteString("/")
	url.WriteString(device_id)
	url.WriteString("/")
	url.WriteString(DEVICES_LOG_ENDPOINT)
	full_resp, err := m._complete_request("GET", url.String(), nil)
	if err != nil {
		logging.Debug("Failed to get device logs: %s", err.Error())
		return resp.Logs, "", err
	}

	if err := json.Unmarshal(full_resp, resp); err != nil {
		logging.Warn("Failed to unmarshal data from device logs.. %s", err.Error())
		return resp.Logs, "", err
	}

	if resp.Success == false {
		return resp.Logs, "", errors.New("Error When retriveing device logs")
	}
	return resp.Logs, resp.PollUrl, nil
}
예제 #6
0
파일: ei.go 프로젝트: jamesbjackson/wrench
func (m *BuildClient) UpdateCodeRevision(model_id string,
	request *CodeRevisionLong) (CodeRevisionLong, error) {
	var url bytes.Buffer
	resp := new(CodeRevisionResponse)
	url.WriteString(EI_URL)
	url.WriteString(MODELS_ENDPOINT)
	url.WriteString("/")
	url.WriteString(model_id)
	url.WriteString("/")
	url.WriteString(MODELS_REVISIONS_ENDPOINT)

	req_string, err := json.Marshal(request)
	logging.Debug("Request String for upload: %s", req_string)
	full_resp, err := m._complete_request("POST", url.String(), req_string)
	if err != nil {
		logging.Debug("Failed to update code revisions: %s", err.Error())
		return resp.Revisions, err
	}

	if err := json.Unmarshal(full_resp, resp); err != nil {
		logging.Warn("Failed to unmarshal data from code revision update.. %s", err.Error())
		return resp.Revisions, err
	}

	if resp.Success == false {
		return resp.Revisions, errors.New("Error When retriveing Code Revisions")
	}
	return resp.Revisions, nil
}
예제 #7
0
파일: ei.go 프로젝트: jamesbjackson/wrench
func (m *BuildClient) GetCodeRevision(model_id string, build_num string) (CodeRevisionLong, error) {
	var url bytes.Buffer
	resp := new(CodeRevisionResponse)
	url.WriteString(EI_URL)
	url.WriteString(MODELS_ENDPOINT)
	url.WriteString("/")
	url.WriteString(model_id)
	url.WriteString("/")
	url.WriteString(MODELS_REVISIONS_ENDPOINT)
	url.WriteString("/")
	url.WriteString(build_num)
	full_resp, err := m._complete_request("GET", url.String(), nil)
	if err != nil {
		logging.Debug("Failed to get code revisions: %s", err.Error())
		return resp.Revisions, err
	}

	if err := json.Unmarshal(full_resp, resp); err != nil {
		logging.Warn("Failed to unmarshal data from code revision.. %s", err.Error())
		return resp.Revisions, err
	}

	if resp.Success == false {
		return resp.Revisions, errors.New("Error When retriveing Code Revisions")
	}
	return resp.Revisions, nil
}
예제 #8
0
파일: ei.go 프로젝트: jamesbjackson/wrench
func (m *BuildClient) RestartModelDevices(model_id string) error {
	var url bytes.Buffer
	resp := new(ModelResponse)
	url.WriteString(EI_URL)
	url.WriteString(MODELS_ENDPOINT)
	url.WriteString("/")
	url.WriteString(model_id)
	url.WriteString("/")
	url.WriteString(MODELS_DEVICE_RESTART_ENDPOINT)

	full_resp, err := m._complete_request("POST", url.String(), nil)
	if err != nil {
		logging.Debug("An error happened during model restart, %s", err.Error())
		return err
	}

	if err := json.Unmarshal(full_resp, resp); err != nil {
		logging.Warn("Failed to unmarshal data from model response.. %s", err.Error())
		return err
	}

	if resp.Success == false {
		return errors.New("Error When retriveing Code Revisions")
	}

	return nil
}
예제 #9
0
파일: ei.go 프로젝트: jamesbjackson/wrench
func (m *BuildClient) GetModel(model_id string) (*Model, error) {
	var url bytes.Buffer
	resp := new(ModelResponse)
	url.WriteString(EI_URL)
	url.WriteString(MODELS_ENDPOINT)
	url.WriteString("/")
	url.WriteString(model_id)

	full_resp, err := m._complete_request("GET", url.String(), nil)
	if err != nil {
		logging.Debug("An error happened during model get, %s", err.Error())
		return &resp.Model, err
	}

	if err := json.Unmarshal(full_resp, resp); err != nil {
		logging.Warn("Failed to unmarshal data from get model response.. %s", err.Error())
		return &resp.Model, err
	}

	if resp.Success == false {
		return &resp.Model, errors.New("Error when attempting to get model: " + resp.Error.MessageShort)
	}

	return &resp.Model, nil
}
예제 #10
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
}
예제 #11
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
}
예제 #12
0
파일: ei.go 프로젝트: jamesbjackson/wrench
func (m *BuildClient) ListModels() (*ModelList, error) {
	list := new(ModelList)
	full_resp, err := m._complete_request("GET", Concat(EI_URL, "models"), nil)
	if err != nil {
		logging.Debug("An error happened during model get, %s", err.Error())
		return list, err
	}

	if err := json.Unmarshal(full_resp, list); err != nil {
		logging.Warn("Failed to unmarshal data from models.. %s", err.Error())
		return list, err
	}

	return list, nil
}
예제 #13
0
파일: ei.go 프로젝트: jamesbjackson/wrench
func (m *BuildClient) ContinueDeviceLogs(poll_url string) ([]DeviceLogEntry, error) {
	var url bytes.Buffer
	resp := new(DeviceLogResponse)
	url.WriteString(BASE_EI_URL)
	url.WriteString(poll_url)
	full_resp, err := m._complete_request("GET", url.String(), nil)
	if err != nil {
		logging.Debug("Failed to get device logs: %s", err.Error())
		return resp.Logs, err
	}

	if err := json.Unmarshal(full_resp, resp); err != nil {
		logging.Warn("Failed to unmarshal data from device logs.. %s", err.Error())
		return resp.Logs, err
	}

	if resp.Success == false {
		return resp.Logs, errors.New("Error when retriveing device logs")
	}
	return resp.Logs, nil
}
예제 #14
0
파일: ei.go 프로젝트: jamesbjackson/wrench
func (m *BuildClient) CreateModel(new_model *Model) (*Model, error) {
	var url bytes.Buffer
	resp := new(ModelResponse)
	url.WriteString(EI_URL)
	url.WriteString(MODELS_ENDPOINT)

	req_string, err := json.Marshal(new_model)
	logging.Debug("Request String for upload: %s", req_string)
	full_resp, err := m._complete_request("POST", url.String(), req_string)
	if err != nil {
		logging.Debug("An error happened during model creation, %s", err.Error())
		return &resp.Model, err
	}

	if err := json.Unmarshal(full_resp, resp); err != nil {
		logging.Warn("Failed to unmarshal data from model response.. %s", err.Error())
		return &resp.Model, err
	}

	return &resp.Model, nil
}
예제 #15
0
파일: ei.go 프로젝트: jamesbjackson/wrench
func (m *BuildClient) DeleteDevice(device_id string) error {
	var url bytes.Buffer
	resp := new(DeviceResponse)
	url.WriteString(EI_URL)
	url.WriteString(DEVICES_ENDPOINT)
	url.WriteString("/")
	url.WriteString(device_id)

	full_resp, err := m._complete_request("DELETE", url.String(), nil)
	if err != nil {
		logging.Debug("Failed to delete device: %s", err.Error())
		return err
	}

	if err := json.Unmarshal(full_resp, resp); err != nil {
		logging.Warn("Failed to unmarshal data from device deletion.. %s", err.Error())
		return err
	}

	if resp.Success == false {
		return errors.New("Error when updating device")
	}
	return nil
}