mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Merge pull request #29816 from techhat/pacmanroot
Allow pacman to use alternate root dir
This commit is contained in:
commit
1b9d7a0940
@ -9,6 +9,7 @@ from __future__ import absolute_import
|
||||
import copy
|
||||
import logging
|
||||
import re
|
||||
import os.path
|
||||
|
||||
# Import salt libs
|
||||
import salt.utils
|
||||
@ -71,6 +72,10 @@ def latest_version(*names, **kwargs):
|
||||
ret[name] = ''
|
||||
cmd = ['pacman', '-Sp', '--needed', '--print-format', '%n %v']
|
||||
cmd.extend(names)
|
||||
|
||||
if 'root' in kwargs:
|
||||
cmd.extend(('-r', kwargs['root']))
|
||||
|
||||
out = __salt__['cmd.run_stdout'](cmd,
|
||||
output_loglevel='trace',
|
||||
python_shell=False)
|
||||
@ -115,7 +120,7 @@ def upgrade_available(name):
|
||||
return latest_version(name) != ''
|
||||
|
||||
|
||||
def list_upgrades(refresh=False):
|
||||
def list_upgrades(refresh=False, root=None):
|
||||
'''
|
||||
List all available package upgrades on this system
|
||||
|
||||
@ -128,6 +133,9 @@ def list_upgrades(refresh=False):
|
||||
upgrades = {}
|
||||
cmd = ['pacman', '-S', '-p', '-u', '--print-format', '%n %v']
|
||||
|
||||
if root is not None:
|
||||
cmd.extend(('-r', root))
|
||||
|
||||
if refresh:
|
||||
cmd.append('-y')
|
||||
|
||||
@ -198,6 +206,10 @@ def list_pkgs(versions_as_list=False, **kwargs):
|
||||
return ret
|
||||
|
||||
cmd = ['pacman', '-Q']
|
||||
|
||||
if 'root' in kwargs:
|
||||
cmd.extend(('-r', kwargs['root']))
|
||||
|
||||
ret = {}
|
||||
out = __salt__['cmd.run'](cmd, output_loglevel='trace', python_shell=False)
|
||||
for line in salt.utils.itertools.split(out, '\n'):
|
||||
@ -218,7 +230,7 @@ def list_pkgs(versions_as_list=False, **kwargs):
|
||||
return ret
|
||||
|
||||
|
||||
def refresh_db():
|
||||
def refresh_db(root=None):
|
||||
'''
|
||||
Just run a ``pacman -Sy``, return a dict::
|
||||
|
||||
@ -231,6 +243,10 @@ def refresh_db():
|
||||
salt '*' pkg.refresh_db
|
||||
'''
|
||||
cmd = ['pacman', '-Sy']
|
||||
|
||||
if root is not None:
|
||||
cmd.extend(('-r', root))
|
||||
|
||||
ret = {}
|
||||
call = __salt__['cmd.run_all'](cmd,
|
||||
output_loglevel='trace',
|
||||
@ -345,6 +361,9 @@ def install(name=None,
|
||||
log.warning('\'version\' parameter will be ignored for multiple '
|
||||
'package targets')
|
||||
|
||||
if 'root' in kwargs:
|
||||
pkg_params['-r'] = kwargs['root']
|
||||
|
||||
if pkg_type == 'file':
|
||||
cmd = ['pacman', '-U', '--noprogressbar', '--noconfirm'] + pkg_params
|
||||
elif pkg_type == 'repository':
|
||||
@ -404,7 +423,7 @@ def install(name=None,
|
||||
return ret
|
||||
|
||||
|
||||
def upgrade(refresh=False):
|
||||
def upgrade(refresh=False, root=None):
|
||||
'''
|
||||
Run a full system upgrade, a pacman -Syu
|
||||
|
||||
@ -428,8 +447,13 @@ def upgrade(refresh=False):
|
||||
|
||||
old = list_pkgs()
|
||||
cmd = ['pacman', '-Su', '--noprogressbar', '--noconfirm']
|
||||
|
||||
if salt.utils.is_true(refresh):
|
||||
cmd.append('-y')
|
||||
|
||||
if root is not None:
|
||||
cmd.extend(('-r', root))
|
||||
|
||||
call = __salt__['cmd.run_all'](cmd,
|
||||
output_loglevel='trace',
|
||||
python_shell=False,
|
||||
@ -461,11 +485,15 @@ def _uninstall(action='remove', name=None, pkgs=None, **kwargs):
|
||||
targets = [x for x in pkg_params if x in old]
|
||||
if not targets:
|
||||
return {}
|
||||
|
||||
cmd = ['pacman',
|
||||
'-Rsc' if action == 'purge' else '-R',
|
||||
'--noprogressbar',
|
||||
'--noconfirm'] + targets
|
||||
|
||||
if 'root' in kwargs:
|
||||
cmd.extend(('-r', kwargs['root']))
|
||||
|
||||
out = __salt__['cmd.run_all'](
|
||||
cmd,
|
||||
output_loglevel='trace',
|
||||
@ -568,7 +596,13 @@ def file_list(*packages):
|
||||
errors = []
|
||||
ret = []
|
||||
cmd = ['pacman', '-Ql']
|
||||
|
||||
if len(packages) > 0 and os.path.exists(packages[0]):
|
||||
packages = list(packages)
|
||||
cmd.extend(('-r', packages.pop(0)))
|
||||
|
||||
cmd.extend(packages)
|
||||
|
||||
out = __salt__['cmd.run'](cmd, output_loglevel='trace', python_shell=False)
|
||||
for line in salt.utils.itertools.split(out, '\n'):
|
||||
if line.startswith('error'):
|
||||
@ -596,7 +630,13 @@ def file_dict(*packages):
|
||||
errors = []
|
||||
ret = {}
|
||||
cmd = ['pacman', '-Ql']
|
||||
|
||||
if len(packages) > 0 and os.path.exists(packages[0]):
|
||||
packages = list(packages)
|
||||
cmd.extend(('-r', packages.pop(0)))
|
||||
|
||||
cmd.extend(packages)
|
||||
|
||||
out = __salt__['cmd.run'](cmd, output_loglevel='trace', python_shell=False)
|
||||
for line in salt.utils.itertools.split(out, '\n'):
|
||||
if line.startswith('error'):
|
||||
@ -630,6 +670,7 @@ def owner(*paths):
|
||||
return ''
|
||||
ret = {}
|
||||
cmd_prefix = ['pacman', '-Qqo']
|
||||
|
||||
for path in paths:
|
||||
ret[path] = __salt__['cmd.run_stdout'](cmd_prefix + [path],
|
||||
python_shell=False)
|
||||
|
Loading…
Reference in New Issue
Block a user