From 962f6ff8f7b52e3b7e876dfd83a77414461d693b Mon Sep 17 00:00:00 2001 From: kyg516 Date: Mon, 26 Sep 2016 18:06:53 +0900 Subject: [PATCH] Update --- app/helpers/application_helper.rb | 47 ++++++++++++++++++------------- app/helpers/home_helper.rb | 24 ++++++++++++---- app/views/home/index.html.erb | 18 ++++++------ 3 files changed, 56 insertions(+), 33 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 96ae91e..18cd461 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -9,15 +9,19 @@ module ApplicationHelper output = `#{command}`.split("\n") output.each do |t| next if t.equal? output.first - s = t.split(' ') - df_each['Filesystem'] = s[0] - df_each['Size'] = s[1] - df_each['Used'] = s[2] - df_each['Avail'] = s[3] - df_each['Use%'] = s[4] - df_each['Mounted on'] = s[5] - df << df_each - df_each = Hash.new + begin + s = t.split(' ') + df_each['Filesystem'] = s[0] + df_each['Size'] = s[1] + df_each['Used'] = s[2] + df_each['Avail'] = s[3] + df_each['Use%'] = s[4] + df_each['Mounted on'] = s[5] + df << df_each + df_each = Hash.new + rescue => ex + puts ex + end end return df end @@ -27,12 +31,10 @@ module ApplicationHelper volume = Hash.new node = Node.take df = get_df - # error check : node is nil if node.nil? return volumes end - command = String.new command << "sshpass -p#{node.user_password} ssh #{node.user_name}@#{node.host_ip} gluster volume info" puts command @@ -60,16 +62,23 @@ module ApplicationHelper def files(dir) files = Array.new file = Hash.new - output = `ls #{dir} -l`.split("\n") + command = String.new + command << "ls #{dir} -l" + puts command + output = `#{command}`.split("\n") output.each do |t| next if t.equal? output.first - s = t.split(" ") - file["auth"] = s[0] - file["size"] = s[4] - file["date"] = s[5] + " " + s[6] + " " + s[7] - file["name"] = s[8] - files << file - file = Hash.new + begin + s = t.split(" ") + file["auth"] = s[0] + file["size"] = s[4] + file["date"] = s[5] + " " + s[6] + " " + s[7] + file["name"] = s[8] + files << file + file = Hash.new + rescue => ex + puts ex + end end return files end diff --git a/app/helpers/home_helper.rb b/app/helpers/home_helper.rb index 99247fd..0b1e255 100644 --- a/app/helpers/home_helper.rb +++ b/app/helpers/home_helper.rb @@ -4,23 +4,37 @@ module HomeHelper du = Array.new du_each = Hash.new command = String.new + avail = 0.0 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}" - avail = `#{command}`.split(" ")[0].to_f + begin + avail = `#{command}`.split(" ")[0].to_f + rescue + # some directory is not connected + avail = `#{command}`.split(" ")[1].to_f + end end command << "sudo du -s #{dir}/*" puts command output = `#{command}`.split("\n") output.each do |t| - 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 + 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 end return du end diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index f06c8de..a359c8c 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -137,7 +137,7 @@ - + <%= @current_dir %> @@ -431,14 +431,6 @@ function change_directory(directory){ } - - - + + +