mirror of
https://git.yoctoproject.org/poky
synced 2026-05-30 00:20:08 +00:00
utils: add trim_version() function
Add a helper function that returns just the first <num_parts> of <version>,
split by periods. For example, trim_version("1.2.3", 2) will return "1.2".
This should help reduce the spread of numerous copies of this idea across
classes and recipes.
(From OE-Core rev: 17a12e3c62807a7d60fcbf0aa4fd9cf4a739a204)
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Saul Wold <sgw@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
f5d0f6becc
commit
fcfba0ddd9
@@ -135,3 +135,18 @@ def packages_filter_out_system(d):
|
||||
|
||||
def getstatusoutput(cmd):
|
||||
return cmdstatus.getstatusoutput(cmd)
|
||||
|
||||
|
||||
def trim_version(version, num_parts=2):
|
||||
"""
|
||||
Return just the first <num_parts> of <version>, split by periods. For
|
||||
example, trim_version("1.2.3", 2) will return "1.2".
|
||||
"""
|
||||
if type(version) is not str:
|
||||
raise TypeError("Version should be a string")
|
||||
if num_parts < 1:
|
||||
raise ValueError("Cannot split to parts < 1")
|
||||
|
||||
parts = version.split(".")
|
||||
trimmed = ".".join(parts[:num_parts])
|
||||
return trimmed
|
||||
|
||||
Reference in New Issue
Block a user