/ Published in: Ruby
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
namespace :project do desc "clean log,upload file, and tar file" task :build => :environment do |t| if get_answer "You really want to clean logs?(yes or no)" puts "cleaning log......." Rake::Task["log:clear"].invoke puts "cleaning log.......done" else puts "skip cleaning log" end if get_answer "You really want to clean all temp file?(yes or no)" puts "cleaning tmp files....." Rake::Task["tmp:clear"].invoke puts "cleaning tmp files.....done" else puts "skip cleaning log" end # clean upload files if get_answer "You really want to clean all uploaded files?(yes or no)" puts "cleaning uploaded files....." path = File.join(RAILS_ROOT,"public","upload") puts path require 'find' Find.find(path) do |path| File.delete(path) if File.file? path end puts "cleaning uploaded files.....done" os =RUBY_PLATFORM if os.include?("mswin32") puts " tar doesn't support win32 platform" exit else puts "tar files......." filename = "#{File.basename(RAILS_ROOT)}.#{Time.now.to_i}.tar.gz" `cd #{RAILS_ROOT} && cd ../ && tar -zcvf ./#{filename} #{File.basename(RAILS_ROOT)}/` puts "tar files.......done" end else puts "skip clean uploaded files" end end def get_answer word answer='no' while true print word answer = STDIN.gets.chomp! break if %w[yes no].include? answer end if answer=="yes" true else false end end end