[OE-core] [PATCH 3/3] utils: add trim_version() function
Chris Larson
clarson at kergoth.com
Thu May 23 21:16:18 UTC 2013
On Thu, May 23, 2013 at 11:45 AM, Ross Burton <ross.burton at intel.com> wrote:
> +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
>
Another option would be to do something like:
def trim_version(version, num_parts=2):
v = distutils.version.LooseVersion(version)
return v.version[:num_parts]
--
Christopher Larson
clarson at kergoth dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Maintainer - Tslib
Senior Software Engineer, Mentor Graphics
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openembedded.org/pipermail/openembedded-core/attachments/20130523/19cbd354/attachment-0002.html>
More information about the Openembedded-core
mailing list