예제 #1
0
 def testUpdateOnly(self):
     oc1 = catalog.OpencswCatalog(StringIO(CATALOG_LINE_1))
     oc2 = catalog.OpencswCatalog(StringIO(CATALOG_LINE_2))
     c = catalog.CatalogComparator()
     new_pkgs, removed_pkgs, updated_pkgs = c.GetCatalogDiff(oc1, oc2)
     self.assertFalse(new_pkgs)
     self.assertFalse(removed_pkgs)
     self.assertTrue("from" in updated_pkgs[0])
예제 #2
0
 def testUpdateOnly(self):
     oc1 = catalog.OpencswCatalog(StringIO(CATALOG_LINE_1))
     oc2 = catalog.OpencswCatalog(StringIO(CATALOG_LINE_2))
     c = catalog.CatalogComparator()
     new_pkgs, removed_pkgs, updated_pkgs = c.GetCatalogDiff(oc1, oc2)
     self.assertFalse(new_pkgs)
     self.assertFalse(removed_pkgs)
     self.assertEquals("revision", updated_pkgs[0]["type"])
예제 #3
0
 def testAddition(self):
     oc1 = catalog.OpencswCatalog(StringIO(CATALOG_LINE_1))
     oc2 = catalog.OpencswCatalog(
         StringIO(CATALOG_LINE_1 + "\n" + CATALOG_LINE_3))
     c = catalog.CatalogComparator()
     new_pkgs, removed_pkgs, updated_pkgs = c.GetCatalogDiff(oc1, oc2)
     self.assertFalse(removed_pkgs)
     self.assertFalse(updated_pkgs)
     self.assertEqual(1, len(new_pkgs))
예제 #4
0
 def _GetPkgsByMaintainer(self, catalogs, rest_client):
     c = catalog.CatalogComparator()
     pkgs_by_maintainer = {}
     for catrel, arch, osrel, cat_a, cat_b in catalogs:
         catalog_key = (catrel, arch, osrel)
         new_pkgs, removed_pkgs, updated_pkgs = c.GetCatalogDiff(
             cat_a, cat_b)
         labels_and_lists = (
             ("new_pkgs", new_pkgs),
             ("removed_pkgs", removed_pkgs),
         )
         for label, pkg_list in labels_and_lists:
             for pkg in pkg_list:
                 maintainer = rest_client.GetMaintainerByMd5(pkg["md5sum"])
                 maintainer_email = maintainer["maintainer_email"]
                 pkgs_by_maintainer.setdefault(maintainer_email, {})
                 pkgs_by_maintainer[maintainer_email].setdefault(label, {})
                 labeled = pkgs_by_maintainer[maintainer_email][label]
                 basename = pkg["file_basename"]
                 labeled.setdefault(basename, {
                     "pkg": pkg,
                     "catalogs": [],
                 })
                 labeled[basename]["catalogs"].append(catalog_key)
         for d in updated_pkgs:
             from_pkg = d["from"]
             to_pkg = d["to"]
             maintainer_from = rest_client.GetMaintainerByMd5(
                 from_pkg["md5sum"])
             maintainer_to = rest_client.GetMaintainerByMd5(
                 to_pkg["md5sum"])
             from_email = maintainer_from["maintainer_email"]
             to_email = maintainer_to["maintainer_email"]
             if from_email == to_email:
                 # A normal upgrade, no takeover
                 label = "upgraded_pkg"
                 self._StorePkgUpdate(catalog_key, label,
                                      pkgs_by_maintainer, from_email,
                                      from_pkg, to_pkg)
             else:
                 # Package takeover
                 self._StorePkgUpdate(catalog_key, "lost_pkg",
                                      pkgs_by_maintainer, from_email,
                                      from_pkg, to_pkg)
                 self._StorePkgUpdate(catalog_key, "got_pkg",
                                      pkgs_by_maintainer, to_email,
                                      from_pkg, to_pkg)
     return pkgs_by_maintainer
예제 #5
0
def GetDiffsByCatalogname(catrel_from, catrel_to, include_downgrades):
  rest_client = rest.RestClient()
  diffs_by_catalogname = {}
  for arch in common_constants.PHYSICAL_ARCHITECTURES:
    logging.debug("Architecture: %s", arch)
    for osrel in common_constants.OS_RELS:
      logging.debug("OS release: %s", osrel)
      cat_from = rest_client.GetCatalog(catrel_from, arch, osrel)
      cat_to = rest_client.GetCatalog(catrel_to, arch, osrel)
      # Should use catalog comparator, but the data format is different
      if cat_from is None:
        cat_from = []
      if cat_to is None:
        cat_to = []
      cat_from_by_c = IndexByCatalogname(cat_from)
      cat_to_by_c = IndexByCatalogname(cat_to)
      comparator = catalog.CatalogComparator()
      new_pkgs, removed_pkgs, updated_pkgs = comparator.GetCatalogDiff(
          cat_to_by_c, cat_from_by_c)
      # By passing the catalogs (as arguments) in reverse order, we get
      # packages to be updated in new_pkgs, and so forth.
      for pkg in new_pkgs:
        catalogname_d = diffs_by_catalogname.setdefault(pkg["catalogname"], {})
        catalogname_d.setdefault("new_pkgs", []).append((arch, osrel, pkg))
      for pkg in removed_pkgs:
        catalogname_d = diffs_by_catalogname.setdefault(pkg["catalogname"], {})
        catalogname_d.setdefault("removed_pkgs", []).append((arch, osrel, pkg))
      for pkg_pair in updated_pkgs:
        # Upgrade or downgrade?
        cmp_result = opencsw.CompareVersions(
            pkg_pair["from"]["version"],
            pkg_pair["to"]["version"])
        if cmp_result < 0:
          direction = "upgrade"
        else:
          direction = "downgrade"
        pkg_pair["direction"] = direction
        pkg = pkg_pair["from"]
        if direction == "upgrade" or include_downgrades:
          catalogname_d = diffs_by_catalogname.setdefault(pkg["catalogname"], {})
          catalogname_d.setdefault("updated_pkgs", []).append((arch, osrel, pkg_pair))
  return diffs_by_catalogname
예제 #6
0
def ComposeDiffsByCatalogname(catalogs, catrel_from, catrel_to,
                              include_version_changes, include_downgrades):
    """Get a data structure indexed with catalognames.

  {
    catalogname: {
      "updated_pkgs": [
        [
          "sparc",
          "SunOS5.9",
          {
            "basename": ...,
            "catalogname": ...,
            "file_basename": ...,
            "md5_sum": ...,
            "mtime": ...,
            "rev": ...,
            "size": ...,
            "version": ...,
            "version_string": ...,
          }
        ],
      ],
      "new_pkgs": [
        ...
      ],
      "removed_pkgs": [
        ...
      ],
    },
  }
  """
    diffs_by_catalogname = {}
    for arch in common_constants.PHYSICAL_ARCHITECTURES:
        logging.debug("Architecture: %s", arch)
        for osrel in common_constants.OS_RELS:
            logging.debug("OS release: %s", osrel)
            cat_from = catalogs[(catrel_from, arch, osrel)]
            cat_to = catalogs[(catrel_to, arch, osrel)]
            # Should use catalog comparator, but the data format is different
            if cat_from is None:
                cat_from = []
            if cat_to is None:
                cat_to = []
            cat_from_by_c = IndexDictByField(cat_from, "catalogname")
            cat_to_by_c = IndexDictByField(cat_to, "catalogname")
            comparator = catalog.CatalogComparator()
            new_pkgs, removed_pkgs, updated_pkgs = comparator.GetCatalogDiff(
                cat_to_by_c, cat_from_by_c)
            # By passing the catalogs (as arguments) in reverse order, we get
            # packages to be updated in new_pkgs, and so forth.
            for pkg in new_pkgs:
                catalogname_d = diffs_by_catalogname.setdefault(
                    (pkg["catalogname"]), {})
                catalogname_d.setdefault("new_pkgs", []).append(
                    (arch, osrel, pkg))
            for pkg in removed_pkgs:
                catalogname_d = diffs_by_catalogname.setdefault(
                    (pkg["catalogname"]), {})
                catalogname_d.setdefault("removed_pkgs", []).append(
                    (arch, osrel, pkg))
            for pkg_pair in updated_pkgs:
                update_decision_by_type = {
                    "revision": True,
                    "version": include_version_changes,
                }
                if (update_decision_by_type[pkg_pair["type"]]
                        and (pkg_pair["direction"] == "upgrade"
                             or include_downgrades)):
                    pkg = pkg_pair["from"]
                    catalogname_d = diffs_by_catalogname.setdefault(
                        (pkg["catalogname"]), {})
                    catalogname_d.setdefault("updated_pkgs", []).append(
                        (arch, osrel, pkg_pair))
    return diffs_by_catalogname