Пример #1
0
func getCpList(dal *release.Dal, cp_info *CpInfo) ([]*release.CpRelease, error) {
	cp_list := make([]*release.CpRelease, 0, 10)
	mode := cp_info.Mode
	sim := cp_info.Sim
	version := cp_info.Version
	prefix := cp_info.Prefix
	version_scalar := cp_policy.QuantitateVersion(version)

	query := fmt.Sprintf("SELECT * FROM %s WHERE mode='%s' AND prefix='%s' AND sim='%s' AND flag=%d AND version_scalar > %d ORDER BY version_scalar DESC",
		cp_constant.TABLE_CP, mode, prefix, sim, cp_constant.AVAILABLE_FLAG, version_scalar)
	revel.INFO.Println("query higher cp: ", query)
	//	fmt.Println(query)
	list, err := doGetCpList(dal, query)
	if err != nil {
		return nil, err
	}
	cp_list = append(cp_list, list...)

	query = fmt.Sprintf("SELECT * FROM %s WHERE mode='%s' AND prefix='%s' AND sim='%s' AND flag=%d AND version_scalar < %d ORDER BY version_scalar DESC LIMIT 5",
		cp_constant.TABLE_CP, mode, prefix, sim, cp_constant.AVAILABLE_FLAG, version_scalar)
	revel.INFO.Println("query lower 5 cp: ", query)
	//	fmt.Println(query)
	list, err = doGetCpList(dal, query)
	if err != nil {
		return nil, err
	}
	cp_list = append(cp_list, list...)

	return cp_list, nil
}
Пример #2
0
Файл: sorter.go Проект: jsli/ota
func SortCpArray(cp_array []models.CpNode) []models.CpNode {
	order_map := make(map[int64]models.CpNode)
	version_int_arr := SortInt{}
	for _, node := range cp_array {
		version_int := cp_policy.QuantitateVersion(node.VersionNo)
		version_int_arr = append(version_int_arr, version_int)
		order_map[version_int] = node
	}

	sort.Sort(version_int_arr)
	sorted_arr := make([]models.CpNode, 0, 50)
	for _, version := range version_int_arr {
		sorted_arr = append(sorted_arr, order_map[version])
	}

	if DEBUG {
		for _, v1 := range cp_array {
			fmt.Print(v1.VersionNo)
			fmt.Print("  ")
		}
		fmt.Print("\n")

		for _, v2 := range sorted_arr {
			fmt.Print(v2.VersionNo)
			fmt.Print("  ")
		}
		fmt.Print("\n")
	}

	return sorted_arr
}
Пример #3
0
func ProcessDir(info os.FileInfo, dal *release.Dal, path string, mode string, sim string, force bool) error {
	version := policy.ExtractVersion(info.Name())
	if version == "" { //illegal version fmt, ignore
		return fmt.Errorf("Illegal version format : %s", info.Name())
	}
	rel_path := fmt.Sprintf("%s/%s", path, info.Name())[constant.PATH_PREFIX_LEN:]
	cp, err := release.FindCpReleaseByPath(dal, rel_path)
	if err != nil {
		return err
	}
	if cp != nil {
		if !force {
			return fmt.Errorf("Existed CP release : %s", cp)
		} else {
			log.Printf("Existed CP release, delete arbi&grbi for force updating : %s", cp)
			release.DeleteArbiByCpId(dal, cp.Id)
			release.DeleteGrbiByCpId(dal, cp.Id)
			release.DeleteRficByCpId(dal, cp.Id)
		}
	} else {
		cp = &release.CpRelease{}
		cp.Mode = mode
		cp.Sim = sim
		cp.Version = version
		cp.VersionScalar = policy.QuantitateVersion(version)
		cp.LastModifyTs = time.Now().Unix()
		cp.Flag = constant.AVAILABLE_FLAG
		cp.RelPath = rel_path

		slice := strings.Split(rel_path, "/")
		cp.Prefix = strings.TrimSuffix(slice[2], version)

		log.Printf("Find new CP release : %s\n", cp)
		id, err := cp.Save(dal)
		if err != nil {
			cp.Id = -1
			log.Printf("Save CP release failed: %s\n", err)
		} else {
			cp.Id = id
			log.Printf("Save CP release success: %d | %s\n", id, cp)
		}
	}

	//find detail information
	if cp.Id > 0 && FLAG_SCAN_DETAIL {
		ProcessDetail(cp, dal)
	} else {
		return fmt.Errorf("Neither finding or saving CP release success! in [%s]", info.Name())
	}

	return nil
}
Пример #4
0
func (cp *CpRelease) LoadSelfFromFileEvent(event *fsnotify.FileEvent) error {
	path := event.Name
	parent_path := pathutil.ParentPath(path)
	cp.Mode = constant.PATH_TO_MODE[parent_path[:len(parent_path)-1]]

	base_name := pathutil.BaseName(path)
	version := policy.ExtractVersion(base_name)
	if version == "" {
		return errors.New(fmt.Sprintf("Illegal version : %s", base_name))
	}
	cp.Version = version
	cp.VersionScalar = policy.QuantitateVersion(version)

	cp.Sim = constant.MODE_TO_SIM[cp.Mode]
	cp.LastModifyTs = time.Now().Unix()
	cp.Flag = constant.AVAILABLE_FLAG
	cp.RelPath = path[constant.PATH_PREFIX_LEN:]
	return nil
}