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

example_dep_spec.rb

This example demonstrates how to handle dependency specs.

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 handle dependency specs.
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 = EnvironmentMaker.instance.make_from_spec(ExampleCommandLine.instance.environment)
00017 
00018 # For each command line parameter:
00019 ARGV.each do | arg |
00020     # Create a PackageDepSpec from the parameter. The second parameter should be either
00021     # an empty array or [:allow_wildcards].
00022     spec = Paludis::parse_user_package_dep_spec(arg, [:allow_wildcards])
00023 
00024     # Display information about the PackageDepSpec.
00025     puts "Information about '#{spec}':"
00026 
00027     if spec.package
00028         puts "    Package:                #{spec.package}"
00029     end
00030 
00031     if spec.category_name_part
00032         puts "    Category part:          #{spec.category_name_part}"
00033     end
00034 
00035     if spec.package_name_part
00036         puts "    Package part:           #{spec.package_name_part}"
00037     end
00038 
00039     if spec.version_requirements and not spec.version_requirements.empty?
00040         print "    Version requirements:   "
00041         need_join = false
00042         spec.version_requirements.each do | r |
00043             if need_join
00044                 case spec.version_requirements_mode
00045                 when VersionRequirementsMode::And
00046                     print " and "
00047                 when VersionRequirementsMode::Or
00048                     print " or "
00049                 end
00050             end
00051 
00052             print r[:operator], r[:spec]
00053             need_join = true
00054         end
00055         puts
00056     end
00057 
00058     if spec.slot
00059         puts "    Slot:                   #{spec.slot}"
00060     end
00061 
00062     if spec.repository
00063         puts "    Repository:             #{spec.repository}"
00064     end
00065 
00066     if spec.use_requirements and not spec.use_requirements.empty?
00067         print "    Use requirements:       "
00068         need_join = false
00069         spec.use_requirements.each do | u |
00070             if need_join
00071                 print " and "
00072             end
00073 
00074             if not u[:state]
00075                 print "-"
00076             end
00077 
00078             print u[:flag]
00079             need_join = true;
00080         end
00081         puts
00082     end
00083 
00084     # And display packages matching that spec
00085     print "    Matches:                "
00086     ids = env.package_database.query(Query::Matches.new(spec), QueryOrder::OrderByVersion)
00087     need_indent = false
00088     ids.each do | id |
00089         if need_indent
00090             puts
00091             print "                            "
00092         end
00093         print id
00094         need_indent = true
00095     end
00096     puts
00097     puts
00098 end
00099 
00100 exit exit_status
00101