metadata: Improve error reporting on failed checksum
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ář <lsedlar@redhat.com>
This commit is contained in:
parent
ee1ee0467b
commit
1a16d94dda
@ -22,11 +22,10 @@ import json
|
|||||||
import productmd.composeinfo
|
import productmd.composeinfo
|
||||||
import productmd.treeinfo
|
import productmd.treeinfo
|
||||||
from productmd.common import get_major_version
|
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_discinfo as create_discinfo
|
||||||
from pungi.compose_metadata.discinfo import write_media_repo as create_media_repo
|
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):
|
def get_description(compose, variant, arch):
|
||||||
@ -343,15 +342,14 @@ def write_extra_files(tree_path, files, checksum_type='sha256', logger=None):
|
|||||||
if logger:
|
if logger:
|
||||||
logger.debug('Processing {file}'.format(file=f))
|
logger.debug('Processing {file}'.format(file=f))
|
||||||
path = os.path.join(tree_path, f)
|
path = os.path.join(tree_path, f)
|
||||||
checksum = pungi_util._doCheckSum(path, checksum_type, logger)
|
try:
|
||||||
# _doCheckSum returns in the format <type>:<digest> _or_ False for failure
|
checksum = compute_file_checksums(path, checksum_type)
|
||||||
if checksum is False:
|
except IOError as exc:
|
||||||
err = 'Failed to calculate the checksum for {file}.'.format(file=path)
|
file = os.path.relpath(exc.filename, '/'.join(tree_path.split('/')[:-3]))
|
||||||
raise RuntimeError(err)
|
raise RuntimeError('Failed to calculate checksum for %s: %s' % (file, exc.strerror))
|
||||||
checksum = checksum.split(':')[1]
|
|
||||||
entry = {
|
entry = {
|
||||||
'file': f,
|
'file': f,
|
||||||
'checksums': {checksum_type: checksum},
|
'checksums': checksum,
|
||||||
'size': os.path.getsize(path),
|
'size': os.path.getsize(path),
|
||||||
}
|
}
|
||||||
metadata['data'].append(entry)
|
metadata['data'].append(entry)
|
||||||
|
Loading…
Reference in New Issue
Block a user