lib/nodes.rb in nodes-0.1.5 vs lib/nodes.rb in nodes-0.1.6

- old
+ new

@@ -1,13 +1,14 @@ +require 'find' + module Nodes - VERSION = "0.1.5" + VERSION = "0.1.6" - def self.init(dir=nil) - dir = Dir.pwd unless dir + def self.init(dir) puts "Init new point '#{File.basename(dir)}' in #{dir}" - src = "#{File.dirname(__FILE__)}/../.node" + src = "#{File.dirname(__FILE__)}/../.point" system("cp -r #{src} #{dir}") end def self.clone(name) puts "Clone from server point '#{name}'" @@ -15,23 +16,46 @@ return unless system("mkdir #{dir}") init dir get dir end - def self.put(dir=nil) - dir = Dir.pwd unless dir - system("cd #{dir} && #{dir}/.node/put") + def self.put(dir) + system("cd #{dir} && #{dir}/.point/put") end - def self.get(dir=nil) - dir = Dir.pwd unless dir - system("cd #{dir} && #{dir}/.node/get") + def self.get(dir) + system("cd #{dir} && #{dir}/.point/get") end - def self.del(dir=nil) - dir = Dir.pwd unless dir - return unless system("cd #{dir} && #{dir}/.node/del") - system("cd #{dir} && rm -rf #{dir}/.node") + def self.del(dir) + return unless system("cd #{dir} && #{dir}/.point/del") + system("cd #{dir} && rm -rf #{dir}/.point") + end + + def self.size(dir, hidden = false) + total_size = 0 + total_files = 0 + total_directories = 0 + Find.find(dir) do |path| + if FileTest.directory?(path) + total_directories += 1 + if File.basename(path)[0] == ?. + Find.prune # Don't look any further into this directory. + else + next + end + else + if hidden || File.basename(path)[0] != ?. + total_files += 1 + total_size += FileTest.size(path) +# print path+" -> " +# puts FileTest.size(path) + end + end + end + puts "size: #{total_size}" + puts "directories: #{total_directories}" + puts "files: #{total_files}" end def self.country ip require 'geoip' print ip \ No newline at end of file