From c29518626a75b5dab642c7d626b1f2c33ceade37 Mon Sep 17 00:00:00 2001 From: Neal Gompa Date: Fri, 23 Aug 2024 09:51:17 -0400 Subject: [PATCH] Allow string versions and test "word" versions There are descriptions out in the wild that use "non-numeric" versions in their descriptions, particularly without separators for splitting. This change switches all of this to strings rather than assuming numbers and gracefully handles the single word case. --- kiwi/system/result.py | 20 ++++++++++++-------- test/unit/system/result_test.py | 9 ++++++++- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/kiwi/system/result.py b/kiwi/system/result.py index 02d265bd87d..07a6cfe5bd3 100644 --- a/kiwi/system/result.py +++ b/kiwi/system/result.py @@ -47,9 +47,9 @@ ('A', str), # architecture name ('I', str), # custom ID setting ('T', str), # image type name - ('M', int), # Major version number - ('m', int), # Minor version number - ('p', int), # Patch version number + ('M', str), # Major version number + ('m', str), # Minor version number + ('p', str), # Patch version number ('v', str) # Version string ] ) @@ -76,7 +76,11 @@ def __init__(self, xml_state: XMLState): self.xml_state = xml_state def add_bundle_format(self, pattern: str): - (major, minor, patch) = self.xml_state.get_image_version().split('.') + version_string = self.xml_state.get_image_version() + if '.' in version_string: + (major, minor, patch) = version_string.split(sep='.', maxsplit=2) + else: + (major, minor, patch) = (version_string, '', '') self.name_tags = result_name_tags( N=self.xml_state.xml_data.get_name(), P='_'.join( @@ -85,10 +89,10 @@ def add_bundle_format(self, pattern: str): A=self.xml_state.host_architecture, I='', T=self.xml_state.get_build_type_name(), - M=int(major), - m=int(minor), - p=int(patch), - v=self.xml_state.get_image_version() + M=major, + m=minor, + p=patch, + v=version_string ) self.result_files['bundle_format'] = { 'pattern': pattern, diff --git a/test/unit/system/result_test.py b/test/unit/system/result_test.py index d7110dd8b07..780b496c76e 100644 --- a/test/unit/system/result_test.py +++ b/test/unit/system/result_test.py @@ -35,13 +35,20 @@ def test_print_results_no_data(self): assert self.result.print_results() is None assert not self._caplog.text - def test_print_results_data(self): + def test_print_results_data_number_version(self): self.xml_state.get_image_version.return_value = '1.1.1' self.result.add('foo', 'bar') self.result.add_bundle_format('%N') with self._caplog.at_level(logging.INFO): self.result.print_results() + def test_print_results_data_word_version(self): + self.xml_state.get_image_version.return_value = 'test' + self.result.add('foo', 'bar') + self.result.add_bundle_format('%N') + with self._caplog.at_level(logging.INFO): + self.result.print_results() + @patch('pickle.dump') @patch('simplejson.dumps') def test_dump(self, mock_simplejson_dumps, mock_pickle_dump):