aboutsummaryrefslogtreecommitdiff
path: root/doc/api/ruby/example_match_package.rb
blob: e0ac15d9f0e2d114b320d490911a9bfb0997adb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env ruby
# vim: set sw=4 sts=4 et tw=100 :

=begin description
This example demonstrates how to use contents. It displays details about
the files installed by 'sys-apps/paludis'.
=end

require 'Paludis'
require 'example_command_line'

include Paludis

exit_status = 0

# We start with an Environment, respecting the user's '--environment' choice.
env = EnvironmentFactory.instance.create(ExampleCommandLine.instance.environment)

# Fetch all installed packages
ids = env[Selection::AllVersionsSorted.new(
    Generator::All.new | Filter::SupportsAction.new(InstalledAction))]

# Fetch the 'system' and 'world' sets. Ordinarily we should check for
# Nil here, but these two sets will always exist.
system = env.set('system')
world = env.set('world')

# For each ID:
ids.each do | id |
    # Is it paludis?
    if match_package(env, parse_user_package_dep_spec('sys-apps/paludis', env, []), id)
        puts id.to_s.ljust(49) + ': paludis'
    elsif match_package_in_set(env, system, id)
        puts id.to_s.ljust(49) + ': system'
    elsif match_package_in_set(env, world, id)
        puts id.to_s.ljust(49) + ': world'
    else
        puts id.to_s.ljust(49) + ': nothing'
    end
end

exit exit_status