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 copy
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
|
import os.path
|
||||||
|
|
||||||
# Import salt libs
|
# Import salt libs
|
||||||
import salt.utils
|
import salt.utils
|
||||||
@ -71,6 +72,10 @@ def latest_version(*names, **kwargs):
|
|||||||
ret[name] = ''
|
ret[name] = ''
|
||||||
cmd = ['pacman', '-Sp', '--needed', '--print-format', '%n %v']
|
cmd = ['pacman', '-Sp', '--needed', '--print-format', '%n %v']
|
||||||
cmd.extend(names)
|
cmd.extend(names)
|
||||||
|
|
||||||
|
if 'root' in kwargs:
|
||||||
|
cmd.extend(('-r', kwargs['root']))
|
||||||
|
|
||||||
out = __salt__['cmd.run_stdout'](cmd,
|
out = __salt__['cmd.run_stdout'](cmd,
|
||||||
output_loglevel='trace',
|
output_loglevel='trace',
|
||||||
python_shell=False)
|
python_shell=False)
|
||||||
@ -115,7 +120,7 @@ def upgrade_available(name):
|
|||||||
return latest_version(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
|
List all available package upgrades on this system
|
||||||
|
|
||||||
@ -128,6 +133,9 @@ def list_upgrades(refresh=False):
|
|||||||
upgrades = {}
|
upgrades = {}
|
||||||
cmd = ['pacman', '-S', '-p', '-u', '--print-format', '%n %v']
|
cmd = ['pacman', '-S', '-p', '-u', '--print-format', '%n %v']
|
||||||
|
|
||||||
|
if root is not None:
|
||||||
|
cmd.extend(('-r', root))
|
||||||
|
|
||||||
if refresh:
|
if refresh:
|
||||||
cmd.append('-y')
|
cmd.append('-y')
|
||||||
|
|
||||||
@ -198,6 +206,10 @@ def list_pkgs(versions_as_list=False, **kwargs):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
cmd = ['pacman', '-Q']
|
cmd = ['pacman', '-Q']
|
||||||
|
|
||||||
|
if 'root' in kwargs:
|
||||||
|
cmd.extend(('-r', kwargs['root']))
|
||||||
|
|
||||||
ret = {}
|
ret = {}
|
||||||
out = __salt__['cmd.run'](cmd, output_loglevel='trace', python_shell=False)
|
out = __salt__['cmd.run'](cmd, output_loglevel='trace', python_shell=False)
|
||||||
for line in salt.utils.itertools.split(out, '\n'):
|
for line in salt.utils.itertools.split(out, '\n'):
|
||||||
@ -218,7 +230,7 @@ def list_pkgs(versions_as_list=False, **kwargs):
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def refresh_db():
|
def refresh_db(root=None):
|
||||||
'''
|
'''
|
||||||
Just run a ``pacman -Sy``, return a dict::
|
Just run a ``pacman -Sy``, return a dict::
|
||||||
|
|
||||||
@ -231,6 +243,10 @@ def refresh_db():
|
|||||||
salt '*' pkg.refresh_db
|
salt '*' pkg.refresh_db
|
||||||
'''
|
'''
|
||||||
cmd = ['pacman', '-Sy']
|
cmd = ['pacman', '-Sy']
|
||||||
|
|
||||||
|
if root is not None:
|
||||||
|
cmd.extend(('-r', root))
|
||||||
|
|
||||||
ret = {}
|
ret = {}
|
||||||
call = __salt__['cmd.run_all'](cmd,
|
call = __salt__['cmd.run_all'](cmd,
|
||||||
output_loglevel='trace',
|
output_loglevel='trace',
|
||||||
@ -345,6 +361,9 @@ def install(name=None,
|
|||||||
log.warning('\'version\' parameter will be ignored for multiple '
|
log.warning('\'version\' parameter will be ignored for multiple '
|
||||||
'package targets')
|
'package targets')
|
||||||
|
|
||||||
|
if 'root' in kwargs:
|
||||||
|
pkg_params['-r'] = kwargs['root']
|
||||||
|
|
||||||
if pkg_type == 'file':
|
if pkg_type == 'file':
|
||||||
cmd = ['pacman', '-U', '--noprogressbar', '--noconfirm'] + pkg_params
|
cmd = ['pacman', '-U', '--noprogressbar', '--noconfirm'] + pkg_params
|
||||||
elif pkg_type == 'repository':
|
elif pkg_type == 'repository':
|
||||||
@ -404,7 +423,7 @@ def install(name=None,
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def upgrade(refresh=False):
|
def upgrade(refresh=False, root=None):
|
||||||
'''
|
'''
|
||||||
Run a full system upgrade, a pacman -Syu
|
Run a full system upgrade, a pacman -Syu
|
||||||
|
|
||||||
@ -428,8 +447,13 @@ def upgrade(refresh=False):
|
|||||||
|
|
||||||
old = list_pkgs()
|
old = list_pkgs()
|
||||||
cmd = ['pacman', '-Su', '--noprogressbar', '--noconfirm']
|
cmd = ['pacman', '-Su', '--noprogressbar', '--noconfirm']
|
||||||
|
|
||||||
if salt.utils.is_true(refresh):
|
if salt.utils.is_true(refresh):
|
||||||
cmd.append('-y')
|
cmd.append('-y')
|
||||||
|
|
||||||
|
if root is not None:
|
||||||
|
cmd.extend(('-r', root))
|
||||||
|
|
||||||
call = __salt__['cmd.run_all'](cmd,
|
call = __salt__['cmd.run_all'](cmd,
|
||||||
output_loglevel='trace',
|
output_loglevel='trace',
|
||||||
python_shell=False,
|
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]
|
targets = [x for x in pkg_params if x in old]
|
||||||
if not targets:
|
if not targets:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
cmd = ['pacman',
|
cmd = ['pacman',
|
||||||
'-Rsc' if action == 'purge' else '-R',
|
'-Rsc' if action == 'purge' else '-R',
|
||||||
'--noprogressbar',
|
'--noprogressbar',
|
||||||
'--noconfirm'] + targets
|
'--noconfirm'] + targets
|
||||||
|
|
||||||
|
if 'root' in kwargs:
|
||||||
|
cmd.extend(('-r', kwargs['root']))
|
||||||
|
|
||||||
out = __salt__['cmd.run_all'](
|
out = __salt__['cmd.run_all'](
|
||||||
cmd,
|
cmd,
|
||||||
output_loglevel='trace',
|
output_loglevel='trace',
|
||||||
@ -568,7 +596,13 @@ def file_list(*packages):
|
|||||||
errors = []
|
errors = []
|
||||||
ret = []
|
ret = []
|
||||||
cmd = ['pacman', '-Ql']
|
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)
|
cmd.extend(packages)
|
||||||
|
|
||||||
out = __salt__['cmd.run'](cmd, output_loglevel='trace', python_shell=False)
|
out = __salt__['cmd.run'](cmd, output_loglevel='trace', python_shell=False)
|
||||||
for line in salt.utils.itertools.split(out, '\n'):
|
for line in salt.utils.itertools.split(out, '\n'):
|
||||||
if line.startswith('error'):
|
if line.startswith('error'):
|
||||||
@ -596,7 +630,13 @@ def file_dict(*packages):
|
|||||||
errors = []
|
errors = []
|
||||||
ret = {}
|
ret = {}
|
||||||
cmd = ['pacman', '-Ql']
|
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)
|
cmd.extend(packages)
|
||||||
|
|
||||||
out = __salt__['cmd.run'](cmd, output_loglevel='trace', python_shell=False)
|
out = __salt__['cmd.run'](cmd, output_loglevel='trace', python_shell=False)
|
||||||
for line in salt.utils.itertools.split(out, '\n'):
|
for line in salt.utils.itertools.split(out, '\n'):
|
||||||
if line.startswith('error'):
|
if line.startswith('error'):
|
||||||
@ -630,6 +670,7 @@ def owner(*paths):
|
|||||||
return ''
|
return ''
|
||||||
ret = {}
|
ret = {}
|
||||||
cmd_prefix = ['pacman', '-Qqo']
|
cmd_prefix = ['pacman', '-Qqo']
|
||||||
|
|
||||||
for path in paths:
|
for path in paths:
|
||||||
ret[path] = __salt__['cmd.run_stdout'](cmd_prefix + [path],
|
ret[path] = __salt__['cmd.run_stdout'](cmd_prefix + [path],
|
||||||
python_shell=False)
|
python_shell=False)
|
||||||
|
Loading…
Reference in New Issue
Block a user