-
Notifications
You must be signed in to change notification settings - Fork 2
/
task.rb
executable file
·68 lines (58 loc) · 1.66 KB
/
task.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env ruby
require 'find'
require 'fileutils'
def fill_test_files
extensions = {
".mp3" => (1000..100000),
".m4a" => (1000..100000),
".jpg" => (1000..100000),
".png" => (1000..100000),
".md" => (100..1000),
".html" => (100..1000),
".rb" => (100..1000),
".txt" => (100..1000),
".erb" => (100..1000),
".csv" => (100..1000),
".log" => (100..1000),
"" => (100..1000)
}
def fill(stuff, size)
out = ""
while out.size < size
out << "Ta nah nah nah nah, Another one bytes the dust\n"
end
out
end
Find.find('test-data') do |file|
unless File.directory?(file) || file =~ /DS_Store/
ext = File.extname(file).downcase
size = rand(extensions[ext])
data = fill("dummy data", size)
puts "Writing #{data.size} bytes to #{file}"
File.write(file, data)
end
end
end
def generate_test_targets
Dir.chdir(File.join(File.dirname(__FILE__), 'test-data'))
# Remove anoying .DS_Store files
Dir["*/**/.DS_Store"].each { |f| FileUtils.rm(f) }
`dirstats home > home.txt`
`dirstats empty > empty.txt`
`dirstats files-only > files-only.txt`
`dirstats symlinks-and-other-weird-stuff > symlinks-and-other-weird-stuff.txt`
`dirstats home --output-format json > home.json`
Dir.chdir "../"
end
tasks = {
"fill_test_files" => "Fills test files with random data.",
"generate_test_targets" => "Generate test targets by running the program on each test directory."
}
if tasks.keys.include?(ARGV.first)
self.send(ARGV.first)
else
puts "Available tasks are:"
tasks.each do |name, description|
puts " #{name.ljust(21)} #{description}"
end
end