aruba 1.0.0.pre.alpha.2 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/PULL_REQUEST_TEMPLATE.md +2 -1
- data/.rspec +0 -1
- data/.rubocop.yml +46 -182
- data/.rubocop_todo.yml +216 -0
- data/.simplecov +7 -5
- data/.travis.yml +56 -40
- data/.yardopts +3 -0
- data/CHANGELOG.md +1312 -0
- data/CONTRIBUTING.md +175 -83
- data/Gemfile +5 -69
- data/LICENSE +1 -1
- data/README.md +58 -21
- data/Rakefile +27 -54
- data/appveyor.yml +7 -10
- data/aruba.gemspec +38 -19
- data/bin/console +3 -12
- data/cucumber.yml +4 -22
- data/exe/aruba +1 -1
- data/fixtures/cli-app/README.md +1 -1
- data/fixtures/cli-app/Rakefile +1 -1
- data/fixtures/cli-app/bin/aruba-test-cli +1 -1
- data/fixtures/cli-app/cli-app.gemspec +4 -4
- data/fixtures/cli-app/lib/cli/app.rb +1 -1
- data/fixtures/cli-app/lib/cli/app/suppress_simple_cov_output.rb +3 -3
- data/fixtures/cli-app/lib/cli/app/version.rb +1 -1
- data/fixtures/cli-app/spec/spec_helper.rb +3 -2
- data/fixtures/empty-app/Rakefile +1 -1
- data/fixtures/empty-app/cli-app.gemspec +4 -4
- data/fixtures/empty-app/lib/cli/app.rb +0 -2
- data/fixtures/empty-app/lib/cli/app/version.rb +1 -1
- data/fixtures/getting-started-app/Gemfile +1 -1
- data/lib/aruba/api.rb +8 -15
- data/lib/aruba/api/bundler.rb +16 -0
- data/lib/aruba/api/commands.rb +272 -0
- data/lib/aruba/api/core.rb +82 -43
- data/lib/aruba/api/environment.rb +24 -7
- data/lib/aruba/api/filesystem.rb +66 -64
- data/lib/aruba/api/text.rb +17 -11
- data/lib/aruba/aruba_path.rb +25 -111
- data/lib/aruba/basic_configuration.rb +8 -25
- data/lib/aruba/basic_configuration/option.rb +2 -2
- data/lib/aruba/cli.rb +4 -1
- data/lib/aruba/colorizer.rb +10 -99
- data/lib/aruba/command.rb +4 -0
- data/lib/aruba/config/jruby.rb +15 -5
- data/lib/aruba/config_wrapper.rb +17 -2
- data/lib/aruba/configuration.rb +107 -0
- data/lib/aruba/console.rb +5 -7
- data/lib/aruba/console/help.rb +5 -2
- data/lib/aruba/contracts/absolute_path.rb +3 -3
- data/lib/aruba/contracts/is_power_of_two.rb +2 -2
- data/lib/aruba/contracts/relative_path.rb +3 -3
- data/lib/aruba/cucumber.rb +0 -3
- data/lib/aruba/cucumber/command.rb +227 -190
- data/lib/aruba/cucumber/environment.rb +1 -1
- data/lib/aruba/cucumber/file.rb +56 -50
- data/lib/aruba/cucumber/hooks.rb +10 -63
- data/lib/aruba/cucumber/testing_frameworks.rb +76 -50
- data/lib/aruba/event_bus.rb +4 -2
- data/lib/aruba/event_bus/name_resolver.rb +10 -10
- data/lib/aruba/events.rb +2 -1
- data/lib/aruba/hooks.rb +3 -5
- data/lib/aruba/in_config_wrapper.rb +10 -3
- data/lib/aruba/initializer.rb +40 -34
- data/lib/aruba/matchers/base/base_matcher.rb +2 -11
- data/lib/aruba/matchers/base/message_indenter.rb +19 -0
- data/lib/aruba/matchers/base/object_formatter.rb +2 -7
- data/lib/aruba/matchers/collection/include_an_object.rb +11 -13
- data/lib/aruba/matchers/command/be_successfully_executed.rb +8 -4
- data/lib/aruba/matchers/command/have_exit_status.rb +16 -4
- data/lib/aruba/matchers/command/have_finished_in_time.rb +5 -5
- data/lib/aruba/matchers/command/have_output.rb +12 -5
- data/lib/aruba/matchers/command/have_output_on_stderr.rb +4 -2
- data/lib/aruba/matchers/command/have_output_on_stdout.rb +4 -2
- data/lib/aruba/matchers/command/have_output_size.rb +2 -2
- data/lib/aruba/matchers/directory/be_an_existing_directory.rb +5 -7
- data/lib/aruba/matchers/directory/have_sub_directory.rb +10 -7
- data/lib/aruba/matchers/file/be_a_command_found_in_path.rb +2 -4
- data/lib/aruba/matchers/file/be_an_existing_executable.rb +4 -6
- data/lib/aruba/matchers/file/be_an_existing_file.rb +5 -7
- data/lib/aruba/matchers/file/have_file_content.rb +4 -4
- data/lib/aruba/matchers/file/have_file_size.rb +8 -8
- data/lib/aruba/matchers/file/have_same_file_content.rb +9 -12
- data/lib/aruba/matchers/path/a_path_matching_pattern.rb +2 -4
- data/lib/aruba/matchers/path/be_an_absolute_path.rb +3 -5
- data/lib/aruba/matchers/path/be_an_existing_path.rb +4 -6
- data/lib/aruba/matchers/path/have_permissions.rb +8 -8
- data/lib/aruba/matchers/string/include_output_string.rb +8 -10
- data/lib/aruba/matchers/string/match_output_string.rb +9 -11
- data/lib/aruba/matchers/string/output_string_eq.rb +7 -9
- data/lib/aruba/platform.rb +0 -8
- data/lib/aruba/platforms/announcer.rb +60 -85
- data/lib/aruba/platforms/aruba_file_creator.rb +4 -2
- data/lib/aruba/platforms/aruba_fixed_size_file_creator.rb +8 -3
- data/lib/aruba/platforms/aruba_logger.rb +22 -2
- data/lib/aruba/platforms/command_monitor.rb +15 -102
- data/lib/aruba/platforms/determine_disk_usage.rb +56 -19
- data/lib/aruba/platforms/filesystem_status.rb +9 -9
- data/lib/aruba/platforms/local_environment.rb +2 -2
- data/lib/aruba/platforms/simple_table.rb +3 -11
- data/lib/aruba/platforms/unix_command_string.rb +7 -4
- data/lib/aruba/platforms/unix_environment_variables.rb +19 -26
- data/lib/aruba/platforms/unix_platform.rb +18 -39
- data/lib/aruba/platforms/unix_which.rb +3 -2
- data/lib/aruba/platforms/windows_command_string.rb +20 -7
- data/lib/aruba/platforms/windows_environment_variables.rb +42 -30
- data/lib/aruba/platforms/windows_platform.rb +4 -0
- data/lib/aruba/platforms/windows_which.rb +9 -4
- data/lib/aruba/processes/basic_process.rb +21 -27
- data/lib/aruba/processes/debug_process.rb +16 -5
- data/lib/aruba/processes/in_process.rb +20 -9
- data/lib/aruba/processes/spawn_process.rb +64 -36
- data/lib/aruba/rspec.rb +28 -31
- data/lib/aruba/runtime.rb +16 -7
- data/lib/aruba/setup.rb +32 -17
- data/lib/aruba/tasks/docker_helpers.rb +4 -2
- data/lib/aruba/version.rb +1 -1
- metadata +194 -64
- data/History.md +0 -612
- data/bin/bootstrap +0 -34
- data/bin/build +0 -3
- data/bin/release +0 -3
- data/fixtures/spawn_process/stderr.sh +0 -3
- data/lib/aruba/api/command.rb +0 -309
- data/lib/aruba/api/deprecated.rb +0 -895
- data/lib/aruba/api/rvm.rb +0 -44
- data/lib/aruba/config.rb +0 -101
- data/lib/aruba/cucumber/rvm.rb +0 -3
- data/lib/aruba/in_process.rb +0 -14
- data/lib/aruba/jruby.rb +0 -4
- data/lib/aruba/matchers/path/match_path_pattern.rb +0 -41
- data/lib/aruba/matchers/rspec_matcher_include_regexp.rb +0 -25
- data/lib/aruba/platforms/disk_usage_calculator.rb +0 -20
- data/lib/aruba/spawn_process.rb +0 -11
@@ -13,6 +13,8 @@ module Aruba
|
|
13
13
|
#
|
14
14
|
# @param [String] value
|
15
15
|
# The value of the environment variable. Needs to be a string.
|
16
|
+
#
|
17
|
+
# @return [self]
|
16
18
|
def set_environment_variable(name, value)
|
17
19
|
name = name.to_s
|
18
20
|
value = value.to_s
|
@@ -21,7 +23,10 @@ module Aruba
|
|
21
23
|
aruba.environment[name] = value
|
22
24
|
new_environment = aruba.environment.to_h
|
23
25
|
|
24
|
-
|
26
|
+
environment_change = { old: old_environment,
|
27
|
+
new: new_environment,
|
28
|
+
changed: { name: name, value: value } }
|
29
|
+
aruba.event_bus.notify Events::AddedEnvironmentVariable.new(environment_change)
|
25
30
|
|
26
31
|
self
|
27
32
|
end
|
@@ -33,6 +38,8 @@ module Aruba
|
|
33
38
|
#
|
34
39
|
# @param [String] value
|
35
40
|
# The value of the environment variable. Needs to be a string.
|
41
|
+
#
|
42
|
+
# @return [self]
|
36
43
|
def append_environment_variable(name, value)
|
37
44
|
name = name.to_s
|
38
45
|
value = value.to_s
|
@@ -41,7 +48,10 @@ module Aruba
|
|
41
48
|
aruba.environment.append name, value
|
42
49
|
new_environment = aruba.environment.to_h
|
43
50
|
|
44
|
-
|
51
|
+
environment_change = { old: old_environment,
|
52
|
+
new: new_environment,
|
53
|
+
changed: { name: name, value: value } }
|
54
|
+
aruba.event_bus.notify Events::ChangedEnvironmentVariable.new(environment_change)
|
45
55
|
|
46
56
|
self
|
47
57
|
end
|
@@ -53,6 +63,8 @@ module Aruba
|
|
53
63
|
#
|
54
64
|
# @param [String] value
|
55
65
|
# The value of the environment variable. Needs to be a string.
|
66
|
+
#
|
67
|
+
# @return [self]
|
56
68
|
def prepend_environment_variable(name, value)
|
57
69
|
name = name.to_s
|
58
70
|
value = value.to_s
|
@@ -61,18 +73,20 @@ module Aruba
|
|
61
73
|
aruba.environment.prepend name, value
|
62
74
|
new_environment = aruba.environment.to_h
|
63
75
|
|
64
|
-
|
76
|
+
environment_change = { old: old_environment,
|
77
|
+
new: new_environment,
|
78
|
+
changed: { name: name, value: value } }
|
79
|
+
aruba.event_bus.notify Events::ChangedEnvironmentVariable.new(environment_change)
|
65
80
|
|
66
81
|
self
|
67
82
|
end
|
68
83
|
|
69
84
|
# Remove existing environment variable
|
70
85
|
#
|
71
|
-
# @param [String]
|
86
|
+
# @param [String] name
|
72
87
|
# The name of the environment variable as string, e.g. 'HOME'
|
73
88
|
#
|
74
|
-
# @
|
75
|
-
# The value of the environment variable. Needs to be a string.
|
89
|
+
# @return [self]
|
76
90
|
def delete_environment_variable(name)
|
77
91
|
name = name.to_s
|
78
92
|
|
@@ -80,7 +94,10 @@ module Aruba
|
|
80
94
|
aruba.environment.delete name
|
81
95
|
new_environment = aruba.environment.to_h
|
82
96
|
|
83
|
-
|
97
|
+
environment_change = { old: old_environment,
|
98
|
+
new: new_environment,
|
99
|
+
changed: { name: name, value: '' } }
|
100
|
+
aruba.event_bus.notify Events::ChangedEnvironmentVariable.new(environment_change)
|
84
101
|
|
85
102
|
self
|
86
103
|
end
|
data/lib/aruba/api/filesystem.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
require '
|
1
|
+
require 'pathname'
|
2
2
|
|
3
|
+
require 'aruba/platform'
|
3
4
|
require 'aruba/extensions/string/strip'
|
4
5
|
|
5
|
-
require 'aruba/aruba_path'
|
6
|
-
|
7
6
|
Aruba.platform.require_matching_files('../matchers/file/*.rb', __FILE__)
|
8
7
|
Aruba.platform.require_matching_files('../matchers/directory/*.rb', __FILE__)
|
9
8
|
Aruba.platform.require_matching_files('../matchers/path/*.rb', __FILE__)
|
@@ -40,8 +39,10 @@ module Aruba
|
|
40
39
|
|
41
40
|
# Check if file exist and is executable
|
42
41
|
#
|
43
|
-
# @param [String]
|
44
|
-
# The
|
42
|
+
# @param [String] path
|
43
|
+
# The path which should exist and be executable
|
44
|
+
#
|
45
|
+
# @return [Boolean]
|
45
46
|
def executable?(path)
|
46
47
|
path = expand_path(path)
|
47
48
|
|
@@ -50,18 +51,16 @@ module Aruba
|
|
50
51
|
|
51
52
|
# Check if path is absolute
|
52
53
|
#
|
53
|
-
# @return [
|
54
|
-
# Result of check
|
54
|
+
# @return [Boolean]
|
55
55
|
def absolute?(path)
|
56
|
-
|
56
|
+
Aruba.platform.absolute_path?(path)
|
57
57
|
end
|
58
58
|
|
59
59
|
# Check if path is relative
|
60
60
|
#
|
61
|
-
# @return [
|
62
|
-
# Result of check
|
61
|
+
# @return [Boolean]
|
63
62
|
def relative?(path)
|
64
|
-
|
63
|
+
Aruba.platform.relative_path?(path)
|
65
64
|
end
|
66
65
|
|
67
66
|
# Return all existing paths (directories, files) in current dir
|
@@ -69,7 +68,7 @@ module Aruba
|
|
69
68
|
# @return [Array]
|
70
69
|
# List of files and directories
|
71
70
|
def all_paths
|
72
|
-
list('.').map { |
|
71
|
+
list('.').map { |path| expand_path(path) }
|
73
72
|
end
|
74
73
|
|
75
74
|
# Return all existing files in current directory
|
@@ -93,7 +92,7 @@ module Aruba
|
|
93
92
|
# @return [Dir]
|
94
93
|
# The directory object
|
95
94
|
def directory(path)
|
96
|
-
|
95
|
+
raise ArgumentError, %(Path "#{name}" does not exist.) unless exist? name
|
97
96
|
|
98
97
|
Dir.new(expand_path(path))
|
99
98
|
end
|
@@ -103,22 +102,31 @@ module Aruba
|
|
103
102
|
# @return [Array]
|
104
103
|
# The content of directory
|
105
104
|
def list(name)
|
106
|
-
|
107
|
-
|
105
|
+
raise ArgumentError, %(Path "#{name}" does not exist.) unless exist? name
|
106
|
+
|
107
|
+
unless directory? name
|
108
|
+
raise ArgumentError,
|
109
|
+
%(Only directories are supported. Path "#{name}" is not a directory.)
|
110
|
+
end
|
108
111
|
|
109
112
|
existing_files = Dir.glob(expand_path(File.join(name, '**', '*')))
|
110
|
-
current_working_directory =
|
113
|
+
current_working_directory = Pathname.new(expand_path('.'))
|
111
114
|
|
112
|
-
existing_files.map
|
115
|
+
existing_files.map do |d|
|
116
|
+
Pathname.new(d).relative_path_from(current_working_directory).to_s
|
117
|
+
end
|
113
118
|
end
|
114
119
|
|
115
120
|
# Return content of file
|
116
121
|
#
|
117
122
|
# @return [Array]
|
118
|
-
# The content of file, without "\n" or "\r\n" at the end.
|
123
|
+
# The content of file, without "\n" or "\r\n" at the end.
|
124
|
+
# To rebuild the file use `content.join("\n")`
|
119
125
|
def read(name)
|
120
|
-
|
121
|
-
|
126
|
+
raise ArgumentError, %(Path "#{name}" does not exist.) unless exist? name
|
127
|
+
unless file? name
|
128
|
+
raise ArgumentError, %(Only files are supported. Path "#{name}" is not a file.)
|
129
|
+
end
|
122
130
|
|
123
131
|
File.readlines(expand_path(name)).map(&:chomp)
|
124
132
|
end
|
@@ -128,10 +136,10 @@ module Aruba
|
|
128
136
|
# The method does not check if file already exists. If the file name is a
|
129
137
|
# path the method will create all neccessary directories.
|
130
138
|
#
|
131
|
-
# @param [String]
|
139
|
+
# @param [String] name
|
132
140
|
# The name of the file
|
133
141
|
#
|
134
|
-
# @param [String]
|
142
|
+
# @param [String] content
|
135
143
|
# The content which should be written to the file
|
136
144
|
def write_file(name, content)
|
137
145
|
Aruba.platform.create_file(expand_path(name), content, false)
|
@@ -146,7 +154,7 @@ module Aruba
|
|
146
154
|
def touch(*args)
|
147
155
|
args = args.flatten
|
148
156
|
|
149
|
-
options = if args.last.
|
157
|
+
options = if args.last.is_a? Hash
|
150
158
|
args.pop
|
151
159
|
else
|
152
160
|
{}
|
@@ -169,9 +177,6 @@ module Aruba
|
|
169
177
|
# @param [String] destination
|
170
178
|
# A file or directory name. If multiple sources are given the destination
|
171
179
|
# needs to be a directory
|
172
|
-
#
|
173
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
174
|
-
# def copy(*source, destination)
|
175
180
|
def copy(*args)
|
176
181
|
args = args.flatten
|
177
182
|
destination = args.pop
|
@@ -181,8 +186,14 @@ module Aruba
|
|
181
186
|
raise ArgumentError, %(The following source "#{s}" does not exist.) unless exist? s
|
182
187
|
end
|
183
188
|
|
184
|
-
|
185
|
-
|
189
|
+
if destination.start_with? aruba.config.fixtures_path_prefix
|
190
|
+
raise ArgumentError,
|
191
|
+
"Using a fixture as destination (#{destination}) is not supported"
|
192
|
+
end
|
193
|
+
|
194
|
+
if source.count > 1 && exist?(destination) && !directory?(destination)
|
195
|
+
raise ArgumentError, 'Multiples sources can only be copied to a directory'
|
196
|
+
end
|
186
197
|
|
187
198
|
source_paths = source.map { |f| expand_path(f) }
|
188
199
|
destination_path = expand_path(destination)
|
@@ -198,7 +209,6 @@ module Aruba
|
|
198
209
|
|
199
210
|
self
|
200
211
|
end
|
201
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
202
212
|
|
203
213
|
# Move a file and/or directory
|
204
214
|
#
|
@@ -210,25 +220,29 @@ module Aruba
|
|
210
220
|
# @param [String] destination
|
211
221
|
# A file or directory name. If multiple sources are given the destination
|
212
222
|
# needs to be a directory
|
213
|
-
#
|
214
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
215
|
-
# rubocop:disable Metrics/MethodLength
|
216
223
|
def move(*args)
|
217
224
|
args = args.flatten
|
218
225
|
destination = args.pop
|
219
226
|
source = args
|
220
227
|
|
221
228
|
source.each do |s|
|
222
|
-
|
229
|
+
if s.start_with? aruba.config.fixtures_path_prefix
|
230
|
+
raise ArgumentError, "Using a fixture as source (#{source}) is not supported"
|
231
|
+
end
|
223
232
|
end
|
224
233
|
|
225
|
-
|
234
|
+
if destination.start_with? aruba.config.fixtures_path_prefix
|
235
|
+
raise ArgumentError,
|
236
|
+
"Using a fixture as destination (#{destination}) is not supported"
|
237
|
+
end
|
226
238
|
|
227
239
|
source.each do |s|
|
228
240
|
raise ArgumentError, %(The following source "#{s}" does not exist.) unless exist? s
|
229
241
|
end
|
230
242
|
|
231
|
-
|
243
|
+
if source.count > 1 && exist?(destination) && !directory?(destination)
|
244
|
+
raise ArgumentError, 'Multiple sources can only be copied to a directory'
|
245
|
+
end
|
232
246
|
|
233
247
|
source_paths = source.map { |f| expand_path(f) }
|
234
248
|
destination_path = expand_path(destination)
|
@@ -244,18 +258,16 @@ module Aruba
|
|
244
258
|
|
245
259
|
self
|
246
260
|
end
|
247
|
-
# rubocop:enable Metrics/MethodLength
|
248
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
249
261
|
|
250
262
|
# Create a file with the given size
|
251
263
|
#
|
252
264
|
# The method does not check if file already exists. If the file name is a
|
253
265
|
# path the method will create all neccessary directories.
|
254
266
|
#
|
255
|
-
# @param [String]
|
267
|
+
# @param [String] name
|
256
268
|
# The name of the file
|
257
269
|
#
|
258
|
-
# @param [Integer]
|
270
|
+
# @param [Integer] size
|
259
271
|
# The size of the file
|
260
272
|
def write_fixed_size_file(name, size)
|
261
273
|
Aruba.platform.create_fixed_size_file(expand_path(name), size, false)
|
@@ -284,21 +296,21 @@ module Aruba
|
|
284
296
|
def chmod(*args)
|
285
297
|
args = args.flatten
|
286
298
|
|
287
|
-
options = if args.last.
|
299
|
+
options = if args.last.is_a? Hash
|
288
300
|
args.pop
|
289
301
|
else
|
290
302
|
{}
|
291
303
|
end
|
292
304
|
|
293
305
|
mode = args.shift
|
294
|
-
mode = if mode.
|
306
|
+
mode = if mode.is_a? String
|
295
307
|
mode.to_i(8)
|
296
308
|
else
|
297
309
|
mode
|
298
310
|
end
|
299
311
|
|
300
|
-
args.each { |
|
301
|
-
paths = args.map { |
|
312
|
+
args.each { |path| raise "Expected #{path} to be present" unless exist?(path) }
|
313
|
+
paths = args.map { |path| expand_path(path) }
|
302
314
|
|
303
315
|
Aruba.platform.chmod(mode, paths, options)
|
304
316
|
|
@@ -336,13 +348,13 @@ module Aruba
|
|
336
348
|
def remove(*args)
|
337
349
|
args = args.flatten
|
338
350
|
|
339
|
-
options = if args.last.
|
351
|
+
options = if args.last.is_a? Hash
|
340
352
|
args.pop
|
341
353
|
else
|
342
354
|
{}
|
343
355
|
end
|
344
356
|
|
345
|
-
args = args.map { |
|
357
|
+
args = args.map { |path| expand_path(path) }
|
346
358
|
|
347
359
|
Aruba.platform.rm(args, options)
|
348
360
|
end
|
@@ -354,7 +366,7 @@ module Aruba
|
|
354
366
|
#
|
355
367
|
# @yield
|
356
368
|
# Pass the content of the given file to this block
|
357
|
-
def with_file_content(file
|
369
|
+
def with_file_content(file)
|
358
370
|
expect(file).to be_an_existing_path
|
359
371
|
|
360
372
|
content = read(file).join("\n")
|
@@ -370,31 +382,21 @@ module Aruba
|
|
370
382
|
# @param [Array, Path] paths
|
371
383
|
# The paths
|
372
384
|
#
|
373
|
-
# @
|
385
|
+
# @return [FileSize]
|
374
386
|
# Bytes on disk
|
375
|
-
|
376
387
|
def disk_usage(*paths)
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
# TODO: change the API so that you could set something like
|
381
|
-
# aruba.config.fs_allocation_unit_size directly
|
388
|
+
paths = paths.flatten
|
389
|
+
expect(paths).to Aruba::Matchers.all be_an_existing_path
|
390
|
+
expanded = paths.map { |path| expand_path(path) }
|
382
391
|
|
383
|
-
|
384
|
-
typical_dev_bsize = 512 # google dev_bsize for more info
|
385
|
-
|
386
|
-
block_multiplier = typical_fs_unit / typical_dev_bsize
|
387
|
-
fs_unit_size = aruba.config.physical_block_size * block_multiplier
|
388
|
-
|
389
|
-
# TODO: the size argument here is unnecessary - ArubaPath should decide
|
390
|
-
# what the disk usage of a file is (even if Aruba.config needs to be
|
391
|
-
# read)
|
392
|
-
deprecated_block_count = fs_unit_size / block_multiplier
|
393
|
-
Aruba.platform.determine_disk_usage(expanded, deprecated_block_count)
|
392
|
+
Aruba.platform.determine_disk_usage(expanded)
|
394
393
|
end
|
395
394
|
|
396
395
|
# Get size of file
|
397
396
|
#
|
397
|
+
# @param [String] name
|
398
|
+
# File name
|
399
|
+
#
|
398
400
|
# @return [Numeric]
|
399
401
|
# The size of the file
|
400
402
|
def file_size(name)
|
data/lib/aruba/api/text.rb
CHANGED
@@ -14,7 +14,14 @@ module Aruba
|
|
14
14
|
# @param [#to_s] text
|
15
15
|
# Input
|
16
16
|
def unescape_text(text)
|
17
|
-
text
|
17
|
+
text
|
18
|
+
.gsub('\n', "\n")
|
19
|
+
.gsub('\"', '"')
|
20
|
+
.gsub('\e', "\e")
|
21
|
+
.gsub('\033', "\e")
|
22
|
+
.gsub('\016', "\016")
|
23
|
+
.gsub('\017', "\017")
|
24
|
+
.gsub('\t', "\t")
|
18
25
|
end
|
19
26
|
|
20
27
|
# Remove ansi characters from text
|
@@ -22,11 +29,10 @@ module Aruba
|
|
22
29
|
# @param [#to_s] text
|
23
30
|
# Input
|
24
31
|
def extract_text(text)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
32
|
+
text
|
33
|
+
.gsub(/(?:\e|\033)\[\d+(?>(;\d+)*)m/, '')
|
34
|
+
.gsub(/\\\[|\\\]/, '')
|
35
|
+
.gsub(/\007|\016|\017/, '')
|
30
36
|
end
|
31
37
|
|
32
38
|
# Unescape special characters and remove ANSI characters
|
@@ -35,19 +41,19 @@ module Aruba
|
|
35
41
|
# The text to sanitize
|
36
42
|
def sanitize_text(text)
|
37
43
|
text = unescape_text(text)
|
38
|
-
text = extract_text(text) if
|
44
|
+
text = extract_text(text) if aruba.config.remove_ansi_escape_sequences
|
39
45
|
|
40
46
|
text.chomp
|
41
47
|
end
|
42
48
|
|
43
|
-
#
|
44
|
-
#
|
45
|
-
# Replace variables in command string
|
49
|
+
# Replace variables in command string (experimental)
|
46
50
|
#
|
47
51
|
# @param [#to_s] text
|
48
52
|
# The text to parse
|
49
53
|
def replace_variables(text)
|
50
|
-
|
54
|
+
if text.include? '<pid-last-command-started>'
|
55
|
+
text = text.gsub(/<pid-last-command-started>/, last_command_started.pid.to_s)
|
56
|
+
end
|
51
57
|
|
52
58
|
text
|
53
59
|
end
|
data/lib/aruba/aruba_path.rb
CHANGED
@@ -1,30 +1,21 @@
|
|
1
1
|
require 'pathname'
|
2
|
-
require 'delegate'
|
3
|
-
|
4
|
-
require 'aruba/file_size'
|
5
2
|
|
6
3
|
# Aruba
|
7
4
|
module Aruba
|
8
5
|
# Pathname for aruba files and directories
|
9
6
|
#
|
10
7
|
# @private
|
11
|
-
class ArubaPath
|
8
|
+
class ArubaPath
|
12
9
|
def initialize(path)
|
13
|
-
obj = [path.to_s].flatten
|
14
|
-
|
15
|
-
super obj
|
16
|
-
|
17
|
-
@delegate_sd_obj = obj
|
10
|
+
@obj = [path.to_s].flatten
|
18
11
|
end
|
19
12
|
|
20
|
-
|
21
|
-
|
22
|
-
::Pathname.new(::File.join(*@delegate_sd_obj))
|
13
|
+
def to_str
|
14
|
+
to_pathname.to_s
|
23
15
|
end
|
24
16
|
|
25
|
-
|
26
|
-
|
27
|
-
@delegate_sd_obj = [obj.to_s].flatten
|
17
|
+
def to_s
|
18
|
+
to_str
|
28
19
|
end
|
29
20
|
|
30
21
|
# Add directory/file to path
|
@@ -39,49 +30,19 @@ module Aruba
|
|
39
30
|
# puts path
|
40
31
|
# # => path/to/dir.d/subdir.d
|
41
32
|
def push(p)
|
42
|
-
@
|
33
|
+
@obj << p
|
43
34
|
end
|
44
35
|
alias << push
|
45
36
|
|
46
|
-
# Remove last component of path
|
37
|
+
# Remove last pushed component of path
|
47
38
|
#
|
48
39
|
# @example
|
49
|
-
# path = ArubaPath.new 'path/to
|
40
|
+
# path = ArubaPath.new 'path/to'
|
41
|
+
# path.push 'dir'
|
50
42
|
# path.pop
|
51
|
-
# puts path
|
52
|
-
# # => path/to
|
43
|
+
# puts path # => path/to
|
53
44
|
def pop
|
54
|
-
@
|
55
|
-
end
|
56
|
-
|
57
|
-
# How many parts has the file name
|
58
|
-
#
|
59
|
-
# @return [Integer]
|
60
|
-
# The count of file name parts
|
61
|
-
#
|
62
|
-
# @example
|
63
|
-
#
|
64
|
-
# path = ArubaPath.new('path/to/file.txt')
|
65
|
-
# path.depth # => 3
|
66
|
-
#
|
67
|
-
def depth
|
68
|
-
__getobj__.each_filename.to_a.size
|
69
|
-
end
|
70
|
-
|
71
|
-
# Path ends with string
|
72
|
-
#
|
73
|
-
# @param [String] string
|
74
|
-
# The string to check
|
75
|
-
def end_with?(string)
|
76
|
-
to_s.end_with? string
|
77
|
-
end
|
78
|
-
|
79
|
-
# Path starts with string
|
80
|
-
#
|
81
|
-
# @param [String] string
|
82
|
-
# The string to check
|
83
|
-
def start_with?(string)
|
84
|
-
to_s.start_with? string
|
45
|
+
@obj.pop
|
85
46
|
end
|
86
47
|
|
87
48
|
# Return string at index
|
@@ -91,67 +52,20 @@ module Aruba
|
|
91
52
|
to_s[index]
|
92
53
|
end
|
93
54
|
|
94
|
-
|
95
|
-
#
|
96
|
-
# This reports the amount of blocks which are allocated by the path.
|
97
|
-
#
|
98
|
-
# @return [Integer]
|
99
|
-
# The count of blocks on disk
|
100
|
-
#
|
101
|
-
# @deprecated
|
102
|
-
def blocks
|
103
|
-
min_bytes_used = minimum_disk_space_used
|
104
|
-
min_bytes_used / Aruba.config.physical_block_size
|
105
|
-
end
|
55
|
+
private
|
106
56
|
|
107
|
-
#
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
#
|
120
|
-
# (The "magic" 512 bye implied makes the value of "blocks" so confusing).
|
121
|
-
#
|
122
|
-
# Currently Aruba allows you to set what's called the `physical_block_size`,
|
123
|
-
# which is a bit misleading - it's the "512" value. So if you somehow have a
|
124
|
-
# "filesystem unit size" of 8192 (instead of a typical 4KB), set the
|
125
|
-
# `physical_block_size` to 1024 (yes, divide by 8: 8192/8 = 1024).
|
126
|
-
#
|
127
|
-
# Ideally, Aruba should provide e.g. `Aruba.config.fs_allocation_unit`
|
128
|
-
# (with 4096 as the default), so you wouldn't have to "divide by 8".
|
129
|
-
#
|
130
|
-
# (typical_fs_unit / typical_dev_bsize = 4096 / 512 = 8)
|
131
|
-
#
|
132
|
-
#
|
133
|
-
# @return [Integer]
|
134
|
-
# Total bytes allocate
|
135
|
-
#
|
136
|
-
# TODO: this is recommended over the above "blocks"
|
137
|
-
def minimum_disk_space_used
|
138
|
-
# TODO: replace Aruba.config.physical_block_size
|
139
|
-
# with something like Aruba.config.fs_allocation_unit
|
140
|
-
dev_bsize = Aruba.config.physical_block_size
|
141
|
-
|
142
|
-
stat = File::Stat.new(to_s)
|
143
|
-
|
144
|
-
blocks = stat.blocks
|
145
|
-
return (blocks * dev_bsize) if blocks
|
146
|
-
|
147
|
-
typical_fs_unit = 4096
|
148
|
-
typical_dev_bsize = 512 # google dev_bsize for more info
|
149
|
-
|
150
|
-
block_multiplier = typical_fs_unit / typical_dev_bsize
|
151
|
-
fs_unit_size = dev_bsize * block_multiplier
|
152
|
-
fs_units = (stat.size + fs_unit_size - 1) / fs_unit_size
|
153
|
-
fs_units = 1 if fs_units.zero?
|
154
|
-
fs_units * fs_unit_size
|
57
|
+
# Get path
|
58
|
+
def to_pathname
|
59
|
+
current_path = @obj.inject do |path, element|
|
60
|
+
if element.start_with? '~'
|
61
|
+
element
|
62
|
+
elsif Aruba.platform.absolute_path? element
|
63
|
+
element
|
64
|
+
else
|
65
|
+
File.join(path, element)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
::Pathname.new(current_path)
|
155
69
|
end
|
156
70
|
end
|
157
71
|
end
|