util: Fix finding older compose
When there are composes with two digit respin, the code would prefer 9 over 10 as latest. Respin needs to be treated as a number. Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
parent
910f816be4
commit
4d117d17f8
@ -388,6 +388,14 @@ def find_old_compose(old_compose_dirs, release_short, release_version,
|
|||||||
base_product_short=None, base_product_version=None):
|
base_product_short=None, base_product_version=None):
|
||||||
composes = []
|
composes = []
|
||||||
|
|
||||||
|
def _sortable(compose_id):
|
||||||
|
"""Convert ID to tuple where respin is an integer for proper sorting."""
|
||||||
|
try:
|
||||||
|
prefix, respin = compose_id.rsplit('.', 1)
|
||||||
|
return (prefix, int(respin))
|
||||||
|
except Exception:
|
||||||
|
return compose_id
|
||||||
|
|
||||||
for compose_dir in force_list(old_compose_dirs):
|
for compose_dir in force_list(old_compose_dirs):
|
||||||
if not os.path.isdir(compose_dir):
|
if not os.path.isdir(compose_dir):
|
||||||
continue
|
continue
|
||||||
@ -419,7 +427,7 @@ def find_old_compose(old_compose_dirs, release_short, release_version,
|
|||||||
try:
|
try:
|
||||||
with open(status_path, 'r') as f:
|
with open(status_path, 'r') as f:
|
||||||
if f.read().strip() in ("FINISHED", "FINISHED_INCOMPLETE", "DOOMED"):
|
if f.read().strip() in ("FINISHED", "FINISHED_INCOMPLETE", "DOOMED"):
|
||||||
composes.append((i, os.path.abspath(path)))
|
composes.append((_sortable(i), os.path.abspath(path)))
|
||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -228,6 +228,12 @@ class TestFindOldCompose(unittest.TestCase):
|
|||||||
old = util.find_old_compose(self.tmp_dir, 'Fedora', 'Rawhide')
|
old = util.find_old_compose(self.tmp_dir, 'Fedora', 'Rawhide')
|
||||||
self.assertEqual(old, self.tmp_dir + '/Fedora-Rawhide-20160229.1')
|
self.assertEqual(old, self.tmp_dir + '/Fedora-Rawhide-20160229.1')
|
||||||
|
|
||||||
|
def test_find_latest_with_two_digit_respin(self):
|
||||||
|
touch(self.tmp_dir + '/Fedora-Rawhide-20160228.n.9/STATUS', 'FINISHED')
|
||||||
|
touch(self.tmp_dir + '/Fedora-Rawhide-20160228.n.10/STATUS', 'FINISHED')
|
||||||
|
old = util.find_old_compose(self.tmp_dir, 'Fedora', 'Rawhide')
|
||||||
|
self.assertEqual(old, self.tmp_dir + '/Fedora-Rawhide-20160228.n.10')
|
||||||
|
|
||||||
def test_finds_ignores_other_files(self):
|
def test_finds_ignores_other_files(self):
|
||||||
touch(self.tmp_dir + '/Fedora-Rawhide-20160229.0', 'not a compose')
|
touch(self.tmp_dir + '/Fedora-Rawhide-20160229.0', 'not a compose')
|
||||||
touch(self.tmp_dir + '/Fedora-Rawhide-20160228.0/STATUS/file', 'also not a compose')
|
touch(self.tmp_dir + '/Fedora-Rawhide-20160228.0/STATUS/file', 'also not a compose')
|
||||||
|
Loading…
Reference in New Issue
Block a user