From 42b9d6b53bed12c16d25d0152facd7fd2ec05d4e Mon Sep 17 00:00:00 2001 From: Kasun Thennakoon Date: Thu, 26 Jun 2014 16:59:05 +0530 Subject: [PATCH] clear unsued libraries --- app/models/disk.rb | 2 - app/views/disk_wizards/confirmation.html.erb | 2 +- app/views/layouts/basic.html.erb | 31 ----- app/views/layouts/disk_wizard.html.erb | 101 -------------- app/views/shared/footer.html.erb | 3 - app/views/shared/header.html.erb | 88 ------------- app/views/welcome/index.html.erb | 9 -- lib/command.rb | 75 ----------- lib/disk_tools.rb | 7 - lib/disk_tools/disk_utils.rb | 131 ------------------- lib/disk_wizards.rb | 1 + lib/{disk_tools => }/fstab.rb | 0 lib/parted.rb | 111 ---------------- 13 files changed, 2 insertions(+), 559 deletions(-) delete mode 100755 app/views/layouts/basic.html.erb delete mode 100755 app/views/layouts/disk_wizard.html.erb delete mode 100644 app/views/shared/footer.html.erb delete mode 100644 app/views/shared/header.html.erb delete mode 100755 app/views/welcome/index.html.erb delete mode 100755 lib/command.rb delete mode 100755 lib/disk_tools.rb delete mode 100755 lib/disk_tools/disk_utils.rb rename lib/{disk_tools => }/fstab.rb (100%) mode change 100755 => 100644 delete mode 100755 lib/parted.rb diff --git a/app/models/disk.rb b/app/models/disk.rb index 900fa54..5548d27 100755 --- a/app/models/disk.rb +++ b/app/models/disk.rb @@ -2,8 +2,6 @@ # inheriting ActiveRecord::Base is not necessary class Disk #< ActiveRecord::Base - require "disk_tools" - attr_reader :model, :size, :rm attr_accessor :kname, :partitions diff --git a/app/views/disk_wizards/confirmation.html.erb b/app/views/disk_wizards/confirmation.html.erb index 4890eb8..6bd4569 100755 --- a/app/views/disk_wizards/confirmation.html.erb +++ b/app/views/disk_wizards/confirmation.html.erb @@ -56,7 +56,7 @@ - <%= button_tag(type: "submit", class: "btn btn-success",data: { confirm: "Are you sure?" }) do %> + <%= button_tag(type: "submit", class: "btn btn-success") do %> Apply <% end %> diff --git a/app/views/layouts/basic.html.erb b/app/views/layouts/basic.html.erb deleted file mode 100755 index 8d16d7c..0000000 --- a/app/views/layouts/basic.html.erb +++ /dev/null @@ -1,31 +0,0 @@ - - - - - <%= @page_title ||= 'Amahi Disk Wizad' %> - - <%= stylesheet_link_tag "application", media: "all" %> - <%= stylesheet_link_tag "basic", media: "all" %> - - <%= javascript_include_tag "//www.google.com/jsapi", "chartkick" %> - <%= javascript_include_tag "application"%> - - <%= favicon_link_tag "fav/favicon.ico"%> - <%= csrf_meta_tag %> - - - - - <%= render "shared/header" %> - -
- - <%= yield %> - -
- - <%= render "shared/footer" %> - - - diff --git a/app/views/layouts/disk_wizard.html.erb b/app/views/layouts/disk_wizard.html.erb deleted file mode 100755 index ebfebfa..0000000 --- a/app/views/layouts/disk_wizard.html.erb +++ /dev/null @@ -1,101 +0,0 @@ - - - - - <%= @page_title ||= 'Amahi Disk Wizard' %> - - <%= stylesheet_link_tag "application", media: "all" %> - <%= stylesheet_link_tag "basic", media: "all" %> - <%= stylesheet_link_tag "bootstrap", media: "all" %> - <%= stylesheet_link_tag "bootstrap-theme", media: "all" %> - - <%= javascript_include_tag "//www.google.com/jsapi", "chartkick" %> - <%= javascript_include_tag "application"%> - <%= javascript_include_tag "bootstrap"%> - <%= javascript_include_tag "bootstrap-contextmenu"%> - <%= javascript_include_tag "disks"%> - - <%= favicon_link_tag "fav/favicon.ico"%> - <%= csrf_meta_tag %> - - - - - - <%= - #render "shared/header" -%> - -
- -
-
-
- -
- - <% if flash[:error] %> -
-
- - Warning! <%= flash[:error] %> -
-
- <% flash[:error] = nil %> - <% end %> - <% if flash[:success] %> -
-
- - <%= flash[:success] %> -
-
- <% flash[:success] = nil %> - <% end %> - <%= yield %> - -
-
-
- -
- - <% render "shared/footer" %> - - - - diff --git a/app/views/shared/footer.html.erb b/app/views/shared/footer.html.erb deleted file mode 100644 index af0b85e..0000000 --- a/app/views/shared/footer.html.erb +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/app/views/shared/header.html.erb b/app/views/shared/header.html.erb deleted file mode 100644 index 70922ad..0000000 --- a/app/views/shared/header.html.erb +++ /dev/null @@ -1,88 +0,0 @@ - - - <%= @page_title ||= 'Amahi Disk Wizard' %> - - <%= stylesheet_link_tag "application", media: "all" %> - <%= stylesheet_link_tag "basic", media: "all" %> - <%= stylesheet_link_tag "bootstrap", media: "all" %> - <%= stylesheet_link_tag "bootstrap-theme", media: "all" %> - - <%= javascript_include_tag "//www.google.com/jsapi", "chartkick" %> - <%= javascript_include_tag "application"%> - <%= javascript_include_tag "bootstrap"%> - <%= javascript_include_tag "bootstrap-contextmenu"%> - <%= javascript_include_tag "disks"%> - - <%= favicon_link_tag "fav/favicon.ico"%> - <%= csrf_meta_tag %> - - - - -
-
-
- -
- - <% if flash[:error] %> -
-
- - Warning! <%= flash[:error] %> -
-
- <% flash[:error] = nil %> - <% end %> - <% if flash[:success] %> -
-
- - <%= flash[:success] %> -
-
- <% flash[:success] = nil %> - <% end %> diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb deleted file mode 100755 index 249fe29..0000000 --- a/app/views/welcome/index.html.erb +++ /dev/null @@ -1,9 +0,0 @@ -
-

Amahi Disk Wizard

-

- Disk wizard provides a hassle free process for mounting, partitioning, formatting of newly attached storage devices to the HDA. Users are few clicks away from getting their devices ready to work with the system.It reduces the previous complexcity of the task. -

-

- <%= link_to "Try New Disk Wizard", select_path, class: "btn btn-primary btn-lg", "role" => "button" %> -

-
\ No newline at end of file diff --git a/lib/command.rb b/lib/command.rb deleted file mode 100755 index 98b7f5e..0000000 --- a/lib/command.rb +++ /dev/null @@ -1,75 +0,0 @@ -# Amahi Home Server -# Copyright (C) 2007-2013 Amahi -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License v3 -# (29 June 2007), as published in the COPYING file. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# file COPYING for more details. -# -# You should have received a copy of the GNU General Public -# License along with this program; if not, write to the Amahi -# team at http://www.amahi.org/ under "Contact Us." -require 'socket' -class Command - CMD_FIFO = "/var/run/hda-ctl/notify" - HDACTL_PID = "/var/run/hda-ctl.pid" - - @cmd = [] - - def initialize(cmd = nil) - @cmd = cmd ? [cmd] : [] - #@dummy_mode = Yettings.dummy_mode - end - - def execute - return if @dummy_mode - puts "EXECUTING: #{@cmd.join "\n"}" if @debug - raise "hda-ctl does not appear to be running!" unless running? - command = @cmd.join "\n" - f = UNIXSocket.open(CMD_FIFO) - f.send(command, 0) - f.close - @cmd = [] - end - - def run_now - raise "hda-ctl does not appear to be running!" unless running? - confirm = "done" # Digest::SHA1.hexdigest(Time.now.to_s.split(//).sort_by {rand}.join) - @cmd.push "confirm: #{confirm}\n" - command = @cmd.join "\n" - f = UNIXSocket.open(CMD_FIFO) - f.send(command, 0) - f.flush - begin - r = f.read; - r.strip! - end until r == confirm or f.eof - raise "error run_now - did not get confirmation of command completion." unless r == confirm - f.close - @cmd = [] - end - - def submit(command) - # FIXME - check for allowed commands? - # here and perhaps in the daemon. - @cmd.push command - end - -private - def running? - begin - f = File.open HDACTL_PID - s = f.readline - f.close - s.chomp! - File.exists?("/proc/#{s}") ? true : false - rescue - false - end - end - -end diff --git a/lib/disk_tools.rb b/lib/disk_tools.rb deleted file mode 100755 index 7fbaf4d..0000000 --- a/lib/disk_tools.rb +++ /dev/null @@ -1,7 +0,0 @@ -module Wizard - class Lib - require "disk_tools/disk_utils" - require "disk_tools/fstab" - end -end - diff --git a/lib/disk_tools/disk_utils.rb b/lib/disk_tools/disk_utils.rb deleted file mode 100755 index 5eef348..0000000 --- a/lib/disk_tools/disk_utils.rb +++ /dev/null @@ -1,131 +0,0 @@ -# Amahi Home Server -# Copyright (C) 2007-2013 Amahi -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License v3 -# (29 June 2007), as published in the COPYING file. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# file COPYING for more details. -# -# You should have received a copy of the GNU General Public -# License along with this program; if not, write to the Amahi -# team at http://www.amahi.org/ under "Contact Us." -class DiskUtils - class << self - def mounts - s = `df -BK`.split( /\r?\n/ )[1..-1] || ["","Incorrect data returned"] - - mount = [] - res = [] - s.each do |line| - word = line.split(/\s+/) - mount.push(word) - end - mount.each do |key| - d = {} - d[:filesystem] = key[0] - d[:bytes] = key[1].to_i * 1024 - d[:used] = key[2].to_i * 1024 - d[:available] = key[3].to_i * 1024 - d[:use_percent] = key[4] - d[:mount] = key[5] - res.push(d) unless ['tmpfs', 'devtmpfs'].include? d[:filesystem] - end - res.sort { |x,y| x[:filesystem] <=> y[:filesystem] } - end - - def get_attached_disks - disks = [] - disk = nil - - lsblk_result = `lsblk -b -P -o MODEL,TYPE,SIZE,KNAME,MOUNTPOINT,FSTYPE`.each_line - - lsblk_result.each do |line| - data_hash = {} - line_data = line.gsub!(/"(.*?)"/,'\1,').split "," - line_data.pop - for data in line_data - data.strip! - key_value_pair = data.split "=" - data_hash[key_value_pair[0]] = key_value_pair[1] - end - - blkid_result = `df -T /dev/#{data_hash['KNAME']}`.lines.pop - blkid_result.gsub!(/"/, '') - blkid_data = blkid_result.split(" ") if not blkid_result.empty? - data_hash['FSTYPE'] = blkid_data[1] unless data_hash['FSTYPE'] and blkid_data - - if data_hash['TYPE'] == "disk" - unless disk.nil? - disks.push disk - disk = nil # cleanup the variable - end - disk = data_hash - puts "DEBUG:***************{/dev/#{disk['KNAME']}}" - disk['removable'] = is_removable? "/dev/#{disk['KNAME']}" - next - end - if data_hash['TYPE'] == "part" - disk["partitions"].nil? ? disk["partitions"] = [data_hash] : disk["partitions"].push(data_hash) - end - end - disks.push disk - return disks - - end - - def find path - puts "***DEBUG path = #{path}" - path_info = `lsblk #{path} -b -P -o MODEL,TYPE,SIZE,KNAME,MOUNTPOINT,FSTYPE`.lines[0].gsub!(/"(.*?)"/,'\1,').split(',') - puts "***DEBUG path_info = #{path_info}" - data_hash = {} - path_info.pop - for data in path_info - data.strip! - key_value_pair = data.split "=" - data_hash[key_value_pair[0]] = key_value_pair[1] - end - puts "***DEBUG data_hash = #{data_hash}" - blkid_result = `df -T #{path}`.lines.pop - blkid_result.gsub!(/"/, '') - puts "***DEBUG blkid_result = #{blkid_result}" - blkid_data = blkid_result.split(" ") if not blkid_result.empty? - data_hash['FSTYPE'] = blkid_data[1] unless data_hash['FSTYPE'] and blkid_data - puts "***DEBUG data_hash = #{data_hash}" - if data_hash['TYPE'] == "disk" - disk = data_hash - puts "/dev/#{disk['KNAME']}" - disk['removable'] = is_removable? "/dev/#{disk['KNAME']}" - end - if data_hash['TYPE'] == "part" - disk = data_hash - disk['BYTES_FREE'] = blkid_data[4] - disk['BYTES_USED'] = blkid_data[3] - end - puts disk - return disk - - end - - def removables - removables = [] - devices_by_id = Pathname.new "/dev/disk/by-id/" - devices_by_id.each_child do |sym_link| - # puts "DEBUG:****************sym_link #{sym_link.class}" - # TODO push disk object insted of device_abs_path string - removables.push sym_link.realpath.to_s if sym_link.to_s =~ /\/usb-*/ rescue next - end - #return array of Filename objects which contents path to removable revices - return removables - end - - def is_removable? device - puts "DEBUG: ************************* #{removables}" - return removables.include? device - end - - end -end diff --git a/lib/disk_wizards.rb b/lib/disk_wizards.rb index fa37202..c1621c4 100755 --- a/lib/disk_wizards.rb +++ b/lib/disk_wizards.rb @@ -4,6 +4,7 @@ require "disk_command.rb" require "diskwz.rb" require "debug_logger.rb" +require "fstab.rb" module DiskWizard class Lib # the code for your plugin library here diff --git a/lib/disk_tools/fstab.rb b/lib/fstab.rb old mode 100755 new mode 100644 similarity index 100% rename from lib/disk_tools/fstab.rb rename to lib/fstab.rb diff --git a/lib/parted.rb b/lib/parted.rb deleted file mode 100755 index 028a209..0000000 --- a/lib/parted.rb +++ /dev/null @@ -1,111 +0,0 @@ -# Amahi Home Server -# Copyright (C) 2007-2013 Amahi -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License v3 -# (29 June 2007), as published in the COPYING file. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# file COPYING for more details. -# -# You should have received a copy of the GNU General Public -# License along with this program; if not, write to the Amahi -# team at http://www.amahi.org/ under "Contact Us." - - -class Parted - - def initialize disk - puts "DEBUG:********** initialize Parted disk = #{disk}" - if disk =~ /(\/\w+\/).+/ - @kname = disk.split('/')[-1] - else - @kname = disk - end - @path = Disk.path @kname - puts "DEBUG:********** initialize Parted path = #{@path}" - end - - def partition_table - puts "DEBUG:************************* partition_table = #{@path}" - command = "parted --script #{@path} print" - puts "DEBUG:************************* partition_table.command = #{command}" - result = disk_command command - puts "DEBUG:************************* partition_table.result = #{result}" - result.each_line do |line| - if line.strip =~ /^Error:/ - puts "DEBUG:************no disk line = #{line}" - return false - elsif line.strip =~ /^Partition Table:/ - #TODO: Need to test for all the types of partition tables - table_type = line.match(/^Partition Table:(.*)/i).captures[0].strip - puts "DEBUG:************line#{table_type}" - return table_type - end - end - end - - def format fs_type - #Creating new filesystem also format the partition with new FS type - return self.create_fs fs_type - end - - def create_partition_table type = 'msdos' - command = "parted --script #{@path} mklabel #{type}" - puts "DEBUG:************************************ create_partition_table.command = #{command}" - result = disk_command command - result.each_line do |line| - if line.strip =~ /^Error:/ - puts "DEBUG:************no disk line#{line}" - return false - end - end - return true - end - - def create_fs fs_type - partition_table = self.partition_table - unless partition_table - self.create_partition_table - command = "parted -s -a optimal #{@path} mkpart primary 1 -- -1" - disk_command(command) - @kname = @kname + 1.to_s - @path = "/dev/#{@kname}" - end - - #can't use parted 'mkfs' command because after version 2.4, the following commands were removed: check, cp, mkfs, mkpartfs, move, resize - fs_type = "vfat" if fs_type == "fat32" - command = "mkfs.#{fs_type} -q -F #{@path}" #-F parameter to ignore warning and -q for quiet execution - puts "DEBUG:************************************ create_fs.command = #{command}" - blocking = true - #TODO: Validation befor executing command , since none-blocking call returns nil result - result = disk_command(command , !blocking) # none-blocking call ,since formatting would take quit long time - puts "DEBUG:************************************ check for blank result result.blank?= #{result.blank?}" - puts "DEBUG:************************************ print result = #{result}" - return @kname if result.blank? # if everything went well result should be blank (in mkfs.* -q quite mode) - return false - end - - private - - def disk_command command, blocking = true - #forward the result(stdio and stderror) to temp file default location for temp file is /var/hda/tmp - puts "DEBUG:****************** disk_command.command = #{command} blocking = #{blocking}" - if blocking # default mode is blocking call, because other commands down the line depend on the result of the previous command(i.e. format after partitioning) - puts "DEBUG:****************** disk_command.full command => #{command} > /tmp/disk_wizard.tmp 2>&1" - Command.new("#{command} > /tmp/disk_wizard.tmp 2>&1").run_now #.execute is kind of none-blocking call and run_now is a blocking call - #TODO: Close opend file,rescue on no file, clear the file after reading to prevent dirty reads - result = File.open("/tmp/disk_wizard.tmp", "r").read - puts "DEBUG:************************************* result = #{result}" - else - puts "DEBUG:####### checkup disk_command.else " - Command.new("#{command} > /tmp/disk_wizard.tmp 2>&1").execute - result = nil - end - puts "DEBUG:************************************* result = #{result}" - return result - end - -end \ No newline at end of file