Skip to content

Instantly share code, notes, and snippets.

@SEJeff
Created July 7, 2011 04:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SEJeff/1068876 to your computer and use it in GitHub Desktop.
Save SEJeff/1068876 to your computer and use it in GitHub Desktop.
API fix for apt.list_pkgs
jeff@desktopmonster:~/src/git/salt/salt/modules (misc-fixes)$ gdi apt.py
diff --git a/salt/modules/apt.py b/salt/modules/apt.py
index f3b0cd8..75751a4 100644
--- a/salt/modules/apt.py
+++ b/salt/modules/apt.py
@@ -196,7 +196,7 @@ def upgrade(refresh=True):
return ret_pkgs
-def list_pkgs(regex_string=""):
+def list_pkgs(package_name="", regex_string=""):
'''
List the packages currently installed in a dict:
{'<package_name>': '<version>'}
@@ -205,12 +205,16 @@ def list_pkgs(regex_string=""):
salt '*' pkg.list_pkgs
'''
ret = {}
- cmd = 'dpkg --list ' + regex_string
+ cmd = 'dpkg --list ' + package_name
out = subprocess.Popen(cmd,
shell=True,
stdout=subprocess.PIPE).communicate()[0].split('\n')
+ if regex_string:
+ regex = re.compile(regex_string)
+ out = filter(regex.match, out)
+
for line in out:
cols = line.split()
if len(cols) and cols[0].count('ii'):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment