class Aruba::Platforms::UnixPlatform

WARNING: All methods found here are not considered part of the public API of aruba.

Those methods can be changed at any time in the feature or removed without any further notice.

This includes all methods for the UNIX platform

@private

Public Class Methods

match?() click to toggle source
# File lib/aruba/platforms/unix_platform.rb, line 33
def self.match?
  !FFI::Platform.windows?
end

Public Instance Methods

absolute_path?(path) click to toggle source

Is absolute path

# File lib/aruba/platforms/unix_platform.rb, line 194
def absolute_path?(path)
  Pathname.new(path).absolute?
end
announcer() click to toggle source
# File lib/aruba/platforms/unix_platform.rb, line 49
def announcer
  Announcer
end
chdir(dir_name, &block) click to toggle source

Change to directory

# File lib/aruba/platforms/unix_platform.rb, line 138
def chdir(dir_name, &block)
  dir_name = ::File.expand_path(dir_name.to_s)

  with_environment 'OLDPWD' => getwd, 'PWD' => dir_name do
    ::Dir.chdir(dir_name, &block)
  end
end
chmod(mode, args, options) click to toggle source

Change mode of file/directory

# File lib/aruba/platforms/unix_platform.rb, line 163
def chmod(mode, args, options)
  FileUtils.chmod_R(mode, args, :noop => options[:noop],
                    :verbose => options[:verbose], :force => options[:force])
end
command?(path) click to toggle source

Check if command is relative

@return [TrueClass, FalseClass]

true
  * command.sh

false
  * /bin/command.sh
  * bin/command.sh
# File lib/aruba/platforms/unix_platform.rb, line 226
def command?(path)
  p = Pathname.new(path)
  p.relative? && p.basename == p
end
command_monitor() click to toggle source
# File lib/aruba/platforms/unix_platform.rb, line 53
def command_monitor
  CommandMonitor
end
command_string() click to toggle source
# File lib/aruba/platforms/unix_platform.rb, line 41
def command_string
  UnixCommandString
end
cp(src, dest) click to toggle source

Copy file/directory

# File lib/aruba/platforms/unix_platform.rb, line 153
def cp(src, dest)
  FileUtils.cp_r(src, dest)
end
create_file(*args) click to toggle source
# File lib/aruba/platforms/unix_platform.rb, line 69
def create_file(*args)
  ArubaFileCreator.new.call(*args)
end
create_fixed_size_file(*args) click to toggle source
# File lib/aruba/platforms/unix_platform.rb, line 73
def create_fixed_size_file(*args)
  ArubaFixedSizeFileCreator.new.call(*args)
end
current_ruby() click to toggle source
# File lib/aruba/platforms/unix_platform.rb, line 97
def current_ruby
  ::File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
end
default_shell() click to toggle source
# File lib/aruba/platforms/unix_platform.rb, line 81
def default_shell
  'bash'
end
deprecated(msg) click to toggle source
# File lib/aruba/platforms/unix_platform.rb, line 93
def deprecated(msg)
  warn(format('%s. Called by %s', msg, caller[1]))
end
detect_ruby(cmd) click to toggle source
# File lib/aruba/platforms/unix_platform.rb, line 85
def detect_ruby(cmd)
  if cmd =~ /^ruby\s/
    cmd.gsub(/^ruby\s/, "#{current_ruby} ")
  else
    cmd
  end
end
determine_disk_usage(*args) click to toggle source
# File lib/aruba/platforms/unix_platform.rb, line 65
def determine_disk_usage(*args)
  DetermineDiskUsage.new.call(*args)
end
determine_file_size(*args) click to toggle source
# File lib/aruba/platforms/unix_platform.rb, line 61
def determine_file_size(*args)
  DetermineFileSize.new.call(*args)
end
directory?(f) click to toggle source

Exists and is directory

# File lib/aruba/platforms/unix_platform.rb, line 174
def directory?(f)
  File.directory? f
end
ensure_newline(str) click to toggle source

@deprecated Add newline at the end

# File lib/aruba/platforms/unix_platform.rb, line 103
def ensure_newline(str)
  deprecated('The use of "#ensure_newline" is deprecated. It will be removed soon')

  str.chomp << "\n"
end
environment_variables() click to toggle source
# File lib/aruba/platforms/unix_platform.rb, line 37
def environment_variables
  UnixEnvironmentVariables
end
executable?(f) click to toggle source

Path is executable

# File lib/aruba/platforms/unix_platform.rb, line 184
def executable?(f)
  File.executable?(f)
end
exist?(f) click to toggle source

Path Exists

# File lib/aruba/platforms/unix_platform.rb, line 179
def exist?(f)
  File.exist? f
end
expand_path(path, base) click to toggle source

Expand path

# File lib/aruba/platforms/unix_platform.rb, line 189
def expand_path(path, base)
  File.expand_path(path, base)
end
file?(f) click to toggle source

Exists and is file

# File lib/aruba/platforms/unix_platform.rb, line 169
def file?(f)
  File.file? f
end
filesystem_status() click to toggle source
# File lib/aruba/platforms/unix_platform.rb, line 45
def filesystem_status
  FilesystemStatus
end
getwd() click to toggle source

Get current working directory

# File lib/aruba/platforms/unix_platform.rb, line 133
def getwd
  Dir.getwd
end
logger() click to toggle source
# File lib/aruba/platforms/unix_platform.rb, line 57
def logger
  ArubaLogger
end
mkdir(dir_name) click to toggle source

Create directory and subdirectories

# File lib/aruba/platforms/unix_platform.rb, line 118
def mkdir(dir_name)
  dir_name = ::File.expand_path(dir_name)

  ::FileUtils.mkdir_p(dir_name) unless ::File.directory?(dir_name)
end
mv(src, dest) click to toggle source

Move file/directory

# File lib/aruba/platforms/unix_platform.rb, line 158
def mv(src, dest)
  FileUtils.mv(src, dest)
end
relative_command?(path) click to toggle source

Check if command is relative

@return [TrueClass, FalseClass]

true
  * bin/command.sh

false
  * /bin/command.sh
  * command.sh
# File lib/aruba/platforms/unix_platform.rb, line 212
def relative_command?(path)
  p = ArubaPath.new(path)
  p.relative? && p.depth > 1
end
relative_path?(path) click to toggle source

Is relative path

# File lib/aruba/platforms/unix_platform.rb, line 199
def relative_path?(path)
  Pathname.new(path).relative?
end
require_matching_files(pattern, base) click to toggle source
# File lib/aruba/platforms/unix_platform.rb, line 109
def require_matching_files(pattern, base)
  if RUBY_VERSION < '1.9.3'
    ::Dir.glob(::File.expand_path(pattern, base)).each { |f| require File.join(File.dirname(f), File.basename(f, '.rb')) }
  else
    ::Dir.glob(::File.expand_path(pattern, base)).each { |f| require_relative f }
  end
end
rm(paths, options = {}) click to toggle source

Remove file, directory + sub-directories

# File lib/aruba/platforms/unix_platform.rb, line 125
def rm(paths, options = {})
  paths = Array(paths).map { |p| ::File.expand_path(p) }

  FileUtils.rm_r(paths, :force => options[:force], :noop => options[:noop],
                 :verbose => options[:verbose], :secure => options[:secure])
end
simple_table(hash, opts = {}) click to toggle source

Transform hash to a string table which can be output on stderr/stdout

# File lib/aruba/platforms/unix_platform.rb, line 260
def simple_table(hash, opts = {})
  SimpleTable.new(hash, opts).to_s
end
touch(args, options) click to toggle source

Touch file, directory

# File lib/aruba/platforms/unix_platform.rb, line 147
def touch(args, options)
  FileUtils.touch(args, :noop => options[:noop], :verbose => options[:verbose],
                  :mtime => options[:mtime], :nocreate => options[:nocreate])
end
unescape(string, keep_ansi = true) click to toggle source

Unescape string

@param [String] string

The string which should be unescaped, e.g. the output of a command

@return

The string stripped from escape sequences
# File lib/aruba/platforms/unix_platform.rb, line 249
def unescape(string, keep_ansi = true)
  # rubocop:disable Metrics/LineLength
  deprecated('The use of "Aruba.platform.unescape" is deprecated. Please use "#unescape_text" and "#sanitize_text" instead. But be aware it uses a different implementation')
  # rubocop:enable Metrics/LineLength

  string = string.gsub('\n', "\n").gsub('\"', '"').gsub('\e', "\e")
  string = string.gsub(/\e\[\d+(?>(;\d+)*)m/, '') unless keep_ansi
  string
end
which(program, path = ENV['PATH']) click to toggle source

Resolve path for command using the PATH-environment variable

Mostly taken from here: github.com/djberg96/ptools

@param [#to_s] program

The name of the program which should be resolved

@param [String] path

The PATH, a string concatenated with ":", e.g. /usr/bin/:/bin on a
UNIX-system
# File lib/aruba/platforms/unix_platform.rb, line 274
def which(program, path = ENV['PATH'])
  UnixWhich.new.call(program, path)
end
with_environment(env = {}, &block) click to toggle source
# File lib/aruba/platforms/unix_platform.rb, line 77
def with_environment(env = {}, &block)
  LocalEnvironment.new.call(env, &block)
end
write_file(path, content) click to toggle source

Write to file

# File lib/aruba/platforms/unix_platform.rb, line 232
def write_file(path, content)
  if RUBY_VERSION < '1.9.3'
    File.open(path, 'wb') do |f|
      f.print content
    end
  else
    File.write(path, content)
  end
end