From 4d117d17f8ae2f2487b76956f90d3de5faad8164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Fri, 14 Jul 2017 10:41:17 +0200 Subject: [PATCH] util: Fix finding older compose MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ář --- pungi/util.py | 10 +++++++++- tests/test_util.py | 6 ++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pungi/util.py b/pungi/util.py index 7be2cb84..40d38305 100644 --- a/pungi/util.py +++ b/pungi/util.py @@ -388,6 +388,14 @@ def find_old_compose(old_compose_dirs, release_short, release_version, base_product_short=None, base_product_version=None): 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): if not os.path.isdir(compose_dir): continue @@ -419,7 +427,7 @@ def find_old_compose(old_compose_dirs, release_short, release_version, try: with open(status_path, 'r') as f: 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: continue diff --git a/tests/test_util.py b/tests/test_util.py index cb40ece3..028fceee 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -228,6 +228,12 @@ class TestFindOldCompose(unittest.TestCase): old = util.find_old_compose(self.tmp_dir, 'Fedora', 'Rawhide') 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): 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')