Update entropy package provider to use locale without shelling out

This commit is contained in:
2016-10-13 18:55:07 +01:00
parent 7ce45a207f
commit a265caa979
2 changed files with 21 additions and 19 deletions

View File

@@ -1,7 +1,7 @@
require 'puppet/provider/package' require 'puppet/provider/package'
require 'fileutils' require 'fileutils'
Puppet::Type.type(:package).provide :entropy, :parent => Puppet::Provider::Package do Puppet::Type.type(:package).provide(:entropy, :parent => Puppet::Provider::Package) do
desc "Provides packaging support for Sabayon's entropy system." desc "Provides packaging support for Sabayon's entropy system."
has_feature :versionable has_feature :versionable
@@ -9,18 +9,28 @@ Puppet::Type.type(:package).provide :entropy, :parent => Puppet::Provider::Packa
has_feature :uninstallable has_feature :uninstallable
has_feature :upgradeable has_feature :upgradeable
commands :equo => "#{File.dirname(__FILE__)}/entropy/equo_locale" commands({
:equo => 'equo',
})
confine :has_entropy => true # Require the locale fact exist
confine :false => Facter.value(:locale).nil?
confine :osfamily => :Gentoo
defaultfor :has_entropy => :true, :osfamily => :Gentoo defaultfor :operatingsystem => :Sabayon
def self.equo_with_locale(*args)
Puppet::Util.withenv :LANG => Facter.value(:locale) do
equo(args)
end
end
def self.instances def self.instances
result_format = /^(\S+)\/(\S+)-([\.\d]+(?:_?(?:a(?:lpha)?|b(?:eta)?|pre|rc|p)\d*)?(?:-r\d+)?)(?:#(\S+))?$/ 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 begin
search_output = equo "query", "list", "installed", "--quiet", "--verbose" search_output = equo_with_locale("query", "list", "installed", "--quiet", "--verbose").chomp
packages = [] packages = []
search_output.each_line do |search_result| search_output.each_line do |search_result|
@@ -32,6 +42,7 @@ Puppet::Type.type(:package).provide :entropy, :parent => Puppet::Provider::Packa
package[field] = value unless !value or value.empty? package[field] = value unless !value or value.empty?
end end
package[:provider] = :entropy package[:provider] = :entropy
packages << new(package) packages << new(package)
end end
end end
@@ -49,7 +60,7 @@ Puppet::Type.type(:package).provide :entropy, :parent => Puppet::Provider::Packa
# We must install a specific version # We must install a specific version
name = "=#{name}-#{should}" name = "=#{name}-#{should}"
end end
equo "install", name equo_with_locale "install", name
end end
# The common package name format. # The common package name format.
@@ -62,7 +73,7 @@ Puppet::Type.type(:package).provide :entropy, :parent => Puppet::Provider::Packa
end end
def uninstall def uninstall
equo "remove", package_name equo_with_locale "remove", package_name
end end
def update def update
@@ -75,8 +86,7 @@ Puppet::Type.type(:package).provide :entropy, :parent => Puppet::Provider::Packa
begin begin
# Look for an installed package from a known repository # Look for an installed package from a known repository
search_output = equo "match", "--quiet", "--verbose", package_name search_output = equo_with_locale("match", "--quiet", "--verbose", package_name).chomp
search_output.chomp
search_match = search_output.match(result_format) search_match = search_output.match(result_format)
if search_match if search_match
@@ -85,8 +95,7 @@ Puppet::Type.type(:package).provide :entropy, :parent => Puppet::Provider::Packa
package[field] = value unless !value or value.empty? package[field] = value unless !value or value.empty?
end end
installed_output = equo 'match', '--quiet', '--verbose', '--installed', package_name installed_output = equo_with_locale('match', '--quiet', '--verbose', '--installed', package_name).chomp
installed_output.chomp
installed_match = installed_output.match(result_format) installed_match = installed_output.match(result_format)
if installed_match if installed_match
@@ -101,8 +110,7 @@ Puppet::Type.type(:package).provide :entropy, :parent => Puppet::Provider::Packa
else else
# List all installed packages and try and find if it's installed from outside a repository # 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 # If so, assume the installed version is the latest available
all_installed = equo "query", "list", "installed", "--quiet", "--verbose" all_installed = equo_with_locale("query", "list", "installed", "--quiet", "--verbose").chomp
all_installed.chomp
all_installed.split("\n").each do |installed_package| all_installed.split("\n").each do |installed_package|

View File

@@ -1,6 +0,0 @@
#!/bin/bash
source /etc/profile
/usr/bin/equo $@
exit 0