From 019ff7c519a060bc686cb140fe57bddd09f2e9cb Mon Sep 17 00:00:00 2001 From: Christoph Haas Date: Mon, 27 Apr 2015 00:17:21 +0200 Subject: [PATCH] Changing Rake namespace to "debshots" Let's group all debshots-related Rake tasks under a common namespace --- lib/tasks/screenshots_to_paperclip.rake | 50 +++++++++++++------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/lib/tasks/screenshots_to_paperclip.rake b/lib/tasks/screenshots_to_paperclip.rake index 1daba4b..282b57b 100644 --- a/lib/tasks/screenshots_to_paperclip.rake +++ b/lib/tasks/screenshots_to_paperclip.rake @@ -1,32 +1,34 @@ -desc "Convert images from the original screenshots directory tree to paperclip-styled images" +namespace :debshots do + desc "Convert images from the original screenshots directory tree to paperclip-styled images" -task :screenshots_to_paperclip => :environment do - Rails.logger = Logger.new(STDOUT) - Rails.logger.level = Logger::INFO - #Rails.logger.level = Logger::DEBUG + task :screenshots_to_paperclip => :environment do + Rails.logger = Logger.new(STDOUT) + Rails.logger.level = Logger::INFO + #Rails.logger.level = Logger::DEBUG - base_path = Rails.root.join('public') + base_path = Rails.root.join('public') - Rails.logger.info "Iterating over screenshots" - Screenshot.all.each do |screenshot| - path = File.join(base_path, screenshot.image_url(:large)) - Rails.logger.info "- #{screenshot.id} (package: #{screenshot.package.name}) (path: #{path})" + Rails.logger.info "Iterating over screenshots" + Screenshot.all.each do |screenshot| + path = File.join(base_path, screenshot.image_url(:large)) + Rails.logger.info "- #{screenshot.id} (package: #{screenshot.package.name}) (path: #{path})" - # Check that the file actually exists - unless File.file? path - Rails.logger.error "Screenshots not found at #{path}. Skipping." - next - end + # Check that the file actually exists + unless File.file? path + Rails.logger.error "Screenshots not found at #{path}. Skipping." + next + end - # Has the screenshot been migrated already? - if screenshot.image.exists? - Rails.logger.error "Screenshot already migrated. Skipping." - next - end + # Has the screenshot been migrated already? + if screenshot.image.exists? + Rails.logger.error "Screenshot already migrated. Skipping." + next + end - File.open(path, 'rb') do |image_file| - screenshot.image = image_file - screenshot.save + File.open(path, 'rb') do |image_file| + screenshot.image = image_file + screenshot.save + end end end -end +end \ No newline at end of file