example_contents.rb
This example demonstrates how to use contents. It displays details about the files installed by 'sys-apps/paludis'.
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 contents. It displays details about 00006 the files installed by 'sys-apps/paludis'. 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 installed 'sys-apps/paludis' 00020 ids = env[Selection::AllVersionsSorted.new( 00021 Generator::Matches.new(Paludis::parse_user_package_dep_spec("sys-apps/paludis", env, []), []) | 00022 Filter::SupportsAction.new(InstalledAction))] 00023 00024 # For each ID: 00025 ids.each do | id | 00026 # Do we have a contents key? PackageID _key methods can return Nil. 00027 if not id.contents_key 00028 puts "ID '#{id}' does not provide a contents key." 00029 else 00030 puts "ID '#{id}' provides contents key:" 00031 00032 # Contents is made up of a collection of ContentsEntry instances. 00033 id.contents_key.value.each do | c | 00034 00035 # Some ContentsEntry subclasses contain more information than others 00036 if c.kind_of? ContentsDevEntry 00037 puts "device #{c.name}" 00038 00039 elsif c.kind_of? ContentsMiscEntry 00040 puts "misc #{c.name}" 00041 00042 elsif c.kind_of? ContentsFileEntry 00043 puts "file #{c.name}" 00044 00045 elsif c.kind_of? ContentsDirEntry 00046 puts "dir #{c.name}" 00047 00048 elsif c.kind_of? ContentsFifoEntry 00049 puts "fifo #{c.name}" 00050 00051 elsif c.kind_of? ContentsSymEntry 00052 puts "sym #{c.name} -> #{c.target}" 00053 00054 else 00055 puts "unknown #{c}" 00056 end 00057 end 00058 00059 puts 00060 end 00061 end 00062 00063 exit exit_status 00064
