[dev-python/python-blivet] add support for /etc/sabayon-release

This commit is contained in:
Fabio Erculiani
2016-06-29 09:19:00 +02:00
parent 483d81dcec
commit f771cbb672
2 changed files with 55 additions and 0 deletions
@@ -0,0 +1,54 @@
From a02bdea93c25139effd7fa755b288c25f7226e35 Mon Sep 17 00:00:00 2001
From: Fabio Erculiani <lxnay@sabayon.org>
Date: Wed, 29 Jun 2016 09:17:36 +0200
Subject: [PATCH 4/4] Add support for parsing /etc/sabayon-release
---
blivet/osinstall.py | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/blivet/osinstall.py b/blivet/osinstall.py
index a2b1895..d198f77 100644
--- a/blivet/osinstall.py
+++ b/blivet/osinstall.py
@@ -106,6 +106,25 @@ def releaseFromOsRelease(fn):
return (relName, relVer)
+def releaseFromSabayonRelease(fn):
+ """
+ Attempt to identify the installation of a Linux distribution via
+ /etc/sabayon-release. This file must already have been verified to exist
+ and be readable.
+
+ :param fn: an open filehandle on /etc/sabayon-release
+ :type fn: filehandle
+ :returns: The distribution's name and version, or None for either or both
+ if they cannot be determined
+ :rtype: (string, string)
+ """
+ with open(fn, "r") as f:
+ rellist = f.readline().split()
+ relVer = rellist[-1]
+ relName = rellist[0]
+
+ return (relName, relVer)
+
def getReleaseString():
"""
Attempt to identify the installation of a Linux distribution by checking
@@ -125,8 +144,11 @@ def getReleaseString():
relArch = None
filename = "%s/etc/redhat-release" % getSysroot()
+ sabayon_filename = "%s/etc/sabayon-release" % getSysroot()
if os.access(filename, os.R_OK):
(relName, relVer) = releaseFromRedhatRelease(filename)
+ elif os.access(sabayon_filename, os.R_OK):
+ (relName, relVer) = releaseFromSabayonRelease(sabayon_filename)
else:
filename = "%s/etc/os-release" % getSysroot()
if os.access(filename, os.R_OK):
--
2.7.4