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')