Class: BuildTool::Commands::Recipes::Install
- Defined in:
- lib/build-tool/commands/recipes/install.rb
Overview
BuildCommand
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #do_execute(args) ⇒ Object
- #find_in_path(path, name) ⇒ Object
- #find_writable_dirs(path) ⇒ Object
- #initialize_options ⇒ Object
Methods inherited from Standard
#complete_module, #complete_modules, #initialize, #log_directory, #while_logging_to
Methods inherited from Base
#<=>, #applicable?, #cleanup_after_vcs_access, #complete_arguments, #complete_readline, #configuration, #debug, #debug2, #do_complete, #each_option, #error, #execute, #fullname, #info, #initialize, #log?, #quiet, #setup_command, #setup_options, #show_help, #skip_command, #summarize, #teardown_command, #trace, #usage, #verbose, #warn
Methods included from HelpText
#cmdalias, #description, included, #long_description, #name
Constructor Details
This class inherits a constructor from BuildTool::Commands::Standard
Instance Method Details
#do_execute(args) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/build-tool/commands/recipes/install.rb', line 26 def do_execute(args) require 'rubygems/user_interaction' # Check parameters if args.length < 1 or args.length > 2 return usage("Wrong number of arguments") end # First param is recipename recipename = args[0] # Second optional parameter is command name if args.length == 2 commandname = args[1] else commandname = args[0] end exename = "#{commandname}-build" conffile = Application::instance.local_configuration_dir.join("#{commandname}.yaml") # Our executable. We use $0 directly here to pick up any rubygem wrapper that could # exists. But we use realpath to skip any unnecessary link buildtool = Pathname.new( $0 ).realpath() # Load the recipe recipe = Recipe.find_recipe(recipename) if !recipe error( "Unknown recipe #{recipename}!" ) return -1 end info( <<-EOS ) Step 1) We need to add a symbolic link name '#{exename}' into $PATH. EOS # Check if there are already commands with exename existing = find_in_path( ENV['PATH'], exename ) found = false # Was the link found? existing.each do |exe| if exe.exist? if exe.symlink? and File.identical? exe, buildtool found = true else warn( "Found another command named #{exename} at #{exe.to_s}" ) end end end if found == true info( "The symlink already exists. We will skip this step." ) else dirs = find_writable_dirs( ENV['PATH'] ) dir = nil if dirs.empty? error( "No writable directory found in $PATH. Please add one (usually $HOME/bin)" ) error( "or create a symbolic link in a directory that is part of $PATH yourself." ) error( "> ln -s #{buildtool} #{exename}" ) elsif dirs.length == 1 dir = dirs[0] info( "Exactly one writeable directory found in $PATH. I will create the symbolic link in" ) info( "#{dir}" ) else if dirs.length > 1 ( dir, index ) = Gem::DefaultUserInteraction.ui.choose_from_list( "More than one writeable directory found in $PATH. Which one should i use?", dirs) end end link = Pathname.new(dir).join(exename) if link.exist? error( "I can not create the link because the 'to' already exists. Please create" ) error( "a symbolic link in a directory that is part of $PATH yourself." ) error( "> ln -s #{buildtool} #{exename}" ) else File.symlink( buildtool, link ) end end # Now write the settings file info( <<EOS ) Step 2) A example configuration is imported into the database. I will open a editor so you are able to adjust it to your needs. The configuration contains comments. Please review them carefully. At least look at LIB_SUFFIX and MAKEFLAGS. EOS # Now switch to the correct database BuildTool::Application::instance.close_database() BuildTool::Application::instance.open_database( commandname ) # Add the recipe setting to the database. Needed to load the configuration and # initialize the database. rs = BuildTool::Setting.new( :name => 'BUILD_TOOL.RECIPE', :value => recipename ) rs.save! BuildTool::Configuration.edit() info( <<EOS ) Step 3) I will create a local configuration file that is used to override the used recipe without losing the ability to update. You will find it at > #{Application::instance.local_configuration_dir.join( commandname, 'recipe' )} EOS if File.exist?( Application::instance.local_configuration_dir.join(commandname)) error( "Local configuration for #{commandname} already exists." ) else FileUtils.mkdir_p( Application::instance.local_configuration_dir.join( commandname ) ) FileUtils.cp(recipe.join("recipe-local"), Application::instance.local_configuration_dir.join( commandname, 'recipe' )) end info( <<EOS ) Step 4) You now can start to use your recipe. The first commands you should look for are: # Show the configuration > #{exename} info # Show all modules > #{exename} module list # Show detailed info for a module > #{exename} module info <module> # Build a module (-u = enable updating) > #{exename} build -u <module> EOS # We were successful return 0 end |
#find_in_path(path, name) ⇒ Object
168 169 170 171 172 173 174 175 176 177 |
# File 'lib/build-tool/commands/recipes/install.rb', line 168 def find_in_path( path, name ) dirs = [] path.split(':').each do |dir| hd = Pathname.new(dir).join(name) if hd.exist? dirs << hd end end dirs end |
#find_writable_dirs(path) ⇒ Object
157 158 159 160 161 162 163 164 165 166 |
# File 'lib/build-tool/commands/recipes/install.rb', line 157 def find_writable_dirs(path) dirs = [] path.split(':').each do |dir| dirhd = Pathname.new(dir) if dirhd.directory? and dirhd.writable? dirs << dir end end dirs end |
#initialize_options ⇒ Object
19 20 21 22 23 24 |
# File 'lib/build-tool/commands/recipes/install.rb', line 19 def . = "Usage: #{self.fullname} [OPTIONS]... RECIPE [SCRIPTNAME]" .separator( "" ) .separator( "Options" ) super end |