Signed-off-by: Ross West <westr@connection.ca>

Code cleanup/spacing fixed
This commit is contained in:
Ross West 2010-05-05 13:23:31 -04:00 коммит произвёл test branch
Родитель a4eb5d5764
Коммит 85f2565ad3
1 изменённых файлов: 216 добавлений и 233 удалений

Просмотреть файл

@ -1,5 +1,3 @@
# Puppet::Type.type(:package).provide :portupgrade, :parent => :freebsd, :source => :freebsd do
Puppet::Type.type(:package).provide :portupgrade, :parent => Puppet::Provider::Package do
include Puppet::Util::Execution
@ -13,6 +11,7 @@ Puppet::Type.type(:package).provide :portupgrade, :parent => Puppet::Provider::P
:portuninstall => "/usr/local/sbin/pkg_deinstall",
:portinfo => "/usr/sbin/pkg_info"
## Activate this only once approved by someone important.
# defaultfor :operatingsystem => :freebsd
# Remove unwanted environment variables.
@ -36,9 +35,9 @@ Puppet::Type.type(:package).provide :portupgrade, :parent => Puppet::Provider::P
packages = []
#exec command
cmd = ["-aoQ"]
cmdline = ["-aoQ"]
begin
output = portinfo(*cmd)
output = portinfo(*cmdline)
rescue Puppet::ExecutionFailure
raise Puppet::Error.new(output)
return nil
@ -73,36 +72,20 @@ Puppet::Type.type(:package).provide :portupgrade, :parent => Puppet::Provider::P
end
######## packagename sub command
def packagename
Puppet.debug "portupgrade.packagename() - checking package name: %s" % self.name
cmd = ["-qO", @resource[:name]]
begin
output = portinfo(*cmd)
rescue Puppet::ExecutionFailure
raise Puppet::Error.new(output)
end
if output =~ /^(\S+)\s+/
self.packagename = $1
return $1
end
return nil
end
######## Installation sub command
def install
Puppet.debug "portupgrade.install() - Installation call on %s" % @resource[:name]
# -M: yes, we're a batch, so don't ask any questions
cmd = %w{-M BATCH=yes} << @resource[:name]
cmdline = ["-M BATCH=yes", @resource[:name]]
output = portinstall(*cmd)
output = portinstall(*cmdline)
if output =~ /\*\* No such /
raise Puppet::ExecutionFailure, "Could not find package %s" % @resource[:name]
end
# No return code required, so do nil to be clean
return nil
end
######## Latest subcommand (returns the latest version available, or current version if installed is latest)
@ -110,12 +93,12 @@ Puppet::Type.type(:package).provide :portupgrade, :parent => Puppet::Provider::P
def latest
Puppet.debug "portupgrade.latest() - Latest check called on %s" % @resource[:name]
# search for latest version available, or return current version.
# cmd = "portversion -v <portorigin>", returns "<portname> <code> <stuff>"
# cmdline = "portversion -v <portorigin>", returns "<portname> <code> <stuff>"
# or "** No matching package found: <portname>"
cmd = ["-v", @resource[:name]]
cmdline = ["-v", @resource[:name]]
begin
output = portversion(*cmd)
output = portversion(*cmdline)
rescue Puppet::ExecutionFailure
raise Puppet::Error.new(output)
end
@ -178,9 +161,9 @@ Puppet::Type.type(:package).provide :portupgrade, :parent => Puppet::Provider::P
def query
Puppet.debug "portupgrade.query() - Called on %s" % @resource[:name]
cmd = ["-qO", @resource[:name]]
cmdline = ["-qO", @resource[:name]]
begin
output = portinfo(*cmd)
output = portinfo(*cmdline)
rescue Puppet::ExecutionFailure
raise Puppet::Error.new(output)
end
@ -209,9 +192,9 @@ Puppet::Type.type(:package).provide :portupgrade, :parent => Puppet::Provider::P
def uninstall
Puppet.debug "portupgrade.uninstall() - called on %s" % @resource[:name]
# Get full package name from port origin to uninstall with
cmd = ["-qO", @resource[:name]]
cmdline = ["-qO", @resource[:name]]
begin
output = portinfo(*cmd)
output = portinfo(*cmdline)
rescue Puppet::ExecutionFailure
raise Puppet::Error.new(output)
end
@ -228,18 +211,18 @@ Puppet::Type.type(:package).provide :portupgrade, :parent => Puppet::Provider::P
def update
Puppet.debug "portupgrade.update() - called on (%s)" % @resource[:name]
cmd = ["-qO", @resource[:name]]
cmdline = ["-qO", @resource[:name]]
begin
output = portinfo(*cmd)
output = portinfo(*cmdline)
rescue Puppet::ExecutionFailure
raise Puppet::Error.new(output)
end
if output =~ /^(\S+)/
# output matches, so upgrade the software
cmd = %w{-M BATCH=yes} << $1
cmdline = ["-M BATCH=yes", $1]
begin
output = portupgrade(*cmd)
output = portupgrade(*cmdline)
rescue Puppet::ExecutionFailure
raise Puppet::Error.new(output)
end