Class: Puppet::Provider::Package::Windows::Package

Inherits:
Object
  • Object
show all
Extended by:
Enumerable, Util::Errors, Util::Windows::Registry
Includes:
Util::Windows::Registry
Defined in:
lib/puppet/provider/package/windows/package.rb

Direct Known Subclasses

ExePackage, MsiPackage

Constant Summary

Constants included from Util::Windows::Registry

Util::Windows::Registry::KEY32, Util::Windows::Registry::KEY64, Util::Windows::Registry::KEY_ALL_ACCESS, Util::Windows::Registry::KEY_READ, Util::Windows::Registry::KEY_WRITE

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util::Errors

adderrorcontext, devfail, error_context, exceptwrap, fail

Methods included from Util::Windows::Registry

open, root, values

Constructor Details

#initialize(name, version) ⇒ Package

Returns a new instance of Package.



72
73
74
75
# File 'lib/puppet/provider/package/windows/package.rb', line 72

def initialize(name, version)
  @name = name
  @version = version
end

Instance Attribute Details

#nameObject (readonly)



12
13
14
# File 'lib/puppet/provider/package/windows/package.rb', line 12

def name
  @name
end

#versionObject (readonly)



12
13
14
# File 'lib/puppet/provider/package/windows/package.rb', line 12

def version
  @version
end

Class Method Details

.each(&block) ⇒ Object

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



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/puppet/provider/package/windows/package.rb', line 16

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) ⇒ Object

Get the class that knows how to install this resource



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/puppet/provider/package/windows/package.rb', line 52

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: '#{resource[:source]}'") unless Puppet::FileSystem.exist?(resource[:source])
    ExePackage
  else
    fail("Don't know how to install '#{resource[:source]}'")
  end
end

.quote(value) ⇒ Object



68
69
70
# File 'lib/puppet/provider/package/windows/package.rb', line 68

def self.quote(value)
  value.include?(' ') ? %Q["#{value.gsub(/"/, '\"')}"] : 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.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/puppet/provider/package/windows/package.rb', line 32

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