Skip to content

Commit 554ecd1

Browse files
hack/build-image: add _split_img method
Split the existing function used to break up a container name into parts into a smaller reusable function. Signed-off-by: John Mulligan <[email protected]>
1 parent 159fd6f commit 554ecd1

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

hack/build-image

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,17 @@ class RepoConfig:
366366
return self.distro_map.get(distro, self.default)
367367

368368

369+
def _split_img(image_name, max_tag_split=3):
370+
if "/" in image_name:
371+
base, rest = image_name.rsplit("/", 1)
372+
else:
373+
base = ""
374+
rest = image_name
375+
iname, tag = rest.split(":", 1)
376+
tparts = tag.split("-", max_tag_split)
377+
return base, iname, tparts
378+
379+
369380
class TargetImage:
370381
def __init__(
371382
self, name, pkg_source, distro, arch, extra_tag="", *, repo_base=""
@@ -414,13 +425,7 @@ class TargetImage:
414425

415426
@classmethod
416427
def parse(cls, image_name):
417-
if "/" in image_name:
418-
base, rest = image_name.rsplit("/", 1)
419-
else:
420-
base = ""
421-
rest = image_name
422-
iname, tag = rest.split(":", 1)
423-
tparts = tag.split("-", 3)
428+
base, iname, tparts = _split_img(image_name)
424429
if len(tparts) < 3:
425430
raise ValueError(f"too few tag components: {tag!r}")
426431
return cls(

0 commit comments

Comments
 (0)