def add_package package
appliance_basesystem = appliance.basesystem
result = appliance.search_software(package)
if result.empty?
puts "'#{package}' has not been found in the repositories currently "\
"added to your appliance."
keep_trying = @shell.yes?('Would you like to search for this package '\
'inside other repositories? (y/n)')
if keep_trying
matches = appliance.search_software(package, :all_repos => true)\
.find_all { |s| s.name == package }
repositories = matches.map do |r|
StudioApi::Repository.find r.repository_id
end.find_all{|r| r.base_system == appliance_basesystem}
if repositories.empty?
puts "Cannot find #{package}, please look at this page: "
puts URI.encode "http://software.opensuse.org/search?p=1&"\
"baseproject=ALL&q=#{package}"
else
puts "Package #{package} can be installed from one of the "\
"following repositories:"
repositories.each_with_index do |repo, index|
puts "#{index+1} - #{repo.name} (#{repo.base_url})"
end
puts "#{repositories.size+1} - None of them."
begin
choice = @shell.ask("Which repo do you want to use? "\
"[1-#{repositories.size+1}]")
end while (choice.to_i > (repositories.size+1) || choice.to_i < 1)
if (choice.to_i == (repositories.size+1))
abort("Package not added.")
else
repo_id = repositories[choice.to_i-1].id
end
appliance.add_repository repo_id
end
else
exit 0
end
end
Utils::execute_printing_progress "Adding #{package} package" do
appliance.add_package(package)
end
end