photo_handler 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/phimport +23 -0
- data/lib/photo_handler.rb +27 -0
- data/lib/photo_handler/config.rb +26 -0
- data/lib/photo_handler/env.rb +3 -0
- data/lib/photo_handler/photo.rb +38 -0
- data/lib/photo_handler/version.rb +4 -0
- metadata +86 -0
data/bin/phimport
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
$:.unshift(lib_dir) unless
|
5
|
+
$:.include?(lib_dir) || $:.include?(File.expand_path(lib_dir))
|
6
|
+
require 'photo_handler'
|
7
|
+
|
8
|
+
usage = <<EOT
|
9
|
+
Usage: #{$0}
|
10
|
+
This script will move files from a source of digital images to a location on disk. It is configured by
|
11
|
+
editing the config/photo_handler.yml file.
|
12
|
+
EOT
|
13
|
+
STDERR.puts usage
|
14
|
+
|
15
|
+
PhotoHandler.source_images.each do |source_image|
|
16
|
+
dest = File.join(PhotoHandler::Config.image_destination_directory,
|
17
|
+
PhotoHandler::Photo.new(source_image).destination_file_name)
|
18
|
+
dir = File.dirname(dest)
|
19
|
+
unless File.exist?(dir)
|
20
|
+
FileUtils.mkdir_p(dir, :verbose => true)
|
21
|
+
end
|
22
|
+
FileUtils.mv(source_image, dest, :verbose => true)
|
23
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require "photo_handler/env"
|
3
|
+
require "photo_handler/config"
|
4
|
+
require "photo_handler/photo"
|
5
|
+
if Gem.available?("ruby-debug")
|
6
|
+
require "ruby-debug"
|
7
|
+
end
|
8
|
+
|
9
|
+
module PhotoHandler
|
10
|
+
def self.root
|
11
|
+
Pathname.new(__FILE__).dirname.parent
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.env
|
15
|
+
"default"
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.source_images
|
19
|
+
source_images = []
|
20
|
+
Find.find(Config.image_source_directory) do |path|
|
21
|
+
if Config.image_extensions.include?(File.extname(path))
|
22
|
+
source_images << path
|
23
|
+
end
|
24
|
+
end
|
25
|
+
source_images
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module PhotoHandler
|
2
|
+
class Config
|
3
|
+
class << self
|
4
|
+
@@config = nil
|
5
|
+
|
6
|
+
protected
|
7
|
+
def config
|
8
|
+
@@config ||= YAML.load_file(PhotoHandler.root.join(*%w(config photo_handler.yml)))[PhotoHandler.env]
|
9
|
+
end
|
10
|
+
|
11
|
+
public
|
12
|
+
|
13
|
+
def has_setting?(name)
|
14
|
+
self.config.has_key?(name.to_s)
|
15
|
+
end
|
16
|
+
|
17
|
+
def method_missing(name, *args)
|
18
|
+
if has_setting?(name.to_s)
|
19
|
+
self.config[name.to_s]
|
20
|
+
else
|
21
|
+
super
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "exifr"
|
2
|
+
|
3
|
+
module PhotoHandler
|
4
|
+
class Photo
|
5
|
+
def initialize(filename)
|
6
|
+
@filename = filename
|
7
|
+
self
|
8
|
+
end
|
9
|
+
|
10
|
+
def exif
|
11
|
+
unless @exif
|
12
|
+
begin
|
13
|
+
@exif = EXIFR::JPEG.new(@filename)
|
14
|
+
rescue EXIFR::MalformedJPEG
|
15
|
+
@exif = EXIFR::TIFF.new(@filename)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
@exif
|
19
|
+
end
|
20
|
+
|
21
|
+
def destination_file_name
|
22
|
+
elements = Config.destination_file_name.split("/")
|
23
|
+
elements.map! do |element|
|
24
|
+
case element
|
25
|
+
when ":ext"
|
26
|
+
File.extname(@filename).downcase[1..-1]
|
27
|
+
when ":date"
|
28
|
+
exif.date_time.strftime("%Y-%m-%d")
|
29
|
+
when ":original_name"
|
30
|
+
File.basename(@filename)
|
31
|
+
else
|
32
|
+
element
|
33
|
+
end
|
34
|
+
end
|
35
|
+
File.join(elements)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: photo_handler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Tom ten Thij
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-11-12 00:00:00 +00:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: exifr
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description: Utilities for managing digital images
|
36
|
+
email:
|
37
|
+
- ruby@tomtenthij.nl
|
38
|
+
executables:
|
39
|
+
- phimport
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files: []
|
43
|
+
|
44
|
+
files:
|
45
|
+
- bin/phimport
|
46
|
+
- lib/photo_handler/config.rb
|
47
|
+
- lib/photo_handler/env.rb
|
48
|
+
- lib/photo_handler/photo.rb
|
49
|
+
- lib/photo_handler/version.rb
|
50
|
+
- lib/photo_handler.rb
|
51
|
+
has_rdoc: true
|
52
|
+
homepage: http://github.com/tomtt/photo_handler
|
53
|
+
licenses: []
|
54
|
+
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
hash: 3
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.3.7
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Utilities for managing digital images
|
85
|
+
test_files: []
|
86
|
+
|