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

example_repository.rb

This example demonstrates how to use Repository.

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 Repository.
00006 =end
00007 
00008 require 'Paludis'
00009 require 'example_command_line'
00010 
00011 include Paludis
00012 
00013 exit_status = 0
00014 
00015 # We start with an Environment, respecting the user's '--environment' choice.
00016 env = EnvironmentFactory.instance.create(ExampleCommandLine.instance.environment)
00017 
00018 # For each repository
00019 env.repositories do |repo|
00020     # A repository is identified by its name.
00021     puts repo.name + ':'
00022 
00023     # Like a PackageID, a Repository has metadata. Usually metadata
00024     # keys will be available for all of the configuration options for
00025     # that repository; some repositories also provide more (ebuild
00026     # format repositories, for example, provide info_pkgs too). See
00027     # "example_metadata_key.rb" for how to display a metadata key 
00028     # in detail.
00029     puts "    Metadata Keys:".ljust(30)
00030     repo.each_metadata do |key|
00031         puts "        #{key.human_name}"
00032     end
00033 
00034     # Repositories support various methods for querying categories,
00035     # packages, IDs and so on. These methods are used by
00036     # Environment::[], but are also sometimes of direct use to
00037     # clients.
00038     puts "    Number of categories: ".ljust(31) + repo.category_names.length.to_s
00039     puts "    IDs for sys-apps/paludis: ".ljust(31) + repo.package_ids('sys-apps/paludis').join(' ')
00040 
00041 end
00042 
00043 exit exit_status
00044