aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Stokes <adam.stokes@ubuntu.com>2014-08-19 10:31:14 -0400
committerBryn M. Reeves <bmr@redhat.com>2014-08-22 14:27:04 +0100
commit1205f93711f4d2f281f740ce70a2ea0f3829ec70 (patch)
treeebc5aa3aa48bd360f05194a944570657b9c7beaf
parenteeeab006e9a587046b8867937f35af9516ab5623 (diff)
downloadsos-1205f93711f4d2f281f740ce70a2ea0f3829ec70.tar.gz
[policies] Add dist_version to policy class
Exposes a `dist_version` to be inherited by policy classes to provide distribution release numbers. For example, on Ubuntu calling this method would return with `14.04`. Fixes #216 Signed-off-by: Adam Stokes <adam.stokes@ubuntu.com>
-rw-r--r--sos/policies/__init__.py6
-rw-r--r--sos/policies/debian.py16
-rw-r--r--sos/policies/redhat.py2
-rw-r--r--sos/policies/ubuntu.py13
4 files changed, 29 insertions, 8 deletions
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py
index 5262785a..89bc6760 100644
--- a/sos/policies/__init__.py
+++ b/sos/policies/__init__.py
@@ -179,6 +179,12 @@ No changes will be made to system configuration.
"""
return False
+ def dist_version(self):
+ """
+ Return the OS version
+ """
+ pass
+
def get_preferred_archive(self):
"""
Return the class object of the prefered archive format for this
diff --git a/sos/policies/debian.py b/sos/policies/debian.py
index a2834f7e..564f5c6b 100644
--- a/sos/policies/debian.py
+++ b/sos/policies/debian.py
@@ -30,14 +30,16 @@ class DebianPolicy(LinuxPolicy):
It returns True or False."""
return os.path.isfile('/etc/debian_version')
- def debianVersion(self):
+ def dist_version(self):
try:
- fp = open("/etc/debian_version").read()
- if "wheezy/sid" in fp:
- return 6
- fp.close()
+ with open('/etc/lsb-release', 'r') as fp:
+ rel_string = fp.read()
+ if "wheezy/sid" in rel_string:
+ return 6
+ elif "jessie/sid" in rel_string:
+ return 7
+ return False
except:
- pass
- return False
+ return False
# vim: et ts=4 sw=4
diff --git a/sos/policies/redhat.py b/sos/policies/redhat.py
index fa26a855..22192463 100644
--- a/sos/policies/redhat.py
+++ b/sos/policies/redhat.py
@@ -128,7 +128,7 @@ No changes will be made to system configuration.
return (os.path.isfile('/etc/redhat-release')
and not os.path.isfile('/etc/fedora-release'))
- def rhel_version(self):
+ def dist_version(self):
try:
pkg = self.pkg_by_name("redhat-release") or \
self.all_pkgs_by_name_regex("redhat-release-.*")[-1]
diff --git a/sos/policies/ubuntu.py b/sos/policies/ubuntu.py
index 4436df18..4c87ecaa 100644
--- a/sos/policies/ubuntu.py
+++ b/sos/policies/ubuntu.py
@@ -23,4 +23,17 @@ class UbuntuPolicy(DebianPolicy):
except:
return False
+ def dist_version(self):
+ """ Returns the version stated in DISTRIB_RELEASE
+ """
+ try:
+ with open('/etc/lsb-release', 'r') as fp:
+ lines = fp.readlines()
+ for line in lines:
+ if "DISTRIB_RELEASE" in line:
+ return line.split("=")[1].strip()
+ return False
+ except:
+ return False
+
# vim: et ts=4 sw=4