Method: Chef::Provider::Package::Portage#parse_emerge

Defined in:
lib/chef/provider/package/portage.rb

#parse_emerge(package, txt) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/chef/provider/package/portage.rb', line 56

def parse_emerge(package, txt)
  availables = {}
  package_without_category = package.split("/").last
  found_package_name = nil

  txt.each_line do |line|
    if line =~ /\*\s+#{PACKAGE_NAME_PATTERN}/
      found_package_name = $&.strip
      if found_package_name == package || found_package_name.split("/").last == package_without_category
        availables[found_package_name] = nil
      end
    end

    if line =~ /Latest version available: (.*)/ && availables.has_key?(found_package_name)
      availables[found_package_name] = $1.strip
    end
  end

  if availables.size > 1
    # shouldn't happen if a category is specified so just use `package`
    raise Chef::Exceptions::Package, "Multiple emerge results found for #{package}: #{availables.keys.join(" ")}. Specify a category."
  end

  availables.values.first
end