class Pennyworth::LocalCommandRunner
LocalCommandRunner
is used for executing commands on the local machine
Public Class Methods
new(opts = {})
click to toggle source
Initialize the command runner
opts
-
Options to modify how and which the commands are run.
Available options:
- [env]
-
Hash of environment options to set for the command, e.g.
{ "MACHINERY_DIR" => "/tmp/machinery" }
# File lib/pennyworth/local_command_runner.rb, line 30 def initialize(opts = {}) @env = opts[:env] || {} end
Public Instance Methods
extract_file(source, destination)
click to toggle source
# File lib/pennyworth/local_command_runner.rb, line 65 def extract_file(source, destination) FileUtils.cp(source, destination) end
inject_directory(source, destination, opts = {})
click to toggle source
# File lib/pennyworth/local_command_runner.rb, line 69 def inject_directory(source, destination, opts = {}) FileUtils.mkdir_p(destination) FileUtils.cp_r(source, destination) FileUtils.chown_R(opts[:owner], opts[:group], destination) end
inject_file(source, destination, opts = {})
click to toggle source
Copy a local file to the remote system.
source
-
Path to the local file
destination
-
Path to the remote file or directory. If
destination
is a path, the same filename assource
will be used. opts
-
Options to modify the attributes of the remote file.
Available options:
- [owner]
-
Owner of the file, e.g. “tux”
- [group]
-
Group of the file, e.g. “users”
- [mode]
-
Mode of the file, e.g. “600”
# File lib/pennyworth/local_command_runner.rb, line 55 def inject_file(source, destination, opts = {}) # Append filename (taken from +source+) to destination if it is a path, so # that +destination+ is always the full target path including the filename. destination = File.join(destination, File.basename(source)) if File.directory?(destination) FileUtils.cp(source, destination) FileUtils.chown(opts[:owner], opts[:group], destination) FileUtils.chmod(opts[:mode], destination) if opts[:mode] end
run(*args)
click to toggle source
# File lib/pennyworth/local_command_runner.rb, line 34 def run(*args) options = args.last.is_a?(Hash) ? args.pop : {} with_env(@env) do Cheetah.run( "bash", "-c", *args, options ) end end