[Reportbug-commits] [reportbug] 02/02: include init system information in bug reports; thanks to Yves-Alexis Perez for the report and debian-devel ml for suggestions and inputs; Closes #741930

Sandro Tosi morph at moszumanska.debian.org
Fri Nov 7 14:18:20 UTC 2014


This is an automated email from the git hooks/post-receive script.

morph pushed a commit to branch master
in repository reportbug.

commit 0f09bcf95e5cbe13c2113e1eb83f14ecb331e53b
Author: Sandro Tosi <morph at debian.org>
Date:   Fri Nov 7 14:17:56 2014 +0000

    include init system information in bug reports; thanks to Yves-Alexis Perez for the report and debian-devel ml for suggestions and inputs; Closes #741930
---
 debian/changelog       |  5 +++++
 reportbug/bugreport.py |  3 +++
 reportbug/utils.py     | 14 ++++++++++++++
 test/test_utils.py     | 28 ++++++++++++++++++++++++++++
 4 files changed, 50 insertions(+)

diff --git a/debian/changelog b/debian/changelog
index 2609f94..2f9d8c6 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -3,6 +3,11 @@ reportbug (6.6.1) UNRELEASED; urgency=medium
   * reportbug/utils.py
     - don't split multiarch information on multiple lines; thanks to James
       Cowgill for the report; Closes: #759690
+  * reportbug/{bugreport.py, utils.py}
+    - include init system information in bug reports; thanks to Yves-Alexis
+      Perez for the report and debian-devel ml for suggestions and inputs;
+      Closes #741930
+
 
  -- Sandro Tosi <morph at debian.org>  Thu, 06 Nov 2014 22:08:34 +0000
 
diff --git a/reportbug/bugreport.py b/reportbug/bugreport.py
index 2062c52..ad47419 100644
--- a/reportbug/bugreport.py
+++ b/reportbug/bugreport.py
@@ -80,6 +80,7 @@ class bugreport(object):
         un = os.uname()
         debinfo = u''
         shellpath = utils.realpath('/bin/sh')
+        init = utils.get_init_system()
 
         locinfo = []
         langsetting = os.environ.get('LANG', 'C')
@@ -174,6 +175,8 @@ class bugreport(object):
             debinfo += u'Locale: %s\n' % locinfo
         if shellpath != '/bin/sh':
             debinfo += u'Shell: /bin/sh linked to %s\n' % shellpath
+        if init:
+            debinfo += u'Init: %s\n' % init
 
         # Don't include system info for certain packages
         if self.sysinfo:
diff --git a/reportbug/utils.py b/reportbug/utils.py
index 2ef17a9..fd93aef 100644
--- a/reportbug/utils.py
+++ b/reportbug/utils.py
@@ -1226,3 +1226,17 @@ def check_package_name(pkg):
     pkg_re = re.compile('^[a-z0-9][a-z0-9+-\.]+$')
 
     return True if pkg_re.match(pkg) else False
+
+def get_init_system():
+    """Determines the init system on the current machine"""
+
+    init = 'unable to detect'
+
+    if os.path.isdir('/run/systemd/system'):
+        init = 'systemd (via /run/systemd/system)'
+    if not subprocess.call('. /lib/lsb/init-functions ; init_is_upstart', shell=True):
+        init = 'upstart (via init_is_upstart())'
+    elif os.path.isfile('/sbin/init') and not os.path.islink('/sbin/init'):
+        init = 'sysvinit (via /sbin/init)'
+
+    return init
diff --git a/test/test_utils.py b/test/test_utils.py
index eae3d91..b16d497 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -7,6 +7,7 @@ from nose.plugins.attrib import attr
 import debianbts
 import mock
 import commands
+import subprocess
 
 class TestUtils(unittest2.TestCase):
 
@@ -284,6 +285,33 @@ class TestSystemInformation(unittest2.TestCase):
 
         commands.getoutput = orig
 
+    def test_get_init_system(self):
+
+        __save = os.path.isdir
+        os.path.isdir = mock.MagicMock(return_value = True)
+        init = utils.get_init_system()
+        self.assertTrue(init.startswith('systemd'))
+        os.path.isdir = __save
+        del __save
+
+        __save = subprocess.call
+        subprocess.call = mock.MagicMock(return_value = 0)
+        init = utils.get_init_system()
+        self.assertTrue(init.startswith('upstart'))
+        subprocess.call = __save
+        del __save
+
+        __save1 = os.path.isfile
+        __save2 = os.path.islink
+        os.path.isfile = mock.MagicMock(return_value = True)
+        os.path.islink = mock.MagicMock(return_value = False)
+        init = utils.get_init_system()
+        self.assertTrue(init.startswith('sysvinit'))
+        os.path.isfile = __save1
+        os.path.islink = __save2
+        del __save1
+        del __save2
+
 class TestMua(unittest2.TestCase):
 
     def test_mua_is_supported(self):

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reportbug/reportbug.git



More information about the Reportbug-commits mailing list