Return to Snippet

Revision: 7175
at July 11, 2008 13:43 by crazylion


Updated Code
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

Revision: 7174
at July 11, 2008 13:42 by crazylion


Updated Code
require 'active_record'
  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

Revision: 7173
at July 11, 2008 13:22 by crazylion


Initial Code
require 'active_record'
  namespace :project do
    desc "clean log,upload file, and tar file"
    task :build => :environment do |t| 
    	answer = "no"
	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

Initial URL

                                

Initial Description

                                

Initial Title
clean rails tmp file,log file and others file.then tar it!

Initial Tags
rails

Initial Language
Ruby