diff options
author | Ross Burton <ross.burton@intel.com> | 2013-05-23 18:45:01 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-05-30 20:59:09 +0100 |
commit | fcfba0ddd95fd459f03a4996c69ff5484aa4f083 (patch) | |
tree | 7527579d72475e34327fd564df9dbec27ac0e90d /meta/lib/oe/utils.py | |
parent | f5d0f6becc6d1eb3a525a9e66ffd8bba52e2ae4e (diff) | |
download | poky-fcfba0ddd95fd459f03a4996c69ff5484aa4f083.tar.gz |
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>
Diffstat (limited to 'meta/lib/oe/utils.py')
-rw-r--r-- | meta/lib/oe/utils.py | 15 |
1 files changed, 15 insertions, 0 deletions
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): | |||
135 | 135 | ||
136 | def getstatusoutput(cmd): | 136 | def getstatusoutput(cmd): |
137 | return cmdstatus.getstatusoutput(cmd) | 137 | return cmdstatus.getstatusoutput(cmd) |
138 | |||
139 | |||
140 | def trim_version(version, num_parts=2): | ||
141 | """ | ||
142 | Return just the first <num_parts> of <version>, split by periods. For | ||
143 | example, trim_version("1.2.3", 2) will return "1.2". | ||
144 | """ | ||
145 | if type(version) is not str: | ||
146 | raise TypeError("Version should be a string") | ||
147 | if num_parts < 1: | ||
148 | raise ValueError("Cannot split to parts < 1") | ||
149 | |||
150 | parts = version.split(".") | ||
151 | trimmed = ".".join(parts[:num_parts]) | ||
152 | return trimmed | ||