aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouis Bouchard <louis.bouchard@canonical.com>2014-09-12 16:37:37 +0200
committerAdam Stokes <adam.stokes@ubuntu.com>2014-09-17 14:04:55 -0400
commit946526d4151a22254341e756b83601a546f313f1 (patch)
treeafb36e8cffdf46f2a8654ab9bde36493b0a5c5a4
parent360a5c4e18fbf0e1598227587d5894d4c90b986e (diff)
downloadsos-946526d4151a22254341e756b83601a546f313f1.tar.gz
[apt] switching shell crap to python syntax
Avoid long string of piped shell commands at all cost Fixes: #398 Signed-off-by: Louis Bouchard <louis.bouchard@canonical.com>
-rw-r--r--sos/plugins/apt.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/sos/plugins/apt.py b/sos/plugins/apt.py
index 6063bf9d..a5ed14d4 100644
--- a/sos/plugins/apt.py
+++ b/sos/plugins/apt.py
@@ -15,6 +15,7 @@
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
from sos.plugins import Plugin, UbuntuPlugin, DebianPlugin
+import pdb
class Apt(Plugin, DebianPlugin, UbuntuPlugin):
@@ -29,17 +30,17 @@ class Apt(Plugin, DebianPlugin, UbuntuPlugin):
"/etc/apt", "/var/log/apt"
])
- apt_cache_policy_ext = "sh -c '%s'" % (
- "dpkg -l | grep ^ii |"
- "cut -d \" \" -f3 |"
- "xargs apt-cache policy"
- )
+ dpkg_result = self.call_ext_prog(
+ "dpkg-query -W -f='${binary:Package}\t${status}\n'")
+ dpkg_output = dpkg_result['output'].splitlines()
+ pkg_list = ' '.join(
+ [v.split('\t')[0] for v in dpkg_output if 'ok installed' in v])
self.add_cmd_outputs([
"apt-get check",
"apt-config dump",
"apt-cache stats",
"apt-cache policy",
- apt_cache_policy_ext
+ "apt-cache policy {}".format(pkg_list)
])
# vim: et ts=4 sw=4