blob: 7cac74fd864d8f877cda041c39f727ceaca2ae96 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
import os
from sos.policies import PackageManager, LinuxPolicy
from sos.plugins import Plugin
from sos.utilities import shell_out
class ArchPolicy(LinuxPolicy):
distro = "Arch Linux"
vendor = "Arch Linux"
vendor_url = "https://www.archlinux.org/"
vendor_text = ""
#package_manager = PackageManager("pacman --query | awk 'BEGIN {OFS = \"|\"} {print $1,$2}'")
valid_subclasses = [Plugin]
def __init__(self, sysroot=None):
super(LinuxPolicy, self).__init__(sysroot=sysroot)
self.package_manager = Pacman()
@classmethod
def check(cls):
"""This method checks to see if we are running on Arch.
It returns True or False."""
try:
with open('/etc/os-release', 'r') as f:
return "archlinux" in f.read()
except:
return False
# this subclass is only needed because sos_get_command_output()
# in utilities.py sets shell=False so the pipe to awk in the
# command below used to format pacman output does not work
# pacman --query | awk 'BEGIN {OFS = \"|\"} {print $1,$2}'
class Pacman(PackageManager):
def get_pkg_list(self):
cmd = "pacman --query"
pkg_list = shell_out(
cmd, timeout=0, chroot=self.chroot
).splitlines()
for pkg in pkg_list:
name, version = pkg.split()
self.packages[name] = {
'name': name,
'version': version.split(".")
}
return self.packages
|