Fixes for run_command shell usage in remainder of packaging modules, save portinstall.

pull/5511/merge
Michael DeHaan 11 years ago
parent 6010e74839
commit 81b4ebbe1d

@ -58,13 +58,13 @@ import json
import shlex import shlex
import os import os
import sys import sys
import pipes
def query_package(module, pkgin_path, name, state="present"): def query_package(module, pkgin_path, name, state="present"):
if state == "present": if state == "present":
rc, out, err = module.run_command("%s -y list | grep ^%s" % (pkgin_path, name)) rc, out, err = module.run_command("%s -y list | grep ^%s" % (pipes.quote(pkgin_path), pipes.quote(name)), use_unsafe_shell=True)
if rc == 0: if rc == 0:
# At least one package with a package name that starts with ``name`` # At least one package with a package name that starts with ``name``

@ -58,13 +58,14 @@ pkgutil: name=CSWcommon state=present
# Install a package from a specific repository # Install a package from a specific repository
pkgutil: name=CSWnrpe site='ftp://myinternal.repo/opencsw/kiel state=latest' pkgutil: name=CSWnrpe site='ftp://myinternal.repo/opencsw/kiel state=latest'
''' '''
import os import os
import pipes
def package_installed(module, name): def package_installed(module, name):
cmd = [module.get_bin_path('pkginfo', True)] cmd = [module.get_bin_path('pkginfo', True)]
cmd.append('-q') cmd.append('-q')
cmd.append(name) cmd.append(name)
#rc, out, err = module.run_command(' '.join(cmd), shell=False)
rc, out, err = module.run_command(' '.join(cmd)) rc, out, err = module.run_command(' '.join(cmd))
if rc == 0: if rc == 0:
return True return True
@ -73,12 +74,14 @@ def package_installed(module, name):
def package_latest(module, name, site): def package_latest(module, name, site):
# Only supports one package # Only supports one package
name = pipes.quote(name)
site = pipes.quote(site)
cmd = [ 'pkgutil', '--single', '-c' ] cmd = [ 'pkgutil', '--single', '-c' ]
if site is not None: if site is not None:
cmd += [ '-t', site ] cmd += [ '-t', site ]
cmd.append(name) cmd.append(name)
cmd += [ '| tail -1 | grep -v SAME' ] cmd += [ '| tail -1 | grep -v SAME' ]
rc, out, err = module.run_command(' '.join(cmd)) rc, out, err = module.run_command(' '.join(cmd), use_unsafe_shell=True)
if rc == 1: if rc == 1:
return True return True
else: else:

@ -216,7 +216,6 @@ class Rhsm(RegistrationBase):
if password: if password:
args.extend(['--password', password]) args.extend(['--password', password])
# Do the needful...
rc, stderr, stdout = self.module.run_command(args, check_rc=True) rc, stderr, stdout = self.module.run_command(args, check_rc=True)
def unsubscribe(self): def unsubscribe(self):

@ -19,6 +19,7 @@
# along with this software. If not, see <http://www.gnu.org/licenses/>. # along with this software. If not, see <http://www.gnu.org/licenses/>.
import re import re
import pipes
DOCUMENTATION = ''' DOCUMENTATION = '''
--- ---
@ -78,9 +79,9 @@ def query_package(module, name, depot=None):
cmd_list = '/usr/sbin/swlist -a revision -l product' cmd_list = '/usr/sbin/swlist -a revision -l product'
if depot: if depot:
rc, stdout, stderr = module.run_command("%s -s %s %s | grep %s" % (cmd_list, depot, name, name)) rc, stdout, stderr = module.run_command("%s -s %s %s | grep %s" % (cmd_list, pipes.quote(depot), pipes.quote(name), pipes.quote(name)), use_unsafe_shell=True)
else: else:
rc, stdout, stderr = module.run_command("%s %s | grep %s" % (cmd_list, name, name)) rc, stdout, stderr = module.run_command("%s %s | grep %s" % (cmd_list, pipes.quote(name), pipes.quote(name)), use_unsafe_shell=True)
if rc == 0: if rc == 0:
version = re.sub("\s\s+|\t" , " ", stdout).strip().split()[1] version = re.sub("\s\s+|\t" , " ", stdout).strip().split()[1]
else: else:

@ -104,7 +104,7 @@ def query_package_provides(module, name):
# rpm -q returns 0 if the package is installed, # rpm -q returns 0 if the package is installed,
# 1 if it is not installed # 1 if it is not installed
cmd = "rpm -q --provides %s >/dev/null" % (name) cmd = "rpm -q --provides %s" % (name)
rc, stdout, stderr = module.run_command(cmd, check_rc=False) rc, stdout, stderr = module.run_command(cmd, check_rc=False)
return rc == 0 return rc == 0
@ -125,7 +125,7 @@ def remove_packages(module, packages):
if not query_package(module, package): if not query_package(module, package):
continue continue
cmd = "%s --auto %s > /dev/null" % (URPME_PATH, package) cmd = "%s --auto %s" % (URPME_PATH, package)
rc, stdout, stderr = module.run_command(cmd, check_rc=False) rc, stdout, stderr = module.run_command(cmd, check_rc=False)
if rc != 0: if rc != 0:
@ -158,7 +158,7 @@ def install_packages(module, pkgspec, force=True, no_suggests=True):
else: else:
force_yes = '' force_yes = ''
cmd = ("%s --auto %s --quiet %s %s > /dev/null" % (URPMI_PATH, force_yes, no_suggests_yes, packages)) cmd = ("%s --auto %s --quiet %s %s" % (URPMI_PATH, force_yes, no_suggests_yes, packages))
rc, out, err = module.run_command(cmd) rc, out, err = module.run_command(cmd)

Loading…
Cancel
Save