33: def self.instances
34: Puppet.debug "portupgrade.rb Building packages list from installed ports"
35:
36:
37: regex = %r{^(\S+)-([^-\s]+):(\S+)$}
38:
39: fields = [:portname, :ensure, :portorigin]
40:
41: hash = Hash.new
42: packages = []
43:
44:
45: cmdline = ["-aoQ"]
46: begin
47: output = portinfo(*cmdline)
48: rescue Puppet::ExecutionFailure
49: raise Puppet::Error.new(output)
50: return nil
51: end
52:
53:
54: output.split("\n").each { |data|
55:
56: hash.clear
57: if match = regex.match(data)
58:
59: fields.zip(match.captures) { |field, value|
60: hash[field] = value
61: }
62:
63:
64:
65: hash[:name] = hash[:portorigin]
66: hash[:provider] = self.name
67:
68:
69: packages << new(hash)
70:
71: else
72:
73: Puppet.debug "portupgrade.Instances() - unable to match output: #{data}"
74: end
75: }
76:
77:
78: return packages
79:
80: end