[checksum] Add arch to file name

This allows the checksum file to include the architecture.

Fixes: #243
Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2016-04-04 09:38:48 +02:00
parent 861a4f5823
commit 1ebb9d1773
5 changed files with 57 additions and 49 deletions

View File

@ -1051,9 +1051,19 @@ Media Checksums Settings
prefix to that name prefix to that name
It is possible to use format strings that will be replace by actual values. It is possible to use format strings that will be replace by actual values.
The allowed keys are ``%(release_showrt)s``, ``%(release_short)s``, The allowed keys are:
``%(release_id)s``, ``%(variant)s``, ``%(version)s``, ``%(date)s``,
``%(type_suffix)s``, ``%(label)s`` and ``%(respin)s`` * ``arch``
* ``compose_id``
* ``date``
* ``label``
* ``label_major_version``
* ``release_short``
* ``respin``
* ``type``
* ``type_suffix``
* ``version``
* ``version``
For example, for Fedora the prefix should be For example, for Fedora the prefix should be
``%(release_short)s-%(variant)s-%(version)s-%(date)s%(type_suffix)s.%(respin)s``. ``%(release_short)s-%(variant)s-%(version)s-%(date)s%(type_suffix)s.%(respin)s``.

View File

@ -33,7 +33,7 @@ from productmd.images import Images
from pungi.wrappers.variants import VariantsXmlParser from pungi.wrappers.variants import VariantsXmlParser
from pungi.paths import Paths from pungi.paths import Paths
from pungi.wrappers.scm import get_file_from_scm from pungi.wrappers.scm import get_file_from_scm
from pungi.util import makedirs, get_arch_variant_data from pungi.util import makedirs, get_arch_variant_data, get_format_substs
from pungi.metadata import compose_to_composeinfo from pungi.metadata import compose_to_composeinfo
@ -270,25 +270,6 @@ class Compose(kobo.log.LoggingBase):
return return
return open(self.status_file, "r").read().strip() return open(self.status_file, "r").read().strip()
def get_format_substs(self, **kwargs):
"""Return a dict of basic format substitutions.
Any kwargs will be added as well.
"""
substs = {
'compose_id': self.compose_id,
'release_short': self.ci_base.release.short,
'version': self.ci_base.release.version,
'date': self.compose_date,
'respin': self.compose_respin,
'type': self.compose_type,
'type_suffix': self.compose_type_suffix,
'label': self.compose_label,
'label_major_version': self.compose_label_major_version,
}
substs.update(kwargs)
return substs
def get_image_name(self, arch, variant, disc_type='dvd', def get_image_name(self, arch, variant, disc_type='dvd',
disc_num=1, suffix='.iso', format=None): disc_num=1, suffix='.iso', format=None):
"""Create a filename for image with given parameters. """Create a filename for image with given parameters.
@ -310,11 +291,12 @@ class Compose(kobo.log.LoggingBase):
variant_uid = variant.parent.uid variant_uid = variant.parent.uid
else: else:
variant_uid = variant.uid variant_uid = variant.uid
args = self.get_format_substs(variant=variant_uid, args = get_format_substs(self,
arch=arch, variant=variant_uid,
disc_type=disc_type, arch=arch,
disc_num=disc_num, disc_type=disc_type,
suffix=suffix) disc_num=disc_num,
suffix=suffix)
try: try:
return format % args return format % args
except KeyError as err: except KeyError as err:

View File

@ -4,6 +4,7 @@ import os
from kobo import shortcuts from kobo import shortcuts
from .base import PhaseBase from .base import PhaseBase
from ..util import get_format_substs
MULTIPLE_CHECKSUMS_ERROR = ( MULTIPLE_CHECKSUMS_ERROR = (
@ -66,29 +67,21 @@ class ImageChecksumPhase(PhaseBase):
for arch in self.compose.im.images[variant]: for arch in self.compose.im.images[variant]:
for image in self.compose.im.images[variant][arch]: for image in self.compose.im.images[variant][arch]:
path = os.path.dirname(os.path.join(top_dir, image.path)) path = os.path.dirname(os.path.join(top_dir, image.path))
images.setdefault((variant, path), set()).add(image) images.setdefault((variant, arch, path), set()).add(image)
return images return images
def _get_base_filename(self, variant): def _get_base_filename(self, variant, arch):
base_checksum_name = self.compose.conf.get('media_checksum_base_filename', '') base_checksum_name = self.compose.conf.get('media_checksum_base_filename', '')
if base_checksum_name: if base_checksum_name:
base_checksum_name = base_checksum_name % { substs = get_format_substs(self.compose, variant=variant, arch=arch)
'release_short': self.compose.ci_base.release.short, base_checksum_name = base_checksum_name % substs
'release_id': self.compose.ci_base.release_id,
'variant': variant,
'version': self.compose.ci_base.release.version,
'date': self.compose.compose_date,
'type_suffix': self.compose.compose_type_suffix,
'respin': self.compose.compose_respin,
'label': self.compose.compose_label,
}
base_checksum_name += '-' base_checksum_name += '-'
return base_checksum_name return base_checksum_name
def run(self): def run(self):
for (variant, path), images in self._get_images().iteritems(): for (variant, arch, path), images in self._get_images().iteritems():
checksums = {} checksums = {}
base_checksum_name = self._get_base_filename(variant) base_checksum_name = self._get_base_filename(variant, arch)
for image in images: for image in images:
filename = os.path.basename(image.path) filename = os.path.basename(image.path)
full_path = os.path.join(path, filename) full_path = os.path.join(path, filename)

View File

@ -370,13 +370,14 @@ def get_volid(compose, arch, variant=None, escape_spaces=False, disc_type=False)
if not variant_uid and "%(variant)s" in i: if not variant_uid and "%(variant)s" in i:
continue continue
try: try:
volid = i % compose.get_format_substs(variant=variant_uid, volid = i % get_format_substs(compose,
release_short=release_short, variant=variant_uid,
version=release_version, release_short=release_short,
arch=arch, version=release_version,
disc_type=disc_type or '', arch=arch,
base_product_short=base_product_short, disc_type=disc_type or '',
base_product_version=base_product_version) base_product_short=base_product_short,
base_product_version=base_product_version)
except KeyError as err: except KeyError as err:
raise RuntimeError('Failed to create volume id: unknown format element: %s' % err.message) raise RuntimeError('Failed to create volume id: unknown format element: %s' % err.message)
volid = _apply_substitutions(compose, volid) volid = _apply_substitutions(compose, volid)
@ -472,3 +473,23 @@ def failable(compose, variant, arch, deliverable, msg=None):
compose.log_info(str(exc)) compose.log_info(str(exc))
tb = traceback.format_exc() tb = traceback.format_exc()
compose.log_debug(tb) compose.log_debug(tb)
def get_format_substs(compose, **kwargs):
"""Return a dict of basic format substitutions.
Any kwargs will be added as well.
"""
substs = {
'compose_id': compose.compose_id,
'release_short': compose.ci_base.release.short,
'version': compose.ci_base.release.version,
'date': compose.compose_date,
'respin': compose.compose_respin,
'type': compose.compose_type,
'type_suffix': compose.compose_type_suffix,
'label': compose.compose_label,
'label_major_version': compose.compose_label_major_version,
}
substs.update(kwargs)
return substs

View File

@ -23,9 +23,11 @@ class DummyCompose(object):
self.supported = True self.supported = True
self.compose_date = '20151203' self.compose_date = '20151203'
self.compose_type_suffix = '.t' self.compose_type_suffix = '.t'
self.compose_type = 'test'
self.compose_respin = 0 self.compose_respin = 0
self.compose_id = 'Test-20151203.0.t' self.compose_id = 'Test-20151203.0.t'
self.compose_label = None self.compose_label = None
self.compose_label_major_version = None
self.image_release = '20151203.t.0' self.image_release = '20151203.t.0'
self.ci_base = mock.Mock( self.ci_base = mock.Mock(
release_id='Test-1.0', release_id='Test-1.0',