_apply_hash_filter: make hash_filter simpler
authorZac Medico <zmedico@gentoo.org>
Wed, 22 Aug 2012 04:01:24 +0000 (21:01 -0700)
committerZac Medico <zmedico@gentoo.org>
Wed, 22 Aug 2012 04:01:24 +0000 (21:01 -0700)
Now any callable object will work, which might be helpful for
consumers of the Manifest.checkFileHashes() method.

pym/_emerge/EbuildFetcher.py
pym/portage/checksum.py
pym/portage/dbapi/bintree.py
pym/portage/package/ebuild/digestcheck.py
pym/portage/package/ebuild/fetch.py

index bbcb6a9d28e98d86025710fa17120bf612aa9be3..2d9635af461343aa5f9dda37daa54f27a73ce347 100644 (file)
@@ -59,6 +59,8 @@ class EbuildFetcher(SpawnProcess):
                                return False
 
                hash_filter = _hash_filter(settings.get("PORTAGE_CHECKSUM_FILTER", ""))
+               if hash_filter.transparent:
+                       hash_filter = None
                stdout_orig = sys.stdout
                stderr_orig = sys.stderr
                global_havecolor = portage.output.havecolor
index de4cc668a4d84ceeda0112347de3a6d557e96cd8..144e6336f3e53f811262686692d6629b483b9eec 100644 (file)
@@ -250,9 +250,13 @@ def _apply_hash_filter(digests, hash_filter):
        dict if no changes are necessary. This will always preserve at
        at least one digest, in order to ensure that they are not all
        discarded.
+       @param digests: dictionary of digests
+       @type digests: dict
+       @param hash_filter: A callable that takes a single hash name
+               argument, and returns True if the hash is to be used or
+               False otherwise
+       @type hash_filter: callable
        """
-       if hash_filter.transparent:
-               return digests
 
        verifiable_hash_types = set(digests).intersection(hashfunc_map)
        verifiable_hash_types.discard("size")
index a2fd5eabe08237f0e982a84bcd279501998706d9..7f0943607444011b82caec30005bb9dd2eb59076 100644 (file)
@@ -1465,7 +1465,8 @@ class binarytree(object):
 
                hash_filter = _hash_filter(
                        self.settings.get("PORTAGE_CHECKSUM_FILTER", ""))
-               digests = _apply_hash_filter(digests, hash_filter)
+               if not hash_filter.transparent:
+                       digests = _apply_hash_filter(digests, hash_filter)
                eout = EOutput()
                eout.quiet = self.settings.get("PORTAGE_QUIET") == "1"
                ok, st = _check_distfile(pkg_path, digests, eout, show_errors=0)
index 1d59948d13d8d97b88c1a4f48240a0b1692110ab..e207ba841257b602ac4adaba4c559836013d6283 100644 (file)
@@ -30,6 +30,8 @@ def digestcheck(myfiles, mysettings, strict=False, justmanifest=None, mf=None):
                return 1
        pkgdir = mysettings["O"]
        hash_filter = _hash_filter(mysettings.get("PORTAGE_CHECKSUM_FILTER", ""))
+       if hash_filter.transparent:
+               hash_filter = None
        if mf is None:
                mf = mysettings.repositories.get_repo_for_location(
                        os.path.dirname(os.path.dirname(pkgdir)))
index 8365ad211b66da0d51d83ff8c7ef25e5a9fab215..576a91239690fc89d119fcc9211f9d5d9a827571 100644 (file)
@@ -358,6 +358,8 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
                        mymirrors += [x.rstrip("/") for x in mysettings["GENTOO_MIRRORS"].split() if x]
 
        hash_filter = _hash_filter(mysettings.get("PORTAGE_CHECKSUM_FILTER", ""))
+       if hash_filter.transparent:
+               hash_filter = None
        skip_manifest = mysettings.get("EBUILD_SKIP_MANIFEST") == "1"
        if skip_manifest:
                allow_missing_digests = True
@@ -799,7 +801,8 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
                                                        continue
                                                else:
                                                        digests = _filter_unaccelarated_hashes(mydigests[myfile])
-                                                       digests = _apply_hash_filter(digests, hash_filter)
+                                                       if hash_filter is not None:
+                                                               digests = _apply_hash_filter(digests, hash_filter)
                                                        verified_ok, reason = verify_all(myfile_path, digests)
                                                        if not verified_ok:
                                                                writemsg(_("!!! Previously fetched"
@@ -1057,7 +1060,8 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0,
                                                                # net connection. This way we have a chance to try to download
                                                                # from another mirror...
                                                                digests = _filter_unaccelarated_hashes(mydigests[myfile])
-                                                               digests = _apply_hash_filter(digests, hash_filter)
+                                                               if hash_filter is not None:
+                                                                       digests = _apply_hash_filter(digests, hash_filter)
                                                                verified_ok, reason = verify_all(myfile_path, digests)
                                                                if not verified_ok:
                                                                        writemsg(_("!!! Fetched file: %s VERIFY FAILED!\n") % myfile,