class Pedophile::BigFiles

Constants

TMP_STRUCTURE_PATH
USE_MIME

Attributes

downloader[R]
files[R]
files_path[R]
full_path[R]

Public Class Methods

new(downloader) click to toggle source
# File lib/pedophile/big_files.rb, line 9
def initialize(downloader)
  @downloader = downloader
  @files = Array.new
end

Public Instance Methods

analyze() click to toggle source
# File lib/pedophile/big_files.rb, line 32
def analyze
  glob_path = "#{full_path}/**/**"
  puts "big files path #{full_path.to_s.cyan}"

  Dir.glob(glob_path) do |item|
    next if item == '.' or item == '..' or File.directory?(item)

    puts "analyze file #{item.to_s.yellow}"

    h = Hash.new
    h[:path] = item

    if USE_MIME
      mime = `file --mime #{item}`
      if mime =~ /(\w+\/\w+);/
        mime = $1
      else
        mime = nil
      end
      h[:mime] = mime
    end

    @files << h
  end

  save_analyzed
end
big_files_path=(path) click to toggle source
# File lib/pedophile/big_files.rb, line 27
def big_files_path=(path)
  @files_path = path
  @full_path = File.join(offline_path, path)
end
copy_folder(path) click to toggle source
# File lib/pedophile/big_files.rb, line 20
def copy_folder(path)
  puts "copying big files path #{path.to_s.cyan}"
  FileUtils.cp_r(path, offline_path)
  puts "done copying path #{path.to_s.cyan}"
  big_files_path = path
end
gsub_big_file(smaller_path) click to toggle source
# File lib/pedophile/big_files.rb, line 81
def gsub_big_file(smaller_path)
  puts "process big file #{smaller_path.to_s.green}"

  self.downloader.offline_tree.files.each do |f|
    if f[:inside]
      to_rename = f[:inside].select do |fi|
        fi[:path].index(smaller_path)
      end

      # TODO gsub path issue with html files inside
      to_rename.each do |fi|
        original_string = fi[:path]
        new_string = File.join(files_path, smaller_path)

        puts "rename big file #{original_string.to_s.blue} to #{new_string.to_s.green}"

        self.downloader.offline_tree.process_massive_gsub(original_string, new_string, true)
      end


    end
  end

end
load_analyzed() click to toggle source
# File lib/pedophile/big_files.rb, line 66
def load_analyzed
  @files = YAML.load_file(TMP_STRUCTURE_PATH)
end
offline_path() click to toggle source
# File lib/pedophile/big_files.rb, line 16
def offline_path
  self.downloader.wget.offline_path
end
save_analyzed() click to toggle source
# File lib/pedophile/big_files.rb, line 60
def save_analyzed
  f = File.new(TMP_STRUCTURE_PATH, "w")
  f.puts @files.to_yaml
  f.close
end