Esempio n. 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.assertEquals("revision", updated_pkgs[0]["type"])
Esempio n. 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.assertTrue("from" in updated_pkgs[0])
Esempio n. 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))
Esempio n. 4
0
    def SyncFromCatalogFile(self,
                            osrel,
                            arch,
                            catrel,
                            catalog_file,
                            force_unpack=False):
        """Syncs a given catalog from a catalog file.

    Imports srv4 files if necessary.
    """
        if catrel not in CATALOGS_ALLOWED_TO_BE_IMPORTED:
            raise UsageError("Catalogs that can be imported: %s" %
                             CATALOGS_ALLOWED_TO_BE_IMPORTED)
        catalog_dir = os.path.dirname(catalog_file)
        # The plan:
        # - read in the catalog file, and build a md5-filename correspondence
        # data structure.
        logging.debug("Reading the catalog file from disk.")
        src_catalog = catalog.OpencswCatalog(open(catalog_file, "rb"))
        catalog_data = src_catalog.GetCatalogData()
        cat_entry_by_md5 = {}
        cat_entry_by_basename = {}
        for catalog_entry in catalog_data:
            cat_entry_by_md5[catalog_entry["md5sum"]] = catalog_entry
            cat_entry_by_basename[
                catalog_entry["file_basename"]] = catalog_entry
        # - import all srv4 files that were not in the database so far
        sqo_objects = set()
        entries_to_import = []
        logging.debug("Checking which srv4 files are already in the db.")
        for md5 in cat_entry_by_md5:
            try:
                sqo_list = m.Srv4FileStats.selectBy(md5_sum=md5).getOne()
            except sqlobject.main.SQLObjectNotFound, e:
                entries_to_import.append(cat_entry_by_md5[md5])
Esempio n. 5
0
 def test_ParseCatalogLine_1(self):
     oc = catalog.OpencswCatalog(None)
     parsed = oc._ParseCatalogLine(CATALOG_LINE_3)
     expected = {
         'catalogname': 'tmux',
         'deps': ('CSWcommon', 'CSWlibevent'),
         'file_basename':
         'tmux-1.2,REV=2010.05.17-SunOS5.9-sparc-CSW.pkg.gz',
         'md5sum': '145351cf6186fdcadcd169b66387f72f',
         'category': 'none',
         'i_deps': (),
         'pkgname': 'CSWtmux',
         'size': '214091',
         'version': '1.2,REV=2010.05.17'
     }
     self.assertEquals(expected, parsed)
Esempio n. 6
0
def StatsListFromCatalog(file_name_list, catalog_file_name=None, debug=False):
    packages = [
        inspective_package.InspectiveCswSrv4File(x, debug)
        for x in file_name_list
    ]
    if catalog_file_name:
        catalog_obj = catalog.OpencswCatalog(open(catalog_file_name, "rb"))
        md5s_by_basename = catalog_obj.GetDataByBasename()
        for pkg in packages:
            basename = os.path.basename(pkg.pkg_path)
            # It might be the case that a file is present on disk, but missing from
            # the catalog file.
            if basename in md5s_by_basename:
                pkg.md5sum = md5s_by_basename[basename]["md5sum"]
    stats_list = [PackageStats(pkg) for pkg in packages]
    return stats_list
Esempio n. 7
0
 def GetCatalogsByTriad(self, cat_tree_url):
     catalogs_by_triad = {}
     for catrel in common_constants.DEFAULT_CATALOG_RELEASES:
         for arch in common_constants.PHYSICAL_ARCHITECTURES:
             for osrel in common_constants.OS_RELS:
                 short_osrel = osrel.replace("SunOS", "")
                 catalog_file_url = (
                     "%s%s/%s/%s/catalog" %
                     (cat_tree_url, catrel, arch, short_osrel))
                 logging.info("Opening %s", repr(catalog_file_url))
                 try:
                     f = urllib2.urlopen(catalog_file_url)
                     key = (catrel, arch, osrel)
                     catalog_instance = catalog.OpencswCatalog(f)
                     catalogs_by_triad[
                         key] = catalog_instance.GetDataByCatalogname()
                 except urllib2.URLError, e:
                     logging.warning(e)
Esempio n. 8
0
 def testGetDataByCatalogname(self):
     fd = StringIO(CATALOG_LINE_1)
     oc = catalog.OpencswCatalog(fd)
     expected = {"syslog_ng": PKG_STRUCT_1}
     self.assertEqual(expected, oc.GetDataByCatalogname())