Example #1
0
def GetPackageStatsByFilenamesOrMd5s(args, debug=False):
    filenames = []
    md5s = []
    for arg in args:
        if struct_util.IsMd5(arg):
            md5s.append(arg)
        else:
            filenames.append(arg)
    srv4_pkgs = [
        inspective_package.InspectiveCswSrv4File(x) for x in filenames
    ]
    pkgstat_objs = []
    pbar = progressbar.ProgressBar()
    pbar.maxval = len(md5s) + len(srv4_pkgs)
    pbar.start()
    counter = itertools.count()
    for pkg in srv4_pkgs:
        pkgstat_objs.append(package_stats.PackageStats(pkg, debug=debug))
        pbar.update(counter.next())
    for md5 in md5s:
        pkgstat_objs.append(
            package_stats.PackageStats(None, md5sum=md5, debug=debug))
        pbar.update(counter.next())
    pbar.finish()
    return pkgstat_objs
Example #2
0
    def test_CollectStats(self):
        """Test if it's possible to collect stats.

    It's a real showdown of a part of code I didn't want to unit test
    earlier.  It's possible to see how the law of Demeter was violated,
    leading to a confusing API.
    """
        mock_srv4 = self.mox.CreateMock(
            inspective_package.InspectiveCswSrv4File)
        mock_dirpkg = self.mox.CreateMock(inspective_package.InspectivePackage)
        mock_pkgmap = self.mox.CreateMock(pkgmap.Pkgmap)
        mock_srv4.GetInspectivePkg().AndReturn(mock_dirpkg)
        mock_srv4.pkg_path = "/tmp/foo-1.2,REV=1234.12.11-SunOS5.8-sparc-CSW.pkg.gz"
        mock_dirpkg.pkgname = "MOCKpkgname"
        mock_dirpkg.GetOverrides().AndReturn([])
        mock_dirpkg.GetCatalogname().AndReturn("mock_catalogname")
        mock_srv4.GetMd5sum().AndReturn("mock md5sum")
        mock_srv4.GetSize().AndReturn(42)
        mock_dirpkg.GetDependencies().AndReturn(([], []))
        mock_dirpkg.ListBinaries().AndReturn([])
        mock_dirpkg.GetBinaryDumpInfo().AndReturn([])
        mock_srv4.GetPkgchkOutput().AndReturn((0, "", ""))
        mock_dirpkg.GetObsoletedBy().AndReturn(([], []))
        mock_dirpkg.GetParsedPkginfo().AndReturn({
            "ARCH":
            "sparc",
            "EMAIL":
            "*****@*****.**",
        })
        mock_dirpkg.GetPkgmap().AndReturn(mock_pkgmap)
        mock_pkgmap.entries = []
        mock_dirpkg.GetFilesContaining(mox.IsA(tuple)).AndReturn([])
        mock_dirpkg.GetFilesMetadata().AndReturn([])
        mock_srv4.GetMtime().AndReturn(
            datetime.datetime(2010, 12, 8, 7, 52, 54))
        mock_dirpkg.GetLddMinusRlines().AndReturn({})
        mock_dirpkg.GetBinaryElfInfo().AndReturn({})
        pkgstats = package_stats.PackageStats(mock_srv4)
        self.mox.ReplayAll()
        data_structure = pkgstats._CollectStats(True)
        self.mox.VerifyAll()
        self.assertEqual(
            "1234.12.11", data_structure["basic_stats"]["parsed_basename"]
            ["revision_info"]["REV"])
        self.assertEqual(datetime.datetime(2010, 12, 8, 7, 52, 54),
                         data_structure["mtime"])