From 17a12e3c62807a7d60fcbf0aa4fd9cf4a739a204 Mon Sep 17 00:00:00 2001 From: Ross Burton Date: Thu, 23 May 2013 18:45:01 +0000 Subject: utils: add trim_version() function Add a helper function that returns just the first of , 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. Signed-off-by: Ross Burton Signed-off-by: Saul Wold Signed-off-by: Richard Purdie --- meta/lib/oe/utils.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'meta/lib/oe/utils.py') diff --git a/meta/lib/oe/utils.py b/meta/lib/oe/utils.py index 0a2092b24b..82987e80d0 100644 --- a/meta/lib/oe/utils.py +++ b/meta/lib/oe/utils.py @@ -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 of , 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 -- cgit 1.2.3-korg