[PATCH blivet] If /etc/os-release exists, check it to identify an installed system.

Brian C. Lane bcl at redhat.com
Thu Feb 13 01:08:37 UTC 2014


On Wed, Feb 12, 2014 at 01:54:15PM -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):

Could you document the new functions with sphinx docs?

> +    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
> +
> +    with open(fn, "r") as f:
> +        parser = shlex.shlex(f)
> +
> +        while True:
> +            key = parser.get_token()
> +            if key == parser.eof:
> +                break
> +            elif key == "NAME":
> +                # Throw away the "=".
> +                parser.get_token()
> +                relName = unquote(parser.get_token())
> +            elif key == "VERSION_ID":
> +                # Throw away the "=".
> +                parser.get_token()
> +                relVer = unquote(parser.get_token())
> +
> +    return (relName, relVer)

It may be cleaner to just read it with our SimpleConfigFile class. That
should handle quotes and even inline comments.


-- 
Brian C. Lane | Anaconda Team | IRC: bcl #anaconda | Port Orchard, WA (PST8PDT)


More information about the anaconda-patches mailing list