Class: Aruba::Platforms::UnixPlatform

Inherits:
Object
  • Object
show all
Defined in:
lib/aruba/platforms/unix_platform.rb

Overview

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

Direct Known Subclasses

WindowsPlatform

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.match?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/aruba/platforms/unix_platform.rb', line 34

def self.match?
  !Gem.win_platform?
end

Instance Method Details

#absolute_path?(path) ⇒ Boolean

Is absolute path

Returns:

  • (Boolean)


180
181
182
# File 'lib/aruba/platforms/unix_platform.rb', line 180

def absolute_path?(path)
  Pathname.new(path).absolute?
end

#announcerObject



50
51
52
# File 'lib/aruba/platforms/unix_platform.rb', line 50

def announcer
  Announcer
end

#builtin_shell_commandsObject



241
242
243
# File 'lib/aruba/platforms/unix_platform.rb', line 241

def builtin_shell_commands
  []
end

#chdir(dir_name, &block) ⇒ Object

Change to directory



126
127
128
129
130
131
132
# File 'lib/aruba/platforms/unix_platform.rb', line 126

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) ⇒ Object

Change mode of file/directory



150
151
152
# File 'lib/aruba/platforms/unix_platform.rb', line 150

def chmod(mode, args, options)
  FileUtils.chmod_R(mode, args, **options)
end

#command?(path) ⇒ Boolean

Check if command is relative

Returns:

  • (Boolean)

    true

    * command.sh
    

    false

    * /bin/command.sh
    * bin/command.sh
    


212
213
214
215
# File 'lib/aruba/platforms/unix_platform.rb', line 212

def command?(path)
  p = Pathname.new(path)
  p.relative? && p.basename == p
end

#command_monitorObject



54
55
56
# File 'lib/aruba/platforms/unix_platform.rb', line 54

def command_monitor
  CommandMonitor
end

#command_stringObject



42
43
44
# File 'lib/aruba/platforms/unix_platform.rb', line 42

def command_string
  UnixCommandString
end

#cp(src, dest) ⇒ Object

Copy file/directory



140
141
142
# File 'lib/aruba/platforms/unix_platform.rb', line 140

def cp(src, dest)
  FileUtils.cp_r(src, dest)
end

#create_file(*args) ⇒ Object



70
71
72
# File 'lib/aruba/platforms/unix_platform.rb', line 70

def create_file(*args)
  ArubaFileCreator.new.call(*args)
end

#create_fixed_size_file(*args) ⇒ Object



74
75
76
# File 'lib/aruba/platforms/unix_platform.rb', line 74

def create_fixed_size_file(*args)
  ArubaFixedSizeFileCreator.new.call(*args)
end

#current_rubyObject



98
99
100
# File 'lib/aruba/platforms/unix_platform.rb', line 98

def current_ruby
  ::File.join(RbConfig::CONFIG["bindir"], RbConfig::CONFIG["ruby_install_name"])
end

#default_shellObject



82
83
84
# File 'lib/aruba/platforms/unix_platform.rb', line 82

def default_shell
  "bash"
end

#deprecated(msg) ⇒ Object



94
95
96
# File 'lib/aruba/platforms/unix_platform.rb', line 94

def deprecated(msg)
  warn(format("%s. Called by %s", msg, caller[1]))
end

#detect_ruby(cmd) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/aruba/platforms/unix_platform.rb', line 86

def detect_ruby(cmd)
  if /^ruby\s/.match?(cmd)
    cmd.gsub(/^ruby\s/, "#{current_ruby} ")
  else
    cmd
  end
end

#determine_disk_usage(paths) ⇒ Object



66
67
68
# File 'lib/aruba/platforms/unix_platform.rb', line 66

def determine_disk_usage(paths)
  DetermineDiskUsage.new.call(paths)
end

#determine_file_size(*args) ⇒ Object



62
63
64
# File 'lib/aruba/platforms/unix_platform.rb', line 62

def determine_file_size(*args)
  DetermineFileSize.new.call(*args)
end

#directory?(f) ⇒ Boolean

Exists and is directory

Returns:

  • (Boolean)


160
161
162
# File 'lib/aruba/platforms/unix_platform.rb', line 160

def directory?(f)
  File.directory? f
end

#environment_variablesObject



38
39
40
# File 'lib/aruba/platforms/unix_platform.rb', line 38

def environment_variables
  UnixEnvironmentVariables
end

#executable?(f) ⇒ Boolean

Path is executable

Returns:

  • (Boolean)


170
171
172
# File 'lib/aruba/platforms/unix_platform.rb', line 170

def executable?(f)
  File.executable?(f)
end

#exist?(f) ⇒ Boolean

Path Exists

Returns:

  • (Boolean)


165
166
167
# File 'lib/aruba/platforms/unix_platform.rb', line 165

def exist?(f)
  File.exist? f
end

#expand_path(path, base) ⇒ Object

Expand path



175
176
177
# File 'lib/aruba/platforms/unix_platform.rb', line 175

def expand_path(path, base)
  File.expand_path(path, base)
end

#file?(f) ⇒ Boolean

Exists and is file

Returns:

  • (Boolean)


155
156
157
# File 'lib/aruba/platforms/unix_platform.rb', line 155

def file?(f)
  File.file? f
end

#filesystem_statusObject



46
47
48
# File 'lib/aruba/platforms/unix_platform.rb', line 46

def filesystem_status
  FilesystemStatus
end

#getwdObject

Get current working directory



121
122
123
# File 'lib/aruba/platforms/unix_platform.rb', line 121

def getwd
  Dir.getwd
end

#loggerObject



58
59
60
# File 'lib/aruba/platforms/unix_platform.rb', line 58

def logger
  ArubaLogger
end

#mkdir(dir_name) ⇒ Object

Create directory and subdirectories



107
108
109
110
111
# File 'lib/aruba/platforms/unix_platform.rb', line 107

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) ⇒ Object

Move file/directory



145
146
147
# File 'lib/aruba/platforms/unix_platform.rb', line 145

def mv(src, dest)
  FileUtils.mv(src, dest)
end

#relative_command?(path) ⇒ Boolean

Check if command is relative

Returns:

  • (Boolean)

    true

    * bin/command.sh
    

    false

    * /bin/command.sh
    * command.sh
    


198
199
200
201
# File 'lib/aruba/platforms/unix_platform.rb', line 198

def relative_command?(path)
  p = Pathname.new(path)
  p.relative? && p.basename != p
end

#relative_path?(path) ⇒ Boolean

Is relative path

Returns:

  • (Boolean)


185
186
187
# File 'lib/aruba/platforms/unix_platform.rb', line 185

def relative_path?(path)
  Pathname.new(path).relative?
end

#require_matching_files(pattern, base) ⇒ Object



102
103
104
# File 'lib/aruba/platforms/unix_platform.rb', line 102

def require_matching_files(pattern, base)
  ::Dir.glob(::File.expand_path(pattern, base)).sort.each { |f| require_relative f }
end

#rm(paths, options = {}) ⇒ Object

Remove file, directory + sub-directories



114
115
116
117
118
# File 'lib/aruba/platforms/unix_platform.rb', line 114

def rm(paths, options = {})
  paths = Array(paths).map { |p| ::File.expand_path(p) }

  FileUtils.rm_r(paths, **options)
end

#simple_table(hash, opts = {}) ⇒ Object

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



223
224
225
# File 'lib/aruba/platforms/unix_platform.rb', line 223

def simple_table(hash, opts = {})
  SimpleTable.new(hash, opts).to_s
end

#term_signal_supported?Boolean

Returns:

  • (Boolean)


245
246
247
# File 'lib/aruba/platforms/unix_platform.rb', line 245

def term_signal_supported?
  true
end

#touch(args, options) ⇒ Object

Touch file, directory



135
136
137
# File 'lib/aruba/platforms/unix_platform.rb', line 135

def touch(args, options)
  FileUtils.touch(args, **options)
end

#which(program, path = ENV["PATH"]) ⇒ Object

Resolve path for command using the PATH-environment variable

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

Parameters:

  • program (#to_s)

    The name of the program which should be resolved

  • path (String) (defaults to: ENV["PATH"])

    The PATH, a string concatenated with “:”, e.g. /usr/bin/:/bin on a UNIX-system



237
238
239
# File 'lib/aruba/platforms/unix_platform.rb', line 237

def which(program, path = ENV["PATH"])
  UnixWhich.new.call(program, path)
end

#with_environment(env = {}, &block) ⇒ Object



78
79
80
# File 'lib/aruba/platforms/unix_platform.rb', line 78

def with_environment(env = {}, &block)
  LocalEnvironment.new.call(env, &block)
end

#write_file(path, content) ⇒ Object

Write to file



218
219
220
# File 'lib/aruba/platforms/unix_platform.rb', line 218

def write_file(path, content)
  File.write(path, content)
end