[PATCH blivet] If /etc/os-release exists, check it to identify an installed system.
Vratislav Podzimek
vpodzime at redhat.com
Fri Feb 14 06:50:09 UTC 2014
On Wed, 2014-02-12 at 13:54 -0500, Chris Lumens wrote:
> This should allow us to identify and list installed OSes that do not have a
> redhat-release file (which is most of them), but are new enough to have an
> os-release file (which is probably not yet that many).
> ---
> blivet/__init__.py | 70 ++++++++++++++++++++++++++++++++++++++++++++----------
> 1 file changed, 57 insertions(+), 13 deletions(-)
>
> diff --git a/blivet/__init__.py b/blivet/__init__.py
> index 59b63ef..666959f 100644
> --- a/blivet/__init__.py
> +++ b/blivet/__init__.py
> @@ -53,6 +53,7 @@ import sys
> import statvfs
> import copy
> import tempfile
> +import shlex
>
> try:
> import nss.nss
> @@ -2962,6 +2963,57 @@ class FSSet(object):
>
> self._fstab_swaps = set(devices)
>
> +def releaseFromRedhatRelease(fn):
> + relName = None
> + relVer = None
> +
> + with open(fn) as f:
> + try:
> + relstr = f.readline().strip()
> + except (IOError, AttributeError):
> + relstr = ""
> +
> + # get the release name and version
> + # assumes that form is something
> + # like "Red Hat Linux release 6.2 (Zoot)"
> + (product, sep, version) = relstr.partition(" release ")
> + if sep:
> + relName = product
> + relVer = version.split()[0]
> +
> + return (relName, relVer)
> +
> +def releaseFromOsRelease(fn):
> + relName = None
> + relVer = None
> +
> + def unquote(s):
> + if s[0] == "\"" or s[0] == "\'":
> + s = s[1:]
> +
> + if s[-1] == "\"" or s[-1] == "\'":
> + s = s[:-1]
> +
> + return s
You could use s.strip('"\'"') instead of unquote. It would remove all
surrounding quotes, but I believe that shouldn't be an issue in this
case.
--
Vratislav Podzimek
Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic
More information about the anaconda-patches
mailing list