def test_calculate_checksum(self): test_file = open(self.test_file) try: file_checksum = file_utils.calculate_checksum(test_file) finally: test_file.close() self.assertEquals(file_checksum, '4da653eb38433cd3bfb0910453f836267a91336' '635d23f047aaecca1b2b960cd')
def calculate_checksum(file_handle): """ Return the sha256 checksum of the given file-like object. :param file_handle: A handle to an open file-like object :type file_handle: file-like object :return: The file's checksum :rtype: string """ return file_utils.calculate_checksum(file_handle)
def generate_unit_key_and_metadata(filepath, **kwargs): """ Analyze the ISO found at the path specified by filepath, and return its unit_key and metadata as a 2-tuple. Since ISOs don't have metadata, this just amounts to the unit key and an empty metadata dict. :param filepath: The path of the file that we need the unit key and metadata for :type filepath: str :param kwargs: Unused keyword arguments :type kwargs: dict :return: A two tuple of (unit_key, metadata), both dicts :rtype: tuple """ iso = open(filepath) try: size = file_utils.calculate_size(iso) checksum = file_utils.calculate_checksum(iso) finally: iso.close() return {'name': os.path.basename(filepath), 'size': size, 'checksum': checksum}, {}