Class: Pawnee::Actions::Compile
- Inherits:
-
Object
- Object
- Pawnee::Actions::Compile
- Defined in:
- lib/pawnee/pawnee/actions/compile.rb
Instance Attribute Summary collapse
-
#base ⇒ Object
Returns the value of attribute base.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#configure ⇒ Object
Runs ./configure on the files.
-
#download(url) ⇒ Object
Uses get to download the file and place it in the temp path.
-
#extract ⇒ Object
Extract the compressed file.
-
#initialize(base, url, temp_dir, options) ⇒ Compile
constructor
Sets up a compile object.
-
#make ⇒ Object
Runs make.
-
#make_install ⇒ Object
Runs sudo make install.
-
#run_with_failure_handler(command, action_name) ⇒ Object
Takes a command and an action_name.
Constructor Details
#initialize(base, url, temp_dir, options) ⇒ Compile
Sets up a compile object
Parameters
- base<Thor>
-
The main class
- url<String>
-
The url to download from
- temp_dir<String>
-
A path to a temporary directory where the compilation
can take place
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/pawnee/pawnee/actions/compile.rb', line 66 def initialize(base, url, temp_dir, ) @base = base @temp_dir = temp_dir self. = @file = File.basename(url) @zip_file = @file[/[.]zip$/] @file_path = File.join(temp_dir, @file) # TODO: GET THE FIRST DIRECTORY INSTEAD dir_name = @file.gsub(/[.]tar[.]gz$/, '').gsub(/[.]zip$/, '') @extracted_path = File.join(temp_dir, dir_name) @base.say_status 'download and compile', url download(url) extract configure unless [:skip_configure] make make_install end |
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
56 57 58 |
# File 'lib/pawnee/pawnee/actions/compile.rb', line 56 def base @base end |
#options ⇒ Object
Returns the value of attribute options.
57 58 59 |
# File 'lib/pawnee/pawnee/actions/compile.rb', line 57 def @options end |
Instance Method Details
#configure ⇒ Object
Runs ./configure on the files
126 127 128 |
# File 'lib/pawnee/pawnee/actions/compile.rb', line 126 def configure run_with_failure_handler("cd #{@extracted_path} ; ./configure #{[:config_options] || ''}", 'configure') end |
#download(url) ⇒ Object
Uses get to download the file and place it in the temp path
88 89 90 |
# File 'lib/pawnee/pawnee/actions/compile.rb', line 88 def download(url) base.get(url, @file_path) end |
#extract ⇒ Object
Extract the compressed file
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/pawnee/pawnee/actions/compile.rb', line 93 def extract base.say_status 'extract', @file if @zip_file base.exec("cd #{@temp_dir} ; unzip #{@file}") else base.exec("cd #{@temp_dir} ; tar xvfpz #{@file}") end # Remove the file base.destination_files.rm_rf(@file_path) end |
#make ⇒ Object
Runs make
131 132 133 |
# File 'lib/pawnee/pawnee/actions/compile.rb', line 131 def make run_with_failure_handler("cd #{@extracted_path} ; make", 'make') end |
#make_install ⇒ Object
Runs sudo make install
136 137 138 |
# File 'lib/pawnee/pawnee/actions/compile.rb', line 136 def make_install run_with_failure_handler("cd #{@extracted_path} ; sudo make install", 'make install') end |
#run_with_failure_handler(command, action_name) ⇒ Object
Takes a command and an action_name. It says its running the action_name, then runs the command and if there is non-zero exit status, it prints out an error, stdout, and stderr, then raises an exception
Parameters
- command<String>
-
The command to be run
- action_name<String>
-
An action name (used to explain what is happening)
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/pawnee/pawnee/actions/compile.rb', line 112 def run_with_failure_handler(command, action_name) base.say_status action_name.downcase, '' stdout, stderr, exit_code, exit_status = base.exec(command, :with_codes => true) if exit_code != 0 base.say_status :error, "Unable to #{action_name}, see output below", :red puts stdout puts stderr raise "Unable to configure #{action_name}" end end |