pungi-koji: Allow user to specify version component count in latest symlink
This change adds an option which allows users to specify the number of version components (i.e. values between dots) The default behavior is preserved, and is equivalent to using '-1' as the value. - Negative values remove items from the end. - Positive values specify the count of of components - Zero will remove the version field entirely from the symlink - When nonzero, at least one version component will appear Merges: https://pagure.io/pungi/pull-request/1361 Signed-off-by: Lon Hohberger <lhh@redhat.com>
This commit is contained in:
parent
3543f8fb3e
commit
9391ce3065
@ -151,6 +151,12 @@ def main():
|
|||||||
default=[],
|
default=[],
|
||||||
help="only create latest symbol link to this compose when compose status matches specified status", # noqa: E501
|
help="only create latest symbol link to this compose when compose status matches specified status", # noqa: E501
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--latest-link-components",
|
||||||
|
type=int,
|
||||||
|
default=-1,
|
||||||
|
help="number of product version components used when creating latest symlink", # noqa: E501
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--print-output-dir",
|
"--print-output-dir",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
@ -203,6 +209,7 @@ def main():
|
|||||||
|
|
||||||
create_latest_link = not opts.no_latest_link
|
create_latest_link = not opts.no_latest_link
|
||||||
latest_link_status = opts.latest_link_status or None
|
latest_link_status = opts.latest_link_status or None
|
||||||
|
latest_link_components = opts.latest_link_components
|
||||||
|
|
||||||
import kobo.conf
|
import kobo.conf
|
||||||
import kobo.log
|
import kobo.log
|
||||||
@ -289,10 +296,13 @@ def main():
|
|||||||
compose,
|
compose,
|
||||||
create_latest_link=create_latest_link,
|
create_latest_link=create_latest_link,
|
||||||
latest_link_status=latest_link_status,
|
latest_link_status=latest_link_status,
|
||||||
|
latest_link_components=latest_link_components,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def run_compose(compose, create_latest_link=True, latest_link_status=None):
|
def run_compose(
|
||||||
|
compose, create_latest_link=True, latest_link_status=None, latest_link_components=-1
|
||||||
|
):
|
||||||
import pungi.phases
|
import pungi.phases
|
||||||
import pungi.metadata
|
import pungi.metadata
|
||||||
import pungi.util
|
import pungi.util
|
||||||
@ -501,15 +511,19 @@ def run_compose(compose, create_latest_link=True, latest_link_status=None):
|
|||||||
|
|
||||||
if latest_link:
|
if latest_link:
|
||||||
compose_dir = os.path.basename(compose.topdir)
|
compose_dir = os.path.basename(compose.topdir)
|
||||||
if len(compose.conf["release_version"].split(".")) == 1:
|
# Omit version entirely if latest_link_components == 0
|
||||||
symlink_name = "latest-%s-%s" % (
|
if latest_link_components == 0:
|
||||||
compose.conf["release_short"],
|
symlink_name = "latest-%s" % compose.conf["release_short"]
|
||||||
compose.conf["release_version"],
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
|
hunks = compose.conf["release_version"].split(".")
|
||||||
|
# Set up our min/max so we don't overrun our array
|
||||||
|
if latest_link_components > 0:
|
||||||
|
latest_link_components = min(len(hunks), latest_link_components)
|
||||||
|
else:
|
||||||
|
latest_link_components = max(1, len(hunks) + latest_link_components)
|
||||||
symlink_name = "latest-%s-%s" % (
|
symlink_name = "latest-%s-%s" % (
|
||||||
compose.conf["release_short"],
|
compose.conf["release_short"],
|
||||||
".".join(compose.conf["release_version"].split(".")[:-1]),
|
".".join(hunks[:latest_link_components]),
|
||||||
)
|
)
|
||||||
if compose.conf.get("base_product_name", ""):
|
if compose.conf.get("base_product_name", ""):
|
||||||
symlink_name += "-%s-%s" % (
|
symlink_name += "-%s-%s" % (
|
||||||
|
Loading…
Reference in New Issue
Block a user