From 1a16d94ddac6cbf1ca08335a6699403e3eb96b8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Wed, 7 Sep 2016 13:05:11 +0200 Subject: [PATCH] metadata: Improve error reporting on failed checksum MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of using the _doChecksum function, it now uses a function from kobo which has nicer API. If there is an error, the message now includes more details. Signed-off-by: Lubomír Sedlář --- pungi/metadata.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/pungi/metadata.py b/pungi/metadata.py index 9b4d34e2..73628add 100644 --- a/pungi/metadata.py +++ b/pungi/metadata.py @@ -22,11 +22,10 @@ import json import productmd.composeinfo import productmd.treeinfo from productmd.common import get_major_version -from kobo.shortcuts import relative_path +from kobo.shortcuts import relative_path, compute_file_checksums from pungi.compose_metadata.discinfo import write_discinfo as create_discinfo from pungi.compose_metadata.discinfo import write_media_repo as create_media_repo -from pungi import util as pungi_util def get_description(compose, variant, arch): @@ -343,15 +342,14 @@ def write_extra_files(tree_path, files, checksum_type='sha256', logger=None): if logger: logger.debug('Processing {file}'.format(file=f)) path = os.path.join(tree_path, f) - checksum = pungi_util._doCheckSum(path, checksum_type, logger) - # _doCheckSum returns in the format : _or_ False for failure - if checksum is False: - err = 'Failed to calculate the checksum for {file}.'.format(file=path) - raise RuntimeError(err) - checksum = checksum.split(':')[1] + try: + checksum = compute_file_checksums(path, checksum_type) + except IOError as exc: + file = os.path.relpath(exc.filename, '/'.join(tree_path.split('/')[:-3])) + raise RuntimeError('Failed to calculate checksum for %s: %s' % (file, exc.strerror)) entry = { 'file': f, - 'checksums': {checksum_type: checksum}, + 'checksums': checksum, 'size': os.path.getsize(path), } metadata['data'].append(entry)