Class: Puppet::Provider::Package::Windows::Package
- Extended by:
- Enumerable, Util::Errors, Util::Windows::Registry
- Includes:
- Util::Windows::Registry
- Defined in:
- lib/puppet/provider/package/windows/package.rb
Direct Known Subclasses
Constant Summary collapse
- REG_DISPLAY_VALUE_NAMES =
%w[DisplayName QuietDisplayName]
Constants included from Util::Windows::Registry
Util::Windows::Registry::ERROR_NO_MORE_ITEMS, Util::Windows::Registry::KEY32, Util::Windows::Registry::KEY64, Util::Windows::Registry::KEY_ALL_ACCESS, Util::Windows::Registry::KEY_READ, Util::Windows::Registry::KEY_WRITE, Util::Windows::Registry::WCHAR_SIZE
Instance Attribute Summary collapse
- #name ⇒ Object readonly
- #version ⇒ Object readonly
Class Method Summary collapse
-
.each(&block) ⇒ Object
Enumerate each package.
- .get_display_name(values) ⇒ Object
-
.installer_class(resource) ⇒ Object
Get the class that knows how to install this resource.
- .munge(value) ⇒ Object
- .quote(value) ⇒ Object
- .reg_value_names_to_load ⇒ Object
- .replace_forward_slashes(value) ⇒ Object
-
.with_key(&block) ⇒ Object
Yield each registry key and its values associated with an installed package.
Instance Method Summary collapse
-
#initialize(name, version) ⇒ Package
constructor
A new instance of Package.
Methods included from Util::Errors
adderrorcontext, devfail, error_context, error_location, error_location_with_space, error_location_with_unknowns, exceptwrap, fail
Methods included from Util::Windows::Registry
delete_key, delete_value, each_key, each_value, keys, open, root, values, values_by_name
Constructor Details
#initialize(name, version) ⇒ Package
Returns a new instance of Package.
105 106 107 108 |
# File 'lib/puppet/provider/package/windows/package.rb', line 105 def initialize(name, version) @name = name @version = version end |
Instance Attribute Details
#name ⇒ Object (readonly)
14 15 16 |
# File 'lib/puppet/provider/package/windows/package.rb', line 14 def name @name end |
#version ⇒ Object (readonly)
14 15 16 |
# File 'lib/puppet/provider/package/windows/package.rb', line 14 def version @version end |
Class Method Details
.each(&block) ⇒ Object
Enumerate each package. The appropriate package subclass will be yielded.
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/puppet/provider/package/windows/package.rb', line 26 def self.each(&block) with_key do |key, values| name = key.name.match(/^.+\\([^\\]+)$/).captures[0] [MsiPackage, ExePackage].find do |klass| pkg = klass.from_registry(name, values) if pkg yield pkg end end end end |
.get_display_name(values) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/puppet/provider/package/windows/package.rb', line 97 def self.get_display_name(values) return if values.nil? return values['DisplayName'] if values['DisplayName'] && values['DisplayName'].length > 0 return values['QuietDisplayName'] if values['QuietDisplayName'] && values['QuietDisplayName'].length > 0 '' end |
.installer_class(resource) ⇒ Object
Get the class that knows how to install this resource
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/puppet/provider/package/windows/package.rb', line 63 def self.installer_class(resource) fail(_("The source parameter is required when using the Windows provider.")) unless resource[:source] case resource[:source] when /\.msi"?\Z/i # REMIND: can we install from URL? # REMIND: what about msp, etc MsiPackage when /\.exe"?\Z/i fail(_("The source does not exist: '%{source}'") % { source: resource[:source] }) unless Puppet::FileSystem.exist?(resource[:source]) || resource[:source].start_with?('http://', 'https://') ExePackage else fail(_("Don't know how to install '%{source}'") % { source: resource[:source] }) end end |
.munge(value) ⇒ Object
81 82 83 |
# File 'lib/puppet/provider/package/windows/package.rb', line 81 def self.munge(value) quote(replace_forward_slashes(value)) end |
.quote(value) ⇒ Object
93 94 95 |
# File 'lib/puppet/provider/package/windows/package.rb', line 93 def self.quote(value) value.include?(' ') ? %Q("#{value.gsub(/"/, '\"')}") : value end |
.reg_value_names_to_load ⇒ Object
18 19 20 21 22 |
# File 'lib/puppet/provider/package/windows/package.rb', line 18 def self.reg_value_names_to_load REG_DISPLAY_VALUE_NAMES | MsiPackage::REG_VALUE_NAMES | ExePackage::REG_VALUE_NAMES end |
.replace_forward_slashes(value) ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/puppet/provider/package/windows/package.rb', line 85 def self.replace_forward_slashes(value) if value.include?('/') value = value.tr('/', "\\") Puppet.debug('Package source parameter contained /s - replaced with \\s') end value end |
.with_key(&block) ⇒ Object
Yield each registry key and its values associated with an installed package. This searches both per-machine and current user contexts, as well as packages associated with 64 and 32-bit installers.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/puppet/provider/package/windows/package.rb', line 43 def self.with_key(&block) %w[HKEY_LOCAL_MACHINE HKEY_CURRENT_USER].each do |hive| [KEY64, KEY32].each do |mode| mode |= KEY_READ begin self.open(hive, 'Software\Microsoft\Windows\CurrentVersion\Uninstall', mode) do |uninstall| each_key(uninstall) do |name, _wtime| self.open(hive, "#{uninstall.keyname}\\#{name}", mode) do |key| yield key, values_by_name(key, reg_value_names_to_load) end end end rescue Puppet::Util::Windows::Error => e raise e unless e.code == Puppet::Util::Windows::Error::ERROR_FILE_NOT_FOUND end end end end |