2016-08-20 06:41:37 +00:00
|
|
|
module HomeHelper
|
2016-09-24 09:00:27 +00:00
|
|
|
|
2016-09-24 16:24:28 +00:00
|
|
|
def get_du(dir)
|
|
|
|
du = Array.new
|
|
|
|
du_each = Hash.new
|
|
|
|
command = String.new
|
2016-09-26 09:06:53 +00:00
|
|
|
avail = 0.0
|
2016-09-24 16:24:28 +00:00
|
|
|
if dir.eql? "/"
|
|
|
|
command = "sudo df /"
|
|
|
|
s = `#{command}`.split("\n")[1].split(" ")
|
|
|
|
avail = s[2].to_f + s[3].to_f
|
|
|
|
else
|
|
|
|
command << "sudo du -s #{dir}"
|
2016-09-26 09:06:53 +00:00
|
|
|
begin
|
|
|
|
avail = `#{command}`.split(" ")[0].to_f
|
|
|
|
rescue
|
|
|
|
# some directory is not connected
|
|
|
|
avail = `#{command}`.split(" ")[1].to_f
|
|
|
|
end
|
2016-09-24 16:24:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
command << "sudo du -s #{dir}/*"
|
|
|
|
puts command
|
|
|
|
output = `#{command}`.split("\n")
|
|
|
|
output.each do |t|
|
2016-09-26 09:06:53 +00:00
|
|
|
begin
|
|
|
|
du_each['usage'] = t.split(" ")[0].to_f / avail
|
|
|
|
du_each['file_name'] = t.split(" ")[1].split("/").last
|
|
|
|
du << du_each
|
|
|
|
du_each = Hash.new
|
|
|
|
rescue
|
|
|
|
# directory is not connected
|
|
|
|
du_each['usage'] = 0.0
|
|
|
|
du_each['file_name'] = t.split(" ")[1].split("/").last.split("'")[0]
|
|
|
|
du << du_each
|
|
|
|
du_each = Hash.new
|
|
|
|
end
|
2016-09-24 16:24:28 +00:00
|
|
|
end
|
|
|
|
return du
|
|
|
|
end
|
|
|
|
|
2016-08-20 06:41:37 +00:00
|
|
|
end
|