Merge #342 Simplify naming format placeholders
This commit is contained in:
commit
9861e80c80
@ -290,7 +290,7 @@ class Compose(kobo.log.LoggingBase):
|
||||
|
||||
:raises RuntimeError: when unknown ``disc_type`` is given
|
||||
"""
|
||||
default_format = "%(compose_id)s-%(variant)s-%(arch)s-%(disc_type)s%(disc_num)s%(suffix)s"
|
||||
default_format = "{compose_id}-{variant}-{arch}-{disc_type}{disc_num}{suffix}"
|
||||
format = format or self.conf.get('image_name_format', default_format)
|
||||
|
||||
if arch == "src":
|
||||
@ -312,7 +312,7 @@ class Compose(kobo.log.LoggingBase):
|
||||
disc_num=disc_num,
|
||||
suffix=suffix)
|
||||
try:
|
||||
return format % args
|
||||
return (format % args).format(**args)
|
||||
except KeyError as err:
|
||||
raise RuntimeError('Failed to create image name: unknown format element: %s' % err.message)
|
||||
|
||||
|
@ -74,7 +74,7 @@ class ImageChecksumPhase(PhaseBase):
|
||||
base_checksum_name = self.compose.conf.get('media_checksum_base_filename', '')
|
||||
if base_checksum_name:
|
||||
substs = get_format_substs(self.compose, variant=variant, arch=arch)
|
||||
base_checksum_name = base_checksum_name % substs
|
||||
base_checksum_name = (base_checksum_name % substs).format(**substs)
|
||||
base_checksum_name += '-'
|
||||
return base_checksum_name
|
||||
|
||||
|
@ -354,13 +354,13 @@ def get_volid(compose, arch, variant=None, escape_spaces=False, disc_type=False)
|
||||
variant_uid = variant and variant.uid or None
|
||||
|
||||
products = [
|
||||
"%(release_short)s-%(version)s %(variant)s.%(arch)s",
|
||||
"%(release_short)s-%(version)s %(arch)s",
|
||||
"{release_short}-{version} {variant}.{arch}",
|
||||
"{release_short}-{version} {arch}",
|
||||
]
|
||||
products = compose.conf.get('image_volid_formats', products)
|
||||
layered_products = [
|
||||
"%(release_short)s-%(version)s %(base_product_short)s-%(base_product_version)s %(variant)s.%(arch)s",
|
||||
"%(release_short)s-%(version)s %(base_product_short)s-%(base_product_version)s %(arch)s",
|
||||
"{release_short}-{version} {base_product_short}-{base_product_version} {variant}.{arch}",
|
||||
"{release_short}-{version} {base_product_short}-{base_product_version} {arch}",
|
||||
]
|
||||
layered_products = compose.conf.get('image_volid_layered_product_formats', layered_products)
|
||||
|
||||
@ -374,7 +374,7 @@ def get_volid(compose, arch, variant=None, escape_spaces=False, disc_type=False)
|
||||
if not variant_uid and "%(variant)s" in i:
|
||||
continue
|
||||
try:
|
||||
volid = i % get_format_substs(compose,
|
||||
args = get_format_substs(compose,
|
||||
variant=variant_uid,
|
||||
release_short=release_short,
|
||||
version=release_version,
|
||||
@ -382,6 +382,7 @@ def get_volid(compose, arch, variant=None, escape_spaces=False, disc_type=False)
|
||||
disc_type=disc_type or '',
|
||||
base_product_short=base_product_short,
|
||||
base_product_version=base_product_version)
|
||||
volid = (i % args).format(**args)
|
||||
except KeyError as err:
|
||||
raise RuntimeError('Failed to create volume id: unknown format element: %s' % err.message)
|
||||
volid = _apply_substitutions(compose, volid)
|
||||
|
@ -137,6 +137,38 @@ class TestImageChecksumPhase(PungiTestCase):
|
||||
mock.call(None, 'md5', 'cafebabe')],
|
||||
any_order=True)
|
||||
|
||||
@mock.patch('os.path.exists')
|
||||
@mock.patch('kobo.shortcuts.compute_file_checksums')
|
||||
@mock.patch('pungi.phases.image_checksum.dump_checksums')
|
||||
def test_checksum_save_individuals_custom_name_str_format(self, dump, cc, exists):
|
||||
compose = DummyCompose(self.topdir, {
|
||||
'media_checksums': ['md5', 'sha256'],
|
||||
'media_checksum_base_filename': '{release_short}-{variant}-{version}-{date}{type_suffix}.{respin}'
|
||||
})
|
||||
|
||||
phase = ImageChecksumPhase(compose)
|
||||
|
||||
exists.return_value = True
|
||||
cc.return_value = {'md5': 'cafebabe', 'sha256': 'deadbeef'}
|
||||
|
||||
phase.run()
|
||||
|
||||
dump.assert_has_calls(
|
||||
[mock.call(self.topdir + '/compose/Client/i386/iso', 'md5',
|
||||
{'image.iso': 'cafebabe'}, 'image.iso.MD5SUM'),
|
||||
mock.call(self.topdir + '/compose/Client/i386/iso', 'sha256',
|
||||
{'image.iso': 'deadbeef'}, 'image.iso.SHA256SUM'),
|
||||
mock.call(self.topdir + '/compose/Client/i386/iso', 'md5', {'image.iso': 'cafebabe'},
|
||||
'test-Client-1.0-20151203.t.0-MD5SUM'),
|
||||
mock.call(self.topdir + '/compose/Client/i386/iso', 'sha256', {'image.iso': 'deadbeef'},
|
||||
'test-Client-1.0-20151203.t.0-SHA256SUM')],
|
||||
any_order=True
|
||||
)
|
||||
cc.assert_called_once_with(self.topdir + '/compose/Client/i386/iso/image.iso', ['md5', 'sha256'])
|
||||
compose.image.add_checksum.assert_has_calls([mock.call(None, 'sha256', 'deadbeef'),
|
||||
mock.call(None, 'md5', 'cafebabe')],
|
||||
any_order=True)
|
||||
|
||||
|
||||
class TestChecksums(unittest.TestCase):
|
||||
def setUp(self):
|
||||
|
Loading…
Reference in New Issue
Block a user