class Raykit::SourceImport

def copy

def copy
  if target.length.zero?
    puts "target has not been specified"
  else
    FileUtils.remove_dir(target) if Dir.exist?(target)
    count = 0
    source_names = []
    work = self["remote"].work_dir
    Dir.chdir(work) do
      cmd = Command.new("rake clean") if File.exist?("rakefile.rb")
      Dir.chdir(source) do
        source_names = Dir.glob(self["glob"])
      end
    end
    source_names.each do |source_name|
      source_file = "#{work}/#{source}/#{source_name}"
      target_name = "#{target}/#{source_name}"
      target_parent = File.dirname(target_name)
      FileUtils.mkdir_p(target_parent) unless Dir.exist?(target_parent)
      FileUtils.copy(source_file, target_name)
      count += 1
    end
    puts "        copied #{count} files to #{target}"
  end
end