Beispiel #1
0
 def __str__(self):
     eapi = self.eapi
     if not isinstance(eapi, basestring):
         eapi = str(eapi)
     eapi = eapi.lstrip("-")
     msg = _("Unable to do any operations on '%(cpv)s', since "
     "its EAPI is higher than this portage version's. Please upgrade"
     " to a portage version that supports EAPI '%(eapi)s'.") % \
     {"cpv": self.cpv, "eapi": eapi}
     return _unicode_decode(msg,
         encoding=_encodings['content'], errors='replace')
Beispiel #2
0
 def __str__(self):
     eapi = self.eapi
     if not isinstance(eapi, basestring):
         eapi = str(eapi)
     eapi = eapi.lstrip("-")
     msg = _("Unable to do any operations on '%(cpv)s', since "
     "its EAPI is higher than this portage version's. Please upgrade"
     " to a portage version that supports EAPI '%(eapi)s'.") % \
     {"cpv": self.cpv, "eapi": eapi}
     return _unicode_decode(msg,
                            encoding=_encodings['content'],
                            errors='replace')
Beispiel #3
0
def verify_all(filename, mydict, calc_prelink=0, strict=0):
	"""
	Verify all checksums against a file.

	@param filename: File to run the checksums against
	@type filename: String
	@param calc_prelink: Whether or not to reverse prelink before running the checksum
	@type calc_prelink: Integer
	@param strict: Enable/Disable strict checking (which stops exactly at a checksum failure and throws an exception)
	@type strict: Integer
	@rtype: Tuple
	@return: 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
	"""
	# Dict relates to single file only.
	# returns: (passed,reason)
	file_is_ok = True
	reason     = "Reason unknown"
	try:
		mysize = os.stat(filename)[stat.ST_SIZE]
		if mydict["size"] != mysize:
			return False,(_("Filesize does not match recorded size"), mysize, mydict["size"])
	except OSError as e:
		if e.errno == errno.ENOENT:
			raise easymgc.exception.FileNotFound(filename)
		return False, (str(e), None, None)

	verifiable_hash_types = set(mydict).intersection(hashfunc_map)
	verifiable_hash_types.discard("size")
	if not verifiable_hash_types:
		expected = set(hashfunc_map)
		expected.discard("size")
		expected = list(expected)
		expected.sort()
		expected = " ".join(expected)
		got = set(mydict)
		got.discard("size")
		got = list(got)
		got.sort()
		got = " ".join(got)
		return False, (_("Insufficient data for checksum verification"), got, expected)

	for x in sorted(mydict):
		if   x == "size":
			continue
		elif x in hashfunc_map:
			myhash = perform_checksum(filename, x, calc_prelink=calc_prelink)[0]
			if mydict[x] != myhash:
				if strict:
					raise easymgc.exception.DigestException(
						("Failed to verify '$(file)s' on " + \
						"checksum type '%(type)s'") % \
						{"file" : filename, "type" : x})
				else:
					file_is_ok = False
					reason     = (("Failed on %s verification" % x), myhash,mydict[x])
					break
	return file_is_ok,reason