Paludis Logo Introduction Examples
Bugs, Requests, Support C++ (core)
Overview Ruby (bindings)
FAQ Python (bindings)
Clients  
Configuration  
API  

example_mask.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 = EnvironmentFactory.instance.create(ExampleCommandLine.instance.environment)
00018 
00019 # Fetch package IDs for 'sys-apps/paludis'
00020 ids = env[Selection::AllVersionsSorted.new(
00021     Generator::Matches.new(Paludis::parse_user_package_dep_spec("sys-apps/paludis", env, []), nil, []))]
00022 
00023 # For each ID:
00024 ids.each do | id |
00025     puts id.to_s + ':'
00026     id.masks.each do |mask|
00027         puts "    Key: ".ljust(31) + mask.key
00028         puts "    Description: ".ljust(31) + mask.description
00029 
00030         # Some Mask subclasses contain more information than others
00031         if mask.kind_of? UserMask
00032             puts "    Class: ".ljust(31) + 'UserMask'
00033         elsif mask.kind_of? UnacceptedMask
00034             puts "    Class: ".ljust(31) + 'UnacceptedMask'
00035             puts "    Unaccepted key: ".ljust(31) + mask.unaccepted_key_name
00036         elsif mask.kind_of? RepositoryMask
00037             puts "    Class: ".ljust(31) + 'RepositoryMask'
00038             puts "    Mask key: ".ljust(31) + mask.mask_key_name
00039         elsif mask.kind_of? UnsupportedMask
00040             puts "    Class: ".ljust(31) + 'UnsupportedMask'
00041             puts "    Explanation: ".ljust(31) + mask.explanation
00042         else
00043             puts "    Class: ".ljust(31) + 'Unknown'
00044         end
00045 
00046         puts
00047 
00048     end
00049 
00050     puts
00051 end
00052 
00053 exit exit_status
00054