example_package_database.rb
This example demonstrates how to use Mask. It displays all the mask keys for a particular PackageID.
00001 #!/usr/bin/env ruby 00002 # vim: set sw=4 sts=4 et tw=100 : 00003 00004 =begin description 00005 This example demonstrates how to use Mask. It displays all the 00006 mask keys for a particular PackageID. 00007 =end 00008 00009 require 'Paludis' 00010 require 'example_command_line' 00011 00012 include Paludis 00013 00014 exit_status = 0 00015 00016 # We start with an Environment, respecting the user's '--environment' choice. 00017 env = EnvironmentMaker.instance.make_from_spec(ExampleCommandLine.instance.environment) 00018 00019 # Mostly PackageDatabase is used by Environment. But other methods are useful: 00020 if env.package_database.has_repository_named?('gentoo') 00021 repo = env.package_database.fetch_repository('gentoo') 00022 puts "Repository 'gentoo' exists, and has format '" + 00023 (repo.format_key ? repo.format_key.value : '') + "'" 00024 end 00025 00026 puts "Our favourite repository is '#{env.package_database.favourite_repository}'" 00027 00028 begin 00029 name = env.package_database.fetch_unique_qualified_package_name('git') 00030 puts "The only package named 'git' is '#{name}'" 00031 rescue NoSuchPackageError 00032 puts "There is no package named 'git'" 00033 rescue AmbiguousPackageNameError 00034 puts "There are several packages named 'git':" 00035 $!.options.each do |o| 00036 puts " #{o}" 00037 end 00038 end 00039 00040 exit exit_status 00041
