class Puppet::Provider::Package::Windows::Package

Attributes

name[R]
version[R]

Public Class Methods

each() { |pkg| ... } click to toggle source

Enumerate each package. The appropriate package subclass will be yielded.

# File lib/puppet/provider/package/windows/package.rb, line 15
def self.each(&block)
  with_key do |key, values|
    name = key.name.match(/^.+\([^\]+)$/).captures[0]

    [MsiPackage, ExePackage].find do |klass|
      if pkg = klass.from_registry(name, values)
        yield pkg
      end
    end
  end
end
installer_class(resource) click to toggle source

Get the class that knows how to install this resource

# File lib/puppet/provider/package/windows/package.rb, line 51
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/
    # REMIND: can we install from URL?
    # REMIND: what about msp, etc
    MsiPackage
  when /\.exe"?\Z/
    fail("The source does not exist: '#{resource[:source]}'") unless File.exists?(resource[:source])
    ExePackage
  else
    fail("Don't know how to install '#{resource[:source]}'")
  end
end
new(name, version) click to toggle source
# File lib/puppet/provider/package/windows/package.rb, line 71
def initialize(name, version)
  @name = name
  @version = version
end
quote(value) click to toggle source
# File lib/puppet/provider/package/windows/package.rb, line 67
def self.quote(value)
  value.include?(' ') ? %Q["#{value.gsub(/"/, '\"')}"] : value
end
with_key() { |key, values(key)| ... } click to toggle source

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.

# File lib/puppet/provider/package/windows/package.rb, line 31
def self.with_key(&block)
  %w[HKEY_LOCAL_MACHINE HKEY_CURRENT_USER].each do |hive|
    [KEY64, KEY32].each do |mode|
      mode |= KEY_READ
      begin
        open(hive, 'Software\Microsoft\Windows\CurrentVersion\Uninstall', mode) do |uninstall|
          uninstall.each_key do |name, wtime|
            open(hive, "#{uninstall.keyname}\\#{name}", mode) do |key|
              yield key, values(key)
            end
          end
        end
      rescue Puppet::Util::Windows::Error => e
        raise e unless e.code == Windows::Error::ERROR_FILE_NOT_FOUND
      end
    end
  end
end