aboutsummaryrefslogtreecommitdiff
path: root/doc/api/ruby/example_repository.rb
blob: a0c7374d1a7a271e93d220502c1d7b11853c0374 (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
44
#!/usr/bin/env ruby
# vim: set sw=4 sts=4 et tw=100 :

=begin description
This example demonstrates how to use Repository.
=end

require 'Paludis'
require 'example_command_line'

include Paludis

exit_status = 0

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

# For each repository
env.package_database.repositories do |repo|
    # A repository is identified by its name.
    puts repo.name + ':'

    # Like a PackageID, a Repository has metadata. Usually metadata
    # keys will be available for all of the configuration options for
    # that repository; some repositories also provide more (ebuild
    # format repositories, for example, provide info_pkgs too). See
    # "example_metadata_key.rb" for how to display a metadata key 
    # in detail.
    puts "    Metadata Keys:".ljust(30)
    repo.each_metadata do |key|
        puts "        #{key.human_name}"
    end

    # Repositories support various methods for querying categories,
    # packages, IDs and so on. These methods are used by
    # PackageDatabase::query, but are also sometimes of direct use to
    # clients.
    puts "    Number of categories: ".ljust(31) + repo.category_names.length.to_s
    puts "    IDs for sys-apps/paludis: ".ljust(31) + repo.package_ids('sys-apps/paludis').join(' ')

end

exit exit_status