func packagesToKeys(packages []map[string]string) []aptly_model.Key { latestVersions := make(map[string]map[string]string) var keys []aptly_model.Key for _, currentPackage := range packages { glog.V(2).Infof("handle package %s %s", currentPackage["Package"], currentPackage["Version"]) name := currentPackage["Package"] if latestPackage, ok := latestVersions[name]; ok { var packageToDelete map[string]string glog.V(4).Infof("compare %s < %s", currentPackage["Version"], latestPackage["Version"]) if aptly_version.LessThan(aptly_version.Version(currentPackage["Version"]), aptly_version.Version(latestPackage["Version"])) { packageToDelete = currentPackage } else { glog.V(4).Infof("set latest version %s %s", currentPackage["Package"], currentPackage["Version"]) latestVersions[name] = currentPackage packageToDelete = latestPackage } keys = append(keys, aptly_model.Key(packageToDelete["Key"])) glog.V(2).Infof("mark package %s %s to delete", packageToDelete["Package"], packageToDelete["Version"]) } else { latestVersions[name] = currentPackage } } for _, p := range latestVersions { glog.V(2).Infof("keep package %s %s", p["Package"], p["Version"]) } return keys }
func (p *packageVersion) PackageVersions(api aptly_model.API, repository aptly_model.Repository, packageName model.Package) ([]aptly_version.Version, error) { glog.V(2).Infof("PackageVersions - repo: %s package: %s", repository, packageName) packageDetails, err := p.listPackageDetails(api, repository) if err != nil { return nil, err } var versions []aptly_version.Version for _, packageDetail := range packageDetails { if packageDetail.Package == packageName { v := packageDetail.Version glog.V(2).Infof("found version: %s", v) versions = append(versions, aptly_version.Version(v)) } } return versions, nil }
func do( packageCopier aptly_package_copier.PackageCopier, packageLatestVersion aptly_package_latest_version.PackageLatestVersion, packageDetailLatestLister aptly_model_latest_lister.PackageDetailLatestLister, repoURL string, apiURL string, apiUsername string, apiPassword string, apiPasswordfile string, sourceRepo string, targetRepo string, targetDistribution string, name string, version string, ) error { glog.Infof("repoURL: %v apiURL: %v apiUsername: %v apiPassword: %v apiPasswordfile: %v sourceRepo: %v targetRepo: %v targetDistribution: %v name: %v version: %v", repoURL, apiURL, apiUsername, apiPassword, apiPasswordfile, sourceRepo, targetRepo, targetDistribution, name, version) if len(apiPasswordfile) > 0 { content, err := ioutil.ReadFile(apiPasswordfile) if err != nil { return err } apiPassword = strings.TrimSpace(string(content)) } if len(apiURL) == 0 { return fmt.Errorf("parameter %s missing", parameterAPIURL) } if len(sourceRepo) == 0 { return fmt.Errorf("parameter %s missing", parameterSource) } if len(targetRepo) == 0 { return fmt.Errorf("parameter %s missing", parameterTarget) } if len(name) == 0 { return fmt.Errorf("parameter %s missing", parameterName) } if len(version) == 0 { return fmt.Errorf("parameter %s missing", parameterVersion) } return copy(packageCopier, packageLatestVersion, packageDetailLatestLister, aptly_model.NewAPI(repoURL, apiURL, apiUsername, apiPassword), aptly_model.Repository(sourceRepo), aptly_model.Repository(targetRepo), aptly_model.Distribution(targetDistribution), aptly_model.Package(name), aptly_version.Version(version)) }
func NewPackageDetailByString(packageName string, version string) PackageDetail { return NewPackageDetail(Package(packageName), aptly_version.Version(version)) }