Skip to content

Commit

Permalink
[alternatives] Add ubuntu section
Browse files Browse the repository at this point in the history
Related: #3224
Signed-off-by: Arif Ali <arif.ali@canonical.com>
  • Loading branch information
arif-ali authored and TurboTurtle committed May 15, 2023
1 parent 76cf57c commit 24fa1f8
Showing 1 changed file with 47 additions and 13 deletions.
60 changes: 47 additions & 13 deletions sos/report/plugins/alternatives.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,17 @@
#
# See the LICENSE file in the source distribution for further information.

from sos.report.plugins import Plugin, RedHatPlugin
from sos.report.plugins import Plugin, RedHatPlugin, UbuntuPlugin


class Alternatives(Plugin, RedHatPlugin):
class Alternatives(Plugin):

short_desc = 'System alternatives'
plugin_name = 'alternatives'
packages = ('chkconfig',)
commands = ('alternatives',)

def setup(self):

self.add_cmd_tags({
"alternatives --display java.*": 'display_java',
"alternatives --display python.*":
'alternatives_display_python'
})

self.add_cmd_output('alternatives --version')
self.add_cmd_output('%s --version' % self.alternatives_cmd)

alts = []
ignore = [
Expand All @@ -37,13 +29,55 @@ def setup(self):
'xinputrc'
]

res = self.collect_cmd_output('alternatives --list')
res = self.collect_cmd_output(self.alternatives_list)
if res['status'] == 0:
for line in res['output'].splitlines():
alt = line.split()[0]
if alt not in ignore:
alts.append(alt)
disp_cmd = "alternatives --display %s"
disp_cmd = "%s --display %s" % (self.alternatives_cmd, "%s")
self.add_cmd_output([disp_cmd % alt for alt in alts])


class RedHatAlternatives(Alternatives, RedHatPlugin):

packages = ('alternatives',)
commands = ('alternatives',)

alternatives_cmd = 'alternatives'
alternatives_list = '%s --list' % alternatives_cmd

def setup(self):

super(RedHatAlternatives, self).setup()

self.add_cmd_tags({
"alternatives --display java.*": 'display_java',
"alternatives --display python.*":
'alternatives_display_python'
})


class UbuntuAlternatives(Alternatives, UbuntuPlugin):

packages = ('dpkg',)
commands = ('update-alternatives',)

alternatives_cmd = 'update-alternatives'
alternatives_list = '%s --get-selections' % alternatives_cmd

def setup(self):

super(UbuntuAlternatives, self).setup()

if self.get_option("all_logs"):
self.add_copy_spec([
"/var/log/alternatives.log*",
])
else:
self.add_copy_spec([
"/var/log/alternatives.log",
"/var/log/alternatives.log.1",
])

# vim: set et ts=4 sw=4 :

0 comments on commit 24fa1f8

Please sign in to comment.