64: def info2hash(device = nil)
65: names = {
66: "PKGINST" => :name,
67: "NAME" => nil,
68: "CATEGORY" => :category,
69: "ARCH" => :platform,
70: "VERSION" => :ensure,
71: "BASEDIR" => :root,
72: "HOTLINE" => nil,
73: "EMAIL" => nil,
74: "VSTOCK" => nil,
75: "VENDOR" => :vendor,
76: "DESC" => :description,
77: "PSTAMP" => nil,
78: "INSTDATE" => nil,
79: "STATUS" => nil,
80: "FILES" => nil
81: }
82:
83: hash = {}
84: cmd = "#{command(:pkginfo)} -l"
85: cmd += " -d #{device}" if device
86: cmd += " #{@resource[:name]}"
87:
88: begin
89:
90: execpipe(cmd) { |process|
91:
92:
93: process.readlines.each { |line|
94: case line
95: when /^$/
96: when /\s*([A-Z]+):\s+(.+)/
97: name = $1
98: value = $2
99: if names.include?(name)
100: hash[names[name]] = value unless names[name].nil?
101: end
102: when /\s+\d+.+/
103:
104: end
105: }
106: }
107: return hash
108: rescue Puppet::ExecutionFailure => detail
109: return {:ensure => :absent} if detail.message =~ /information for "#{Regexp.escape(@resource[:name])}" was not found/
110: puts detail.backtrace if Puppet[:trace]
111: raise Puppet::Error, "Unable to get information about package #{@resource[:name]} because of: #{detail}"
112: end
113: end