diff options
author | Pavel Moravec <pmoravec@redhat.com> | 2019-12-11 22:16:57 +0100 |
---|---|---|
committer | Pavel Moravec <pmoravec@redhat.com> | 2019-12-11 22:16:57 +0100 |
commit | 416313e48657428fb172ed649a411954b1a343fa (patch) | |
tree | b5a104ee1473bd1f0cdfab9daf19831c9e2fd08b | |
parent | 40cfbd26a64d33cd3ed87edbf8d2b248d339ad9b (diff) | |
download | sos-416313e48657428fb172ed649a411954b1a343fa.tar.gz |
[dnf] Use output from command instead of reading file
As the installed module loop uses `collect_cmd_output`, we can just
iterate over the output directly, rather than re-reading the contents
into memory a second time via the saved file.
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
-rw-r--r-- | sos/plugins/dnf.py | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/sos/plugins/dnf.py b/sos/plugins/dnf.py index 8c878e1a..754ca26a 100644 --- a/sos/plugins/dnf.py +++ b/sos/plugins/dnf.py @@ -24,20 +24,16 @@ class DNFPlugin(Plugin, RedHatPlugin): ("history-info", "detailed transaction history", "slow", False), ] - def get_modules_info(self, module_file): - if module_file: - try: - module_out = open(module_file).read() - except IOError: - self._log_warn("could not read module list file") - return - # take just lines with the module names, i.e. containing "[i]" and - # not the "Hint: [d]efault, [e]nabled, [i]nstalled,.." - for line in module_out.splitlines(): - if "[i]" in line: - module = line.split()[0] - if module != "Hint:": - self.add_cmd_output("dnf module info " + module) + def get_modules_info(self, modules): + if not modules: + return + # take just lines with the module names, i.e. containing "[i]" and + # not the "Hint: [d]efault, [e]nabled, [i]nstalled,.." + for line in modules.splitlines(): + if "[i]" in line: + module = line.split()[0] + if module != "Hint:": + self.add_cmd_output("dnf module info " + module) def setup(self): self.add_copy_spec("/etc/dnf/") @@ -74,7 +70,7 @@ class DNFPlugin(Plugin, RedHatPlugin): self.add_cmd_output("dnf history info %d" % tr_id) # Get list of dnf installed modules and their details. - module_file = self.collect_cmd_output("dnf module list --installed") - self.get_modules_info(module_file['filename']) + modules = self.collect_cmd_output("dnf module list --installed") + self.get_modules_info(modules['output']) # vim: set et ts=4 sw=4 : |