Permalink
Browse files

update apt module to use cross calls

  • Loading branch information...
thatch45 committed Nov 26, 2011
1 parent 6c1e931 commit 682f7c3cb5f84f5217a68987b3503f2b28e2f86d
Showing with 9 additions and 17 deletions.
  1. +9 −17 salt/modules/apt.py
View
@@ -2,9 +2,6 @@
Support for APT (Advanced Packaging Tool)
'''
-# FIXME: we want module internal calls rather than using subprocess direclty
-import subprocess
-
def __virtual__():
'''
@@ -25,9 +22,7 @@ def available_version(name):
version = ''
cmd = 'apt-cache show {0} | grep Version'.format(name)
- out = subprocess.Popen(cmd,
- shell=True,
- stdout=subprocess.PIPE).communicate()[0]
+ out = __salt__['cmd.stdout'](cmd)
version_list = out.split()
if len(version_list) >= 2:
@@ -65,9 +60,8 @@ def refresh_db():
salt '*' pkg.refresh_db
'''
cmd = 'apt-get update'
- out = subprocess.Popen(cmd,
- shell=True,
- stdout=subprocess.PIPE).communicate()[0].split('\n')
+
+ out = __salt__['cmd.stdout'](cmd)
servers = {}
for line in out:
@@ -96,13 +90,13 @@ def install(pkg, refresh=False):
salt '*' pkg.install <package name>
'''
- if(refresh):
+ if refresh:
refresh_db()
ret_pkgs = {}
old_pkgs = list_pkgs()
cmd = 'apt-get -y install {0}'.format(pkg)
- subprocess.call(cmd, shell=True)
+ __salt__['cmd.redcode'](cmd)
new_pkgs = list_pkgs()
for pkg in new_pkgs:
@@ -133,7 +127,7 @@ def remove(pkg):
old_pkgs = list_pkgs()
cmd = 'apt-get -y remove {0}'.format(pkg)
- subprocess.call(cmd, shell=True)
+ __salt__['cmd.retcode'](cmd)
new_pkgs = list_pkgs()
for pkg in old_pkgs:
if pkg not in new_pkgs:
@@ -158,7 +152,7 @@ def purge(pkg):
# Remove inital package
purge_cmd = 'apt-get -y purge {0}'.format(pkg)
- subprocess.call(purge_cmd, shell=True)
+ __salt__['cmd.retcode'](purge_cmd)
new_pkgs = list_pkgs()
@@ -194,7 +188,7 @@ def upgrade(refresh=True):
ret_pkgs = {}
old_pkgs = list_pkgs()
cmd = 'apt-get -y dist-upgrade'
- subprocess.call(cmd, shell=True)
+ __salt__['cmd.retcode'](cmd)
new_pkgs = list_pkgs()
for pkg in new_pkgs:
@@ -224,9 +218,7 @@ def list_pkgs(regex_string=""):
ret = {}
cmd = 'dpkg --list {0}'.format(regex_string)
- out = subprocess.Popen(cmd,
- shell=True,
- stdout=subprocess.PIPE).communicate()[0].split('\n')
+ __salt__['cmd.stdout'](cmd)
for line in out:
cols = line.split()

0 comments on commit 682f7c3

Please sign in to comment.