example_environment.rb
This example demonstrates how to use EnvironmentFactory and the resultant Environment.
00001 #!/usr/bin/env ruby 00002 # vim: set sw=4 sts=4 et tw=80 : 00003 00004 =begin description 00005 This example demonstrates how to use EnvironmentFactory and the resultant 00006 Environment. 00007 =end 00008 00009 require 'Paludis' 00010 require 'example_command_line' 00011 00012 include Paludis 00013 00014 exit_status = 0 00015 00016 # We use EnvironmentFactory to construct an environment from the user's 00017 # --environment commandline choice. With an empty string, this uses the 00018 # distribution-defined default environment. With a non-empty string, it 00019 # is split into two parts upon the first colon (if there is no colon, 00020 # the second part is considered empty). The first part is the name of 00021 # the environment class to use (e.g. 'paludis', 'portage') and the 00022 # second part is passed as parameters to be handled by that 00023 # environment's constructor. 00024 env = EnvironmentFactory.instance.create(ExampleCommandLine.instance.environment) 00025 00026 # A lot of the Environment members aren't very useful to clients. The mask 00027 # related methods are used by PackageID, and shouldn't usually be called 00028 # directly from clients. The system information and mirror functions are mostly 00029 # for use by Repository subclasses. The [] operator is covered in other 00030 # examples. That leaves the package database and sets. The package database has 00031 # its own examples, so we'll start with sets: 00032 00033 world = env.set('world') 00034 if (world) 00035 # see examples_dep_tree.rb for how to make use of this set 00036 puts "World set exists" 00037 else 00038 puts "No world set defined" 00039 end 00040
