example_match_package.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 all installed packages 00020 ids = env[Selection::AllVersionsSorted.new( 00021 Generator::All.new | Filter::InstalledAtRoot.new("/"))] 00022 00023 # Fetch the 'system' and 'world' sets. Ordinarily we should check for 00024 # Nil here, but these two sets will always exist. 00025 system = env.set('system') 00026 world = env.set('world') 00027 00028 # For each ID: 00029 ids.each do | id | 00030 # Is it paludis? 00031 if match_package(env, parse_user_package_dep_spec('sys-apps/paludis', env, []), id, nil, []) 00032 puts id.to_s.ljust(49) + ': paludis' 00033 elsif match_package_in_set(env, system, id, []) 00034 puts id.to_s.ljust(49) + ': system' 00035 elsif match_package_in_set(env, world, id, []) 00036 puts id.to_s.ljust(49) + ': world' 00037 else 00038 puts id.to_s.ljust(49) + ': nothing' 00039 end 00040 end 00041 00042 exit exit_status 00043