pkgset: Use release number of a module
Signed-off-by: Martin Curlej <mcurlej@redhat.com> updated regex, added comment, pep8 fix
This commit is contained in:
parent
65bc6969e2
commit
079454c502
@ -17,6 +17,7 @@
|
||||
import os
|
||||
import cPickle as pickle
|
||||
import json
|
||||
import re
|
||||
|
||||
import pungi.wrappers.kojiwrapper
|
||||
import pungi.phases.pkgset.pkgsets
|
||||
@ -52,11 +53,29 @@ def get_pdc_client_session(compose):
|
||||
|
||||
|
||||
def variant_dict_from_str(module_str):
|
||||
module_info = {}
|
||||
"""
|
||||
Method which parses module NVR string, defined in a variants file and returns
|
||||
a module info dictionary instead.
|
||||
|
||||
release_start = module_str.rfind('-')
|
||||
module_info['variant_version'] = module_str[release_start+1:]
|
||||
module_info['variant_id'] = module_str[:release_start]
|
||||
Attributes:
|
||||
module_str: string, the NV(R) of module defined in a variants file.
|
||||
"""
|
||||
|
||||
module_info = {}
|
||||
# The regex is matching a string which should represent the release number
|
||||
# of a module. The release number is in format: "%Y%m%d%H%M%S"
|
||||
release_regex = re.compile("^(\d){14}$")
|
||||
|
||||
section_start = module_str.rfind('-')
|
||||
module_str_first_part = module_str[section_start+1:]
|
||||
if release_regex.match(module_str_first_part):
|
||||
module_info['variant_release'] = module_str_first_part
|
||||
module_str = module_str[:section_start]
|
||||
section_start = module_str.rfind('-')
|
||||
module_info['variant_version'] = module_str[section_start+1:]
|
||||
else:
|
||||
module_info['variant_version'] = module_str_first_part
|
||||
module_info['variant_id'] = module_str[:section_start]
|
||||
module_info['variant_type'] = 'module'
|
||||
|
||||
return module_info
|
||||
|
@ -6,6 +6,7 @@ import os
|
||||
import sys
|
||||
import unittest
|
||||
import json
|
||||
import re
|
||||
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
||||
|
||||
@ -198,5 +199,28 @@ class TestSourceKoji(helpers.PungiTestCase):
|
||||
[mock.call('koji')])
|
||||
|
||||
|
||||
class TestCorrectNVR(helpers.PungiTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestCorrectNVR, self).setUp()
|
||||
self.nv = "base-runtime-f26"
|
||||
self.nvr = "base-runtime-f26-20170502134116"
|
||||
self.release_regex = re.compile("^(\d){14}$")
|
||||
|
||||
def test_nv(self):
|
||||
module_info = source_koji.variant_dict_from_str(self.nv)
|
||||
expectedKeys = ["variant_version", "variant_id", "variant_type"]
|
||||
self.assertItemsEqual(module_info.keys(), expectedKeys)
|
||||
|
||||
def test_nvr(self):
|
||||
module_info = source_koji.variant_dict_from_str(self.nvr)
|
||||
expectedKeys = ["variant_version", "variant_id", "variant_type", "variant_release"]
|
||||
self.assertItemsEqual(module_info.keys(), expectedKeys)
|
||||
|
||||
def test_correct_release(self):
|
||||
module_info = source_koji.variant_dict_from_str(self.nvr)
|
||||
self.assertIsNotNone(self.release_regex.match(module_info["variant_release"]))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
Loading…
Reference in New Issue
Block a user