-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
187 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,38 @@ | ||
require 'fileutils' | ||
|
||
# rubocop:disable Metrics/BlockLength | ||
namespace :picture_set do | ||
COMBINED_SUFFIX = '_combined.jpg'.freeze | ||
|
||
desc 'Combine all images into one' | ||
task :combine_images, [:path] => [:environment] do |_task, args| | ||
path = args[:path] | ||
path = Rails.root.join('public', 'picture_sets') if path.blank? | ||
puts "Using directory #{path}." | ||
Dir.chdir(path) do | ||
picture_sets = Dir.glob('*').select { |f| File.directory? f } | ||
picture_sets.each do |date| | ||
puts "Processing #{date}..." | ||
combine_images(date, path) | ||
end | ||
end | ||
desc 'Re-create collage images' | ||
task :recreate_collage_images, [:path] => [:environment] do |_task, args| | ||
PictureSet::PICTURE_PATH = args[:path] if args[:path].present? | ||
PictureSet.all.each { |ps| ps.combine_images(overwrite: true) } | ||
end | ||
|
||
desc 'Remove combined images. Necessary before running combine_images task again.' | ||
task :clean_combine_images, [:path] => [:environment] do |_task, args| | ||
path = args[:path] | ||
path = Rails.root.join('public', 'picture_sets') if path.blank? | ||
puts "Using directory #{path}." | ||
Dir.chdir(path) do | ||
picture_sets = Dir.glob('*').select { |f| File.directory? f } | ||
picture_sets.each do |date| | ||
Dir.chdir(File.join(path, date)) do | ||
FileUtils.rm("#{date}#{COMBINED_SUFFIX}", force: true) | ||
end | ||
end | ||
desc 'Re-create single polaroid images' | ||
task :recreate_polaroid_images, [:path] => [:environment] do |_task, args| | ||
PictureSet::PICTURE_PATH = args[:path] if args[:path].present? | ||
PictureSet.all.each do |ps| | ||
angle = Random.rand(355..365) | ||
(1..4).each { |num| ps.convert_to_polaroid(num, angle) } | ||
end | ||
end | ||
|
||
desc 'Copies all images into one directory (without the single polaroids)' | ||
task :copy, %i[path output] => [:environment] do |_task, args| | ||
path = args[:path] | ||
path = Rails.root.join('public', 'picture_sets') if path.blank? | ||
puts "Using directory #{path}." | ||
Dir.chdir(path) do | ||
picture_sets = Dir.glob('*').select { |f| File.directory?(f) && f != 'all' } | ||
picture_sets.each do |date| | ||
begin | ||
Syscall.execute("cp #{File.join(path, date, '*.jpg')} #{args[:output]}") | ||
Syscall.execute("cp #{File.join(path, date, '*.gif')} #{args[:output]}") | ||
rescue StandardError => e | ||
puts e | ||
end | ||
end | ||
end | ||
desc 'Re-create animated gifs' | ||
task :recreate_animations, [:path] => [:environment] do |_task, args| | ||
PictureSet::PICTURE_PATH = args[:path] if args[:path].present? | ||
PictureSet.all.each { |ps| ps.create_animation(overwrite: true) } | ||
end | ||
|
||
def combine_images(date, path) | ||
dir = File.join(path, date) | ||
return if File.exist?(File.join(dir, "#{date}#{COMBINED_SUFFIX}")) | ||
begin | ||
Syscall.execute("time montage -geometry '25%x25%+25+25<' -background '#{OPTS.background_color}' " \ | ||
"-title '#{OPTS.image_caption}' -font '#{OPTS.font}' -fill '#{OPTS.font_color}' " \ | ||
"-pointsize #{OPTS.combined_image_fontsize} -gravity 'Center' #{date}_*.jpg #{date}#{COMBINED_SUFFIX}", | ||
dir: dir) | ||
rescue StandardError => e | ||
puts "Can not process #{dir}: #{e}" | ||
desc 'Exports all images into a single directory (without the single polaroids)' | ||
task :export, %i[output path] => [:environment] do |_task, args| | ||
PictureSet::PICTURE_PATH = args[:path] if args[:path].present? | ||
puts "copying from #{PictureSet::PICTURE_PATH} to #{args[:output]}." | ||
PictureSet.all.each do |ps| | ||
Dir.chdir(ps.dir) do | ||
FileUtils.cp(ps.animation, args[:output]) | ||
FileUtils.cp(ps.pictures.map { |p| p[:full] }, args[:output]) | ||
end | ||
end | ||
end | ||
|
||
end | ||
# rubocop:enable Metrics/BlockLength |
Empty file.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe GpioPort, type: :model do | ||
|
||
before(:each) do | ||
PiPiper = Class.new | ||
PiPiper::Pin = double('PiPiper::Pin') | ||
end | ||
|
||
describe '#on' do | ||
|
||
it 'turns on pin' do | ||
pin = double | ||
expect(File).to receive(:open).with('/sys/class/gpio/unexport', 'w') | ||
expect(PiPiper::Pin).to receive(:new).with(pin: 5, direction: :out).and_return(pin) | ||
expect(pin).to receive(:on) | ||
GpioPort.on(5) | ||
end | ||
|
||
end | ||
|
||
describe '#off' do | ||
|
||
it 'turns off pin' do | ||
pin = double | ||
expect(File).to receive(:open).with('/sys/class/gpio/unexport', 'w') | ||
expect(PiPiper::Pin).to receive(:new).with(pin: 5, direction: :out).and_return(pin) | ||
expect(pin).to receive(:off) | ||
GpioPort.off(5) | ||
end | ||
|
||
end | ||
|
||
end |
Oops, something went wrong.