From 1d73dbb8fc856bd99a43fac21667ecc69b62a539 Mon Sep 17 00:00:00 2001 From: "D. Paolella" Date: Thu, 21 Nov 2024 11:21:10 +0100 Subject: [PATCH] Move isolate_timestamp_in_release() to artcommon --- artcommon/artcommonlib/release_util.py | 18 ++++++++++++ artcommon/tests/test_util.py | 31 +++++++++++++++++++- doozer/doozerlib/cli/scan_sources.py | 8 ++--- doozer/doozerlib/cli/scan_sources_konflux.py | 2 +- doozer/doozerlib/util.py | 18 ------------ doozer/tests/test_util.py | 29 ------------------ 6 files changed, 53 insertions(+), 53 deletions(-) diff --git a/artcommon/artcommonlib/release_util.py b/artcommon/artcommonlib/release_util.py index eb3fdd1e3..abe2b6f5e 100644 --- a/artcommon/artcommonlib/release_util.py +++ b/artcommon/artcommonlib/release_util.py @@ -52,6 +52,24 @@ def isolate_el_version_in_release(release: str) -> Optional[int]: return None +def isolate_timestamp_in_release(release: str) -> Optional[str]: + """ + Given a release field, determines whether is contains + a timestamp. If it does, it returns the timestamp. + If it is not found, None is returned. + """ + match = re.search(r"(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})", release) # yyyyMMddHHmm + if match: + year = int(match.group(1)) + month = int(match.group(2)) + day = int(match.group(3)) + hour = int(match.group(4)) + minute = int(match.group(5)) + if year >= 2000 and month >= 1 and month <= 12 and day >= 1 and day <= 31 and hour <= 23 and minute <= 59: + return match.group(0) + return None + + class SoftwareLifecyclePhase(Enum): PRE_RELEASE = 0 SIGNING = 1 diff --git a/artcommon/tests/test_util.py b/artcommon/tests/test_util.py index 8b08d5a13..e04f6acf8 100644 --- a/artcommon/tests/test_util.py +++ b/artcommon/tests/test_util.py @@ -3,7 +3,7 @@ import yaml from artcommonlib import util, build_util, release_util -from artcommonlib.model import Model, MissingModel +from artcommonlib.model import Model from artcommonlib.release_util import SoftwareLifecyclePhase from artcommonlib.util import deep_merge, isolate_major_minor_in_group @@ -226,3 +226,32 @@ def test_eq(self): self.assertEqual(SoftwareLifecyclePhase.PRE_RELEASE, 0) self.assertEqual(SoftwareLifecyclePhase.EOL.value, 100) self.assertNotEqual(SoftwareLifecyclePhase.EOL.value, 101) + + def test_isolate_timestamp_in_release(self): + actual = release_util.isolate_timestamp_in_release("foo-4.7.0-202107021813.p0.g01c9f3f.el8") + expected = "202107021813" + self.assertEqual(actual, expected) + + actual = release_util.isolate_timestamp_in_release("foo-container-v4.7.0-202107021907.p0.g8b4b094") + expected = "202107021907" + self.assertEqual(actual, expected) + + actual = release_util.isolate_timestamp_in_release("foo-container-v4.7.0-202107021907.p0.g8b4b094") + expected = "202107021907" + self.assertEqual(actual, expected) + + actual = release_util.isolate_timestamp_in_release("foo-container-v4.8.0-202106152230.p0.g25122f5.assembly.stream") + expected = "202106152230" + self.assertEqual(actual, expected) + + actual = release_util.isolate_timestamp_in_release("foo-container-v4.7.0-1.p0.g8b4b094") + expected = None + self.assertEqual(actual, expected) + + actual = release_util.isolate_timestamp_in_release("foo-container-v4.7.0-202199999999.p0.g8b4b094") + expected = None + self.assertEqual(actual, expected) + + actual = release_util.isolate_timestamp_in_release("") + expected = None + self.assertEqual(actual, expected) diff --git a/doozer/doozerlib/cli/scan_sources.py b/doozer/doozerlib/cli/scan_sources.py index 72e3ebdc6..62fe8d7cc 100644 --- a/doozer/doozerlib/cli/scan_sources.py +++ b/doozer/doozerlib/cli/scan_sources.py @@ -7,11 +7,11 @@ from typing import List, Tuple, Optional import artcommonlib.util -from artcommonlib import exectools +from artcommonlib import exectools, release_util from artcommonlib.model import Missing from artcommonlib.pushd import Dir from artcommonlib.rhcos import get_primary_container_name -from doozerlib import brew, rhcos, util +from doozerlib import brew, rhcos from doozerlib.cli import cli, pass_runtime, click_coroutine from doozerlib.cli import release_gen_payload as rgp from doozerlib.image import ImageMetadata @@ -328,7 +328,7 @@ def find_oldest_newest(self, koji_api, build_info): self.newest_image_event_ts = create_event_ts def check_dependents(self, image_meta: ImageMetadata, build_info): - rebase_time = util.isolate_timestamp_in_release(build_info["release"]) + rebase_time = release_util.isolate_timestamp_in_release(build_info["release"]) if not rebase_time: # no timestamp string in NVR? return @@ -354,7 +354,7 @@ def _check_dep(dep_key): if not dep_info: return - dep_rebase_time = util.isolate_timestamp_in_release(dep_info["release"]) + dep_rebase_time = release_util.isolate_timestamp_in_release(dep_info["release"]) if not dep_rebase_time: # no timestamp string in NVR? return diff --git a/doozer/doozerlib/cli/scan_sources_konflux.py b/doozer/doozerlib/cli/scan_sources_konflux.py index c5d6471ae..083cfd968 100644 --- a/doozer/doozerlib/cli/scan_sources_konflux.py +++ b/doozer/doozerlib/cli/scan_sources_konflux.py @@ -21,7 +21,7 @@ from doozerlib.metadata import RebuildHint, RebuildHintCode, Metadata from doozerlib.runtime import Runtime from doozerlib.source_resolver import SourceResolver -from doozerlib.util import isolate_timestamp_in_release +from artcommonlib.release_util import isolate_timestamp_in_release DEFAULT_THRESHOLD_HOURS = 6 diff --git a/doozer/doozerlib/util.py b/doozer/doozerlib/util.py index a32453b56..79fa3d9f7 100644 --- a/doozer/doozerlib/util.py +++ b/doozer/doozerlib/util.py @@ -357,24 +357,6 @@ def strip_epoch(nvr: str): return nvr.split(':')[0] -def isolate_timestamp_in_release(release: str) -> Optional[str]: - """ - Given a release field, determines whether is contains - a timestamp. If it does, it returns the timestamp. - If it is not found, None is returned. - """ - match = re.search(r"(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})", release) # yyyyMMddHHmm - if match: - year = int(match.group(1)) - month = int(match.group(2)) - day = int(match.group(3)) - hour = int(match.group(4)) - minute = int(match.group(5)) - if year >= 2000 and month >= 1 and month <= 12 and day >= 1 and day <= 31 and hour <= 23 and minute <= 59: - return match.group(0) - return None - - def get_release_tag_datetime(release: str) -> Optional[str]: match = re.search(r"(\d{4})-(\d{2})-(\d{2})-(\d{6})", release) # yyyy-MM-dd-HHmmss if match: diff --git a/doozer/tests/test_util.py b/doozer/tests/test_util.py index 2fa546b25..5f56a50b1 100644 --- a/doozer/tests/test_util.py +++ b/doozer/tests/test_util.py @@ -36,35 +36,6 @@ def test_bogus_arch_xlate(self): with self.assertRaises(Exception): brew_arch_for_go_arch("bogus") - def test_isolate_timestamp_in_release(self): - actual = util.isolate_timestamp_in_release("foo-4.7.0-202107021813.p0.g01c9f3f.el8") - expected = "202107021813" - self.assertEqual(actual, expected) - - actual = util.isolate_timestamp_in_release("foo-container-v4.7.0-202107021907.p0.g8b4b094") - expected = "202107021907" - self.assertEqual(actual, expected) - - actual = util.isolate_timestamp_in_release("foo-container-v4.7.0-202107021907.p0.g8b4b094") - expected = "202107021907" - self.assertEqual(actual, expected) - - actual = util.isolate_timestamp_in_release("foo-container-v4.8.0-202106152230.p0.g25122f5.assembly.stream") - expected = "202106152230" - self.assertEqual(actual, expected) - - actual = util.isolate_timestamp_in_release("foo-container-v4.7.0-1.p0.g8b4b094") - expected = None - self.assertEqual(actual, expected) - - actual = util.isolate_timestamp_in_release("foo-container-v4.7.0-202199999999.p0.g8b4b094") - expected = None - self.assertEqual(actual, expected) - - actual = util.isolate_timestamp_in_release("") - expected = None - self.assertEqual(actual, expected) - def test_get_release_name_for_assembly(self): releases_config = Model({ "releases": {