*) Make install() definition similar with order package modules

*) Handle refresh param in install()
*) Fix upgrade(): freebsd-update does'nt care about packages, it's about OS itself. But there is not easy way to upgrade package with old package system.
*) Fix docstring example in search()
*) Bring the changes above to the man page
This commit is contained in:
Denis Generalov 2012-09-20 02:05:14 +04:00
parent 2dc5ebb80e
commit 74398d19fd
2 changed files with 19 additions and 12 deletions

View File

@ -7705,7 +7705,7 @@ salt \(aq*\(aq pkg.available_version <package name>
.UNINDENT
.INDENT 0.0
.TP
.B salt.modules.freebsdpkg.install(name, *args, **kwargs)
.B salt.modules.freebsdpkg.install(name, refresh=False, repo='', **kwargs)
Install the passed package
.sp
Return a dict containing the new package names and versions:
@ -7807,20 +7807,20 @@ salt \(aq*\(aq pkg.remove <package name>
.INDENT 0.0
.TP
.B salt.modules.freebsdpkg.search(pkg_name)
Use \fIpkg search\fP if pkg is being used.
Use \fIpkg search\fP if pkgng is being used.
.sp
CLI Example:
.sp
.nf
.ft C
salt \(aq*\(aq pkg.pkgng_search \(aqmysql\-server\(aq
salt \(aq*\(aq pkg.search \(aqmysql\-server\(aq
.ft P
.fi
.UNINDENT
.INDENT 0.0
.TP
.B salt.modules.freebsdpkg.upgrade()
Run a full system upgrade, a \fBfreebsd\-update fetch install\fP
Run \fBpkg upgrade\fP, if pkgng used. Otherwise do nothing
.sp
Return a dict containing the new package names and versions:
.sp

View File

@ -19,7 +19,7 @@ def search(pkg_name):
CLI Example::
salt '*' pkg.pkgng_search 'mysql-server'
salt '*' pkg.search 'mysql-server'
'''
if _check_pkgng():
res = __salt__['cmd.run']('pkg search {0}'.format(pkg_name))
@ -114,7 +114,7 @@ def list_pkgs():
return ret
def install(name, *args, **kwargs):
def install(name, refresh=False, repo='', **kwargs):
'''
Install the passed package
@ -130,12 +130,14 @@ def install(name, *args, **kwargs):
env = ()
if _check_pkgng():
pkg_command = 'pkg install -y'
if 'repo' in kwargs:
env = (('PACKAGESITE', kwargs['repo']),)
if not refresh:
pkg_command += ' -L'
if repo:
env = (('PACKAGESITE', repo),)
else:
pkg_command = 'pkg_add -r'
if 'repo' in kwargs:
env = (('PACKAGEROOT', kwargs['repo']),)
if repo:
env = (('PACKAGEROOT', repo),)
old = list_pkgs()
__salt__['cmd.retcode']('%s {0}'.format(name) % pkg_command, env=env)
new = list_pkgs()
@ -159,7 +161,7 @@ def install(name, *args, **kwargs):
def upgrade():
'''
Run a full system upgrade, a ``freebsd-update fetch install``
Run pkg upgrade, if pkgng used. Otherwise do nothing
Return a dict containing the new package names and versions::
@ -170,8 +172,13 @@ def upgrade():
salt '*' pkg.upgrade
'''
if not _check_pkgng():
# There is not easy way to upgrade packages with old package system
return {}
old = list_pkgs()
__salt__['cmd.retcode']('freebsd-update fetch install')
__salt__['cmd.retcode']('pkg upgrade -y')
new = list_pkgs()
pkgs = {}
for npkg in new: