-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.rb
executable file
·89 lines (71 loc) · 2.06 KB
/
util.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env ruby
#
# Author: [email protected]
require 'mail'
require 'open3'
class Util
def self.mail_and_copy(config, files, report_name)
desc = "#{report_name} Report for " +
"#{config[:report_qtr]}/#{config[:report_year]} - " +
"#{config[:start]} to #{config[:end]}"
mail = Mail.new do
from config[:mailfrom]
to config[:mailto]
subject desc
body desc
end
files.each do |file|
mail.add_file(file)
end
mail.delivery_method :sendmail
mail.deliver!
if Dir.exist?(config[:output_dir])
FileUtils.cp(files, config[:output_dir])
end
end
def self.do_cmd(cmd)
output, status = Open3.capture2e(cmd)
success = status.exitstatus.zero?
raise "#{cmd} exited unsuccessfully: #{output}" if !success
end
def self.commify(number)
number.to_s.reverse.gsub(/(\d+\.)?(\d{3})(?=\d)/, '\\1\\2,').reverse
end
def self.parse_report(report_file)
totals = Hash.new
totals[:all] = {
:size => 0,
:num_files => 0,
:provider => 'all',
:collection => 'all'
}
File.open(report_file).each do |line|
next if line =~ /DATESTAMP/
#puts line
path, oxum = line.split(':Arbitrary-Oxum: ')
#puts path
#puts oxum
provider, collection = path.split('/').slice(1,2)
#puts provider
#puts collection
size, num_files = oxum.split('.')
#puts size
#puts num_files
key = "#{provider}/#{collection}".to_sym
#puts "key #{key}"
if !totals.key?(key)
totals[key] = {
:size => 0,
:num_files => 0,
:provider => provider,
:collection => collection
}
end
totals[key][:size] += size.to_i
totals[key][:num_files] += num_files.to_i
totals[:all][:size] += size.to_i
totals[:all][:num_files] += num_files.to_i
end
return totals
end
end