Fix entropy providers use of equo with locale

Previous attempt didn't work properly. This version uses the proper
`provider.has_command` api to specify the env vars which should be used.

Also catches the exit 1 thrown when `equo match --installed` doesn't
find anything, now that the wrapper script is no longer hiding the exit
code behind an explicit `exit 0`.
This commit is contained in:
2016-10-13 22:08:04 +01:00
parent 80644b6813
commit 53bbad2eb1

View File

@@ -9,9 +9,14 @@ Puppet::Type.type(:package).provide(:entropy, :parent => Puppet::Provider::Packa
has_feature :uninstallable
has_feature :upgradeable
commands({
:equo => 'equo',
})
has_command(:equo, "equo") do
locale = Facter.value(:locale)
environment({
:LANG => locale,
:LC_ALL => locale,
:LANGUAHE => locale,
})
end
# Require the locale fact exist
confine :false => Facter.value(:locale).nil?
@@ -19,18 +24,12 @@ Puppet::Type.type(:package).provide(:entropy, :parent => Puppet::Provider::Packa
defaultfor :operatingsystem => :Sabayon
def self.equo_with_locale(*args)
Puppet::Util.withenv :LANG => Facter.value(:locale) do
equo(args)
end
end
def self.instances
result_format = /^(\S+)\/(\S+)-([\.\d]+(?:_?(?:a(?:lpha)?|b(?:eta)?|pre|rc|p)\d*)?(?:-r\d+)?)(?:#(\S+))?$/
result_fields = [:category, :name, :ensure]
result_fields = [:category, :name, :ensure]
begin
search_output = equo_with_locale("query", "list", "installed", "--quiet", "--verbose").chomp
search_output = equo("query", "list", "installed", "--quiet", "--verbose").chomp
packages = []
search_output.each_line do |search_result|
@@ -60,7 +59,7 @@ Puppet::Type.type(:package).provide(:entropy, :parent => Puppet::Provider::Packa
# We must install a specific version
name = "=#{name}-#{should}"
end
equo_with_locale "install", name
equo "install", name
end
# The common package name format.
@@ -73,7 +72,7 @@ Puppet::Type.type(:package).provide(:entropy, :parent => Puppet::Provider::Packa
end
def uninstall
equo_with_locale "remove", package_name
equo "remove", package_name
end
def update
@@ -81,12 +80,12 @@ Puppet::Type.type(:package).provide(:entropy, :parent => Puppet::Provider::Packa
end
def query
result_format = /^(\S+)\/(\S+)-([\.\d]+(?:_(?:alpha|beta|pre|rc|p)\d+)?(?:-r\d+)?)(?:#(\S+))?$/
result_format = /^(\S+)\/(\S+)-([\.\d]+(?:_(?:alpha|beta|pre|rc|p)\d+)?(?:-r\d+)?)(?::[^#]+)?(?:#(\S+))?$/
result_fields = [:category, :name, :version_available]
begin
# Look for an installed package from a known repository
search_output = equo_with_locale("match", "--quiet", "--verbose", package_name).chomp
search_output = equo("match", "--quiet", "--verbose", package_name).chomp
search_match = search_output.match(result_format)
if search_match
@@ -95,13 +94,18 @@ Puppet::Type.type(:package).provide(:entropy, :parent => Puppet::Provider::Packa
package[field] = value unless !value or value.empty?
end
installed_output = equo_with_locale('match', '--quiet', '--verbose', '--installed', package_name).chomp
installed_match = installed_output.match(result_format)
if installed_match
installed_match_fields = Hash[result_fields.zip(installed_match.captures)]
package[:ensure] = installed_match_fields[:version_available]
else
begin
installed_output = equo('match', '--quiet', '--verbose', '--installed', package_name).chomp
installed_match = installed_output.match(result_format)
if installed_match
installed_match_fields = Hash[result_fields.zip(installed_match.captures)]
package[:ensure] = installed_match_fields[:version_available]
else
package[:ensure] = :absent
end
rescue Puppet::ExecutionFailure
package[:ensure] = :absent
end
@@ -110,7 +114,7 @@ Puppet::Type.type(:package).provide(:entropy, :parent => Puppet::Provider::Packa
else
# List all installed packages and try and find if it's installed from outside a repository
# If so, assume the installed version is the latest available
all_installed = equo_with_locale("query", "list", "installed", "--quiet", "--verbose").chomp
all_installed = equo("query", "list", "installed", "--quiet", "--verbose").chomp
all_installed.split("\n").each do |installed_package|