15: def self.instances
16: result_format = /(\S+) (\S+) \[(?:([0-9.a-zA-Z]+(?:_(?:alpha|beta|pre|rc|p)[0-9]*)*(?:-r[0-9]*)?)(?:\([^\)]+\))?(?:\[([^\]]+)\])?[ ]*)*\] \[(?:(?:\{M\})?(?:\([~*]+\))?([0-9.a-zA-Z]+(?:_(?:alpha|beta|pre|rc|p)[0-9]*)*(?:-r[0-9]*)?)(?:\(([^\)]+)\))?(?:![mf])*(?:\[([^\]]+)\])?)?\] ([\S]*) (.*)/
17: result_fields = [:category, :name, :ensure, :ensure_overlay, :version_available, :slot, :overlay, :vendor, :description]
18:
19: version_format = "<version>{!last} {}"
20: search_format = "<category> <name> [<installedversions:SPLITVERSIONS>] [<bestversion:SPLITVERSIONS>] <homepage> <description>"
21:
22: begin
23: if !FileUtils.uptodate?("/var/cache/eix", %w(/usr/bin/eix /usr/portage/metadata/timestamp))
24: update_eix
25: end
26: search_output = nil
27: withenv :SPLITVERSIONS => version_format do
28: search_output = eix "--nocolor", "--pure-packages", "--installed", "--format", search_format
29: end
30:
31: packages = []
32: search_output.each do |search_result|
33: match = result_format.match( search_result )
34:
35: if match
36: package = {}
37: result_fields.zip(match.captures) { |field, value|
38: package[field] = value unless !value or value.empty?
39: }
40: package[:provider] = :portage
41: package[:ensure] = package[:ensure].split.last
42:
43: packages << new(package)
44: end
45: end
46:
47: return packages
48: rescue Puppet::ExecutionFailure => detail
49: raise Puppet::Error.new(detail)
50: end
51: end