Browse Source

[2062] Add OS distribution name

Mukund Sivaraman 13 years ago
parent
commit
5c6c47046b
2 changed files with 42 additions and 0 deletions
  1. 1 0
      src/bin/showtech/showtech.py.in
  2. 41 0
      src/lib/python/isc/sysinfo/sysinfo.py

+ 1 - 0
src/bin/showtech/showtech.py.in

@@ -35,6 +35,7 @@ def main():
 
 
     print('\nPlatform');
     print('\nPlatform');
     print(' + Operating system: ' + s.get_platform_name())
     print(' + Operating system: ' + s.get_platform_name())
+    print(' + Distribution: ' + s.get_platform_distro())
     print(' + Kernel version: ' + s.get_platform_version())
     print(' + Kernel version: ' + s.get_platform_version())
     if s.get_platform_is_smp():
     if s.get_platform_is_smp():
         print(' + SMP kernel: yes')
         print(' + SMP kernel: yes')

+ 41 - 0
src/lib/python/isc/sysinfo/sysinfo.py

@@ -18,6 +18,8 @@
 import os
 import os
 import sys
 import sys
 import re
 import re
+import subprocess
+import os.path
 
 
 class SysInfo:
 class SysInfo:
     def __init__(self):
     def __init__(self):
@@ -71,6 +73,42 @@ class SysInfo:
                     self._mem_swap_free = int(r.group(1).strip()) * 1024
                     self._mem_swap_free = int(r.group(1).strip()) * 1024
                     continue
                     continue
 
 
+        self._platform_distro = None
+
+        try:
+            s = subprocess.check_output(['lsb_release', '-a'])
+            for line in s.decode('utf-8').split('\n'):
+                r = re.match('^Description:(.*)', line)
+                if r:
+                    self._platform_distro = r.group(1).strip()
+                    break
+        except (subprocess.CalledProcessError, OSError):
+            pass
+
+        if self._platform_distro is None:
+            files = ['/etc/debian_release',
+                     '/etc/debian_version',
+                     '/etc/SuSE-release',
+                     '/etc/UnitedLinux-release',
+                     '/etc/mandrake-release',
+                     '/etc/gentoo-release',
+                     '/etc/fedora-release',
+                     '/etc/redhat-release',
+                     '/etc/redhat_version',
+                     '/etc/slackware-release',
+                     '/etc/slackware-version',
+                     '/etc/arch-release',
+                     '/etc/lsb-release',
+                     '/etc/mageia-release']
+            for fn in files:
+                if os.path.exists(fn):
+                    with open(fn) as f:
+                        self._platform_distro = f.read().strip()
+                    break
+
+        if self._platform_distro is None:
+            self._platform_distro = 'Unknown'
+
     def get_num_processors(self):
     def get_num_processors(self):
         # This is the number of hyperthreads when hyper-threading is
         # This is the number of hyperthreads when hyper-threading is
         # used. This is not entirely portable, so we'll have to handle
         # used. This is not entirely portable, so we'll have to handle
@@ -95,6 +133,9 @@ class SysInfo:
     def get_platform_is_smp(self):
     def get_platform_is_smp(self):
         return self._platform_is_smp
         return self._platform_is_smp
 
 
+    def get_platform_distro(self):
+        return self._platform_distro
+
     def get_uptime(self):
     def get_uptime(self):
         return self._uptime
         return self._uptime