portage.checksum module¶
- portage.checksum._apply_hash_filter(digests, hash_filter)¶
Return a new dict containing the filtered digests, or the same 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
- portage.checksum._filter_unaccelarated_hashes(digests)¶
If multiple digests are available and some are unaccelerated, then return a new dict that omits the unaccelerated ones. This allows extreme performance problems like bug #425046 to be avoided whenever practical, especially for cases like stage builds where acceleration may not be available for some hashes due to minimization of dependencies.
- class portage.checksum._generate_hash_function(hashtype, hashobject, origin='unknown')¶
Bases:
object
- _hashobject¶
- checksum_file(filename)¶
Run a checksum against a file.
- Parameters
filename (String) – File to run the checksum against
- Returns
The hash and size of the data
- checksum_str(data)¶
Obtain a checksum of a byte-string.
- Parameters
data (bytes) – Data to hash
- Returns
The hash of the data (hex-digest)
- class portage.checksum._hash_filter(filter_str)¶
Bases:
object
Implements filtering for PORTAGE_CHECKSUM_FILTER.
- _tokens¶
- transparent¶
- portage.checksum._open_file(filename)¶
- portage.checksum._perform_md5_merge(x, **kwargs)¶
- portage.checksum.checksum_str(data, hashname='MD5')¶
Run a specific checksum against a byte string.
- Parameters
filename (Bytes) – Data to checksum
hashname (String) – The type of hash function to run
- Return type
String
- Returns
The hash (hex-digest) of the data
- portage.checksum.get_hash_origin(hashtype)¶
- portage.checksum.get_valid_checksum_keys()¶
- portage.checksum.is_prelinkable_elf(filename)¶
- portage.checksum.perform_all(x, calc_prelink=0)¶
- portage.checksum.perform_checksum(filename, hashname='MD5', calc_prelink=0)¶
Run a specific checksum against a file. The filename can be either unicode or an encoded byte string. If filename is unicode then a UnicodeDecodeError will be raised if necessary.
- Parameters
filename (String) – File to run the checksum against
hashname (String) – The type of hash function to run
calc_prelink (Integer) – Whether or not to reverse prelink before running the checksum
- Return type
Tuple
- Returns
The hash and size of the data
- portage.checksum.perform_md5(x, calc_prelink=0)¶
- portage.checksum.perform_multiple_checksums(filename, hashes=['MD5'], calc_prelink=0)¶
Run a group of checksums against a file.
- Parameters
filename (String) – File to run the checksums against
hashes – A list of checksum functions to run against the file
calc_prelink (Integer) – Whether or not to reverse prelink before running the checksum
- Return type
Tuple
- Returns
A dictionary in the form: return_value[hash_name] = (hash_result,size) for each given checksum
- portage.checksum.verify_all(filename, mydict, calc_prelink=0, strict=0)¶
Verify all checksums against a file.
- Parameters
filename (String) – File to run the checksums against
calc_prelink (Integer) – Whether or not to reverse prelink before running the checksum
strict (Integer) – Enable/Disable strict checking (which stops exactly at a checksum failure and throws an exception)
- Return type
Tuple
- Returns
Result of the checks and possible message: 1) If size fails, False, and a tuple containing a message, the given size, and the actual size 2) If there is an os error, False, and a tuple containing the system error followed by 2 nulls 3) If a checksum fails, False and a tuple containing a message, the given hash, and the actual hash 4) If all checks succeed, return True and a fake reason