example_query.rb
This example demonstrates how use the standard Query classes.
00001 #!/usr/bin/env ruby 00002 # vim: set sw=4 sts=4 et tw=100 : 00003 00004 =begin description 00005 This example demonstrates how use the standard Query classes. 00006 =end 00007 00008 require 'Paludis' 00009 require 'example_command_line' 00010 00011 include Paludis 00012 00013 # Run a query, and show its results. 00014 def show_query(env, query) 00015 # Queries support a crude form of stringification. 00016 puts "#{query}:" 00017 00018 # Usually the only thing clients will do with a Query object is pass it to 00019 # PackageDatabase#query. 00020 ids = env.package_database.query(query, QueryOrder::OrderByVersion) 00021 00022 # Show the results 00023 ids.each do | id | 00024 puts " #{id}" 00025 end 00026 puts 00027 end 00028 00029 # We start with an Environment, respecting the user's '--environment' choice. 00030 env = EnvironmentMaker.instance.make_from_spec(ExampleCommandLine.instance.environment) 00031 00032 # Make some queries, and display what they give. 00033 show_query(env, Query::Matches.new(Paludis::parse_user_package_dep_spec("sys-apps/paludis", []))) 00034 00035 # Queries can be combined. The resulting query is optimised internally, 00036 # potentially giving better performance than doing things by hand. 00037 show_query(env, 00038 Query::Matches.new(Paludis::parse_user_package_dep_spec("sys-apps/paludis", [])) & 00039 Query::SupportsInstalledAction.new) 00040 00041 # Usually Query::NotMasked should be combined with Query::SupportsInstallAction, 00042 # since installed packages aren't masked. 00043 show_query(env, 00044 Query::Matches.new(Paludis::parse_user_package_dep_spec("sys-apps/paludis", [])) & 00045 Query::SupportsInstallAction.new & 00046 Query::NotMasked.new) 00047
