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