Changing Rake namespace to "debshots"
Let's group all debshots-related Rake tasks under a common namespace
This commit is contained in:
parent
3cd354f9c8
commit
019ff7c519
1 changed files with 26 additions and 24 deletions
|
|
@ -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
|
task :screenshots_to_paperclip => :environment do
|
||||||
Rails.logger = Logger.new(STDOUT)
|
Rails.logger = Logger.new(STDOUT)
|
||||||
Rails.logger.level = Logger::INFO
|
Rails.logger.level = Logger::INFO
|
||||||
#Rails.logger.level = Logger::DEBUG
|
#Rails.logger.level = Logger::DEBUG
|
||||||
|
|
||||||
base_path = Rails.root.join('public')
|
base_path = Rails.root.join('public')
|
||||||
|
|
||||||
Rails.logger.info "Iterating over screenshots"
|
Rails.logger.info "Iterating over screenshots"
|
||||||
Screenshot.all.each do |screenshot|
|
Screenshot.all.each do |screenshot|
|
||||||
path = File.join(base_path, screenshot.image_url(:large))
|
path = File.join(base_path, screenshot.image_url(:large))
|
||||||
Rails.logger.info "- #{screenshot.id} (package: #{screenshot.package.name}) (path: #{path})"
|
Rails.logger.info "- #{screenshot.id} (package: #{screenshot.package.name}) (path: #{path})"
|
||||||
|
|
||||||
# Check that the file actually exists
|
# Check that the file actually exists
|
||||||
unless File.file? path
|
unless File.file? path
|
||||||
Rails.logger.error "Screenshots not found at #{path}. Skipping."
|
Rails.logger.error "Screenshots not found at #{path}. Skipping."
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
# Has the screenshot been migrated already?
|
# Has the screenshot been migrated already?
|
||||||
if screenshot.image.exists?
|
if screenshot.image.exists?
|
||||||
Rails.logger.error "Screenshot already migrated. Skipping."
|
Rails.logger.error "Screenshot already migrated. Skipping."
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
File.open(path, 'rb') do |image_file|
|
File.open(path, 'rb') do |image_file|
|
||||||
screenshot.image = image_file
|
screenshot.image = image_file
|
||||||
screenshot.save
|
screenshot.save
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Loading…
Add table
Add a link
Reference in a new issue