sicily 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +10 -3
- data/README.md +10 -0
- data/lib/sicily.rb +3 -0
- data/lib/sicily/config.rb +6 -17
- data/lib/sicily/file_processor.rb +0 -43
- data/lib/sicily/task/dummy_task.rb +10 -0
- data/lib/sicily/task/file_task.rb +29 -14
- data/lib/sicily/task/google_photo_task.rb +20 -5
- data/lib/sicily/task/resize_task.rb +19 -6
- data/lib/sicily/task_loader.rb +20 -0
- data/lib/sicily/util/image_util.rb +12 -0
- data/lib/sicily/version.rb +1 -1
- data/sicily.gemspec +8 -1
- metadata +38 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24bffd7625f941daf5ce70d26b13e2e125e357ae
|
4
|
+
data.tar.gz: 60915840c1a95a889b11fa1025846c1a83507b96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3628311381543b604a85d12c2e5ce1a824c9111c168d3512d37c01ee5c0270a19d45ccd438d88b983a15b264c15e45eaf2ca1d66dd960f4208a49b56610e7778
|
7
|
+
data.tar.gz: f8c1ef202d59a65ecc9063a507eb88f8b73f5ded2d359a832539086d7c18b48e707a2c609c894c57dc6d345ba38074c293fae8f718115b8a8abf50ab83f74630
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,29 +1,36 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sicily (0.1.
|
4
|
+
sicily (0.1.3)
|
5
5
|
concurrent-ruby (~> 1.0.5)
|
6
6
|
exifr (~> 1.3.3)
|
7
|
+
fastimage (~> 2.1.1)
|
8
|
+
fastimage_resize (~> 2.0.3)
|
7
9
|
god (~> 0.13.7)
|
8
10
|
listen (~> 3.1.5)
|
9
|
-
mini_magick (~> 4.8.0)
|
10
11
|
terminal-notifier (~> 2.0.0)
|
11
12
|
whenever (~> 0.10.0)
|
12
13
|
|
13
14
|
GEM
|
14
15
|
remote: https://rubygems.org/
|
15
16
|
specs:
|
17
|
+
RubyInline (3.12.4)
|
18
|
+
ZenTest (~> 4.3)
|
19
|
+
ZenTest (4.11.1)
|
16
20
|
chronic (0.10.2)
|
17
21
|
concurrent-ruby (1.0.5)
|
18
22
|
diff-lcs (1.3)
|
19
23
|
exifr (1.3.3)
|
24
|
+
fastimage (2.1.1)
|
25
|
+
fastimage_resize (2.0.3)
|
26
|
+
RubyInline (>= 3.8.2)
|
27
|
+
fastimage (>= 1.2.9)
|
20
28
|
ffi (1.9.21)
|
21
29
|
god (0.13.7)
|
22
30
|
listen (3.1.5)
|
23
31
|
rb-fsevent (~> 0.9, >= 0.9.4)
|
24
32
|
rb-inotify (~> 0.9, >= 0.9.7)
|
25
33
|
ruby_dep (~> 1.2)
|
26
|
-
mini_magick (4.8.0)
|
27
34
|
rake (10.5.0)
|
28
35
|
rb-fsevent (0.10.2)
|
29
36
|
rb-inotify (0.9.10)
|
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/sicily.svg)](https://badge.fury.io/rb/sicily)
|
2
|
+
|
1
3
|
# Sicily
|
2
4
|
|
3
5
|
A rule-based photo organizer written in Ruby
|
@@ -51,6 +53,14 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
51
53
|
|
52
54
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
53
55
|
|
56
|
+
### Adding a New Task
|
57
|
+
|
58
|
+
Refer to `lib/sicily/task/` and `spec/sicily/task/`.
|
59
|
+
|
60
|
+
You create any task as you want.
|
61
|
+
|
62
|
+
TaskLoader(`lib/sicily/task_loader.rb`) will load it automatically.
|
63
|
+
|
54
64
|
## TODO
|
55
65
|
* error handling
|
56
66
|
* logging
|
data/lib/sicily.rb
CHANGED
@@ -2,10 +2,13 @@ require "sicily/version"
|
|
2
2
|
require "sicily/config"
|
3
3
|
require "sicily/monitor"
|
4
4
|
require "sicily/util/file_util"
|
5
|
+
require "sicily/task_loader"
|
5
6
|
|
6
7
|
module Sicily
|
7
8
|
@monitored_paths = []
|
8
9
|
|
10
|
+
TaskLoader.new.load_all_tasks
|
11
|
+
|
9
12
|
def self.on(path, &block)
|
10
13
|
if self.can_monitor?(@monitored_paths, path)
|
11
14
|
self.start_monitor!(path, &block)
|
data/lib/sicily/config.rb
CHANGED
@@ -1,20 +1,12 @@
|
|
1
|
-
require "singleton"
|
2
|
-
|
3
1
|
module Sicily
|
4
|
-
|
5
|
-
|
6
|
-
block.call GoogleCredential.instance
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.config
|
10
|
-
Config.instance
|
2
|
+
class << self
|
3
|
+
attr_accessor :config
|
11
4
|
end
|
12
5
|
|
13
6
|
class Config
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
:num_thread_pool
|
7
|
+
attr_reader :forbid_new_file_in_subfolder,
|
8
|
+
:notify_when_done,
|
9
|
+
:num_thread_pool
|
18
10
|
|
19
11
|
def initialize
|
20
12
|
@forbid_new_file_in_subfolder = true
|
@@ -23,8 +15,5 @@ module Sicily
|
|
23
15
|
end
|
24
16
|
end
|
25
17
|
|
26
|
-
|
27
|
-
include Singleton
|
28
|
-
attr_accessor :id, :pw
|
29
|
-
end
|
18
|
+
Sicily.config = Config.new
|
30
19
|
end
|
@@ -1,50 +1,7 @@
|
|
1
|
-
require "sicily/task/resize_task"
|
2
|
-
require "sicily/task/google_photo_task"
|
3
|
-
require "sicily/task/file_task"
|
4
|
-
require "sicily/util/file_util"
|
5
|
-
|
6
1
|
module Sicily
|
7
2
|
class FileProcessor
|
8
3
|
def initialize(path)
|
9
4
|
@path = path
|
10
5
|
end
|
11
|
-
|
12
|
-
def fit_if_photo(width, height)
|
13
|
-
Task::ResizeTask.fit_if_photo @path, width, height
|
14
|
-
end
|
15
|
-
|
16
|
-
def google_photo
|
17
|
-
Task::GooglePhotoTask.upload @path
|
18
|
-
end
|
19
|
-
|
20
|
-
def mv(dest_path)
|
21
|
-
file_task_op :mv, dest_path
|
22
|
-
end
|
23
|
-
|
24
|
-
def cp(dest_path)
|
25
|
-
file_task_op :cp, dest_path
|
26
|
-
end
|
27
|
-
|
28
|
-
def rm
|
29
|
-
Task::FileTask.rm @path
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
def file_task_op(op, dest_path)
|
34
|
-
cannot_op = Sicily.config.forbid_new_file_in_subfolder &&
|
35
|
-
Util::FileUtil.is_related?(@path, dest_path)
|
36
|
-
|
37
|
-
if cannot_op
|
38
|
-
raise [
|
39
|
-
"Cannot #{op} to child folder",
|
40
|
-
" src : #{@path}",
|
41
|
-
" dest : #{dest_path}",
|
42
|
-
].join("\n")
|
43
|
-
return
|
44
|
-
end
|
45
|
-
|
46
|
-
final_dest_path = Util::FileUtil.eval_dest_path(@path, dest_path)
|
47
|
-
Task::FileTask.public_send op, @path, final_dest_path
|
48
|
-
end
|
49
6
|
end
|
50
7
|
end
|
@@ -3,26 +3,41 @@ require "sicily/config"
|
|
3
3
|
|
4
4
|
module Sicily
|
5
5
|
module Task
|
6
|
-
class
|
7
|
-
def self.
|
8
|
-
|
9
|
-
|
6
|
+
class Base
|
7
|
+
def self.prepare_dest_path(path_src, path_dest)
|
8
|
+
cannot_op = Sicily.config.forbid_new_file_in_subfolder &&
|
9
|
+
Util::FileUtil.is_related?(path_src, path_dest)
|
10
|
+
|
11
|
+
if cannot_op
|
12
|
+
raise [
|
13
|
+
"Cannot do file operation to child folder",
|
14
|
+
" src : #{path_src}",
|
15
|
+
" dest : #{path_dest}",
|
16
|
+
].join("\n")
|
17
|
+
return
|
18
|
+
end
|
19
|
+
|
20
|
+
final_dest_path = Util::FileUtil.eval_dest_path(path_src, path_dest)
|
21
|
+
final_dest_path = File.expand_path final_dest_path
|
22
|
+
FileUtils.mkdir_p final_dest_path
|
10
23
|
|
11
|
-
|
12
|
-
file_op :cp, path_src, path_dest
|
24
|
+
final_dest_path
|
13
25
|
end
|
26
|
+
end
|
14
27
|
|
15
|
-
|
16
|
-
|
28
|
+
module FileTask
|
29
|
+
def mv(path_dest)
|
30
|
+
path_dest = Base.prepare_dest_path(@path, path_dest)
|
31
|
+
FileUtils.mv @path, path_dest
|
17
32
|
end
|
18
33
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
34
|
+
def cp(path_dest)
|
35
|
+
path_dest = Base.prepare_dest_path(@path, path_dest)
|
36
|
+
FileUtils.cp @path, path_dest
|
37
|
+
end
|
23
38
|
|
24
|
-
|
25
|
-
FileUtils.
|
39
|
+
def rm
|
40
|
+
FileUtils.rm @path
|
26
41
|
end
|
27
42
|
end
|
28
43
|
end
|
@@ -1,16 +1,31 @@
|
|
1
1
|
require "sicily/config"
|
2
2
|
|
3
3
|
module Sicily
|
4
|
+
class << self
|
5
|
+
attr_accessor :config_google
|
6
|
+
end
|
7
|
+
|
8
|
+
class GoogleCredential
|
9
|
+
attr_accessor :id, :pw
|
10
|
+
end
|
11
|
+
|
12
|
+
Sicily.config_google = GoogleCredential.new
|
13
|
+
|
14
|
+
def self.configure_google(&block)
|
15
|
+
return if block.nil?
|
16
|
+
block.call Sicily.config_google
|
17
|
+
end
|
18
|
+
|
4
19
|
module Task
|
5
|
-
|
6
|
-
def
|
7
|
-
id =
|
8
|
-
pw =
|
20
|
+
module GooglePhotoTask
|
21
|
+
def google_photo
|
22
|
+
id = Sicily.config_google.id
|
23
|
+
pw = Sicily.config_google.pw
|
9
24
|
|
10
25
|
if id.to_s.empty? or pw.to_s.empty?
|
11
26
|
raise "no google credential"
|
12
27
|
else
|
13
|
-
cmd = "upload-gphotos \"#{path}\" -u #{id} -p #{pw}"
|
28
|
+
cmd = "upload-gphotos \"#{@path}\" -u #{id} -p #{pw}"
|
14
29
|
`#{cmd}`
|
15
30
|
end
|
16
31
|
end
|
@@ -1,14 +1,27 @@
|
|
1
|
-
require "
|
1
|
+
require "sicily/util/image_util"
|
2
|
+
require "fastimage_resize"
|
2
3
|
|
3
4
|
module Sicily
|
4
5
|
module Task
|
5
|
-
class
|
6
|
-
def self.
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
class SizeCalculator
|
7
|
+
def self.size_to_fit(container_width, container_height, image_width, image_height)
|
8
|
+
if container_width*image_height > container_height*image_width
|
9
|
+
[(image_width*container_height/image_height).to_i, container_height]
|
10
|
+
else
|
11
|
+
[container_width, (image_height*container_width/image_width).to_i]
|
10
12
|
end
|
11
13
|
end
|
12
14
|
end
|
15
|
+
|
16
|
+
module ResizeTask
|
17
|
+
def fit_if_photo(container_width, container_height)
|
18
|
+
size = Util::ImageUtil.get_size(@path)
|
19
|
+
image_width = size[0]
|
20
|
+
image_height = size[1]
|
21
|
+
|
22
|
+
dest_size = SizeCalculator.size_to_fit container_width, container_height, image_width, image_height
|
23
|
+
FastImage.resize(@path, dest_size[0], dest_size[1], :outfile => @path)
|
24
|
+
end
|
25
|
+
end
|
13
26
|
end
|
14
27
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Sicily
|
2
|
+
class TaskLoader
|
3
|
+
def load_all_tasks
|
4
|
+
Dir["#{File.dirname(__FILE__)}/task/*.rb"].each {|file|
|
5
|
+
require file
|
6
|
+
|
7
|
+
module_name = camelize(File.basename(file, ".*"))
|
8
|
+
maybe_module = Task.const_get(module_name)
|
9
|
+
if maybe_module.class.name == "Module"
|
10
|
+
FileProcessor.send(:include, maybe_module)
|
11
|
+
end
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def camelize(str)
|
17
|
+
str.split('_').map {|w| w.capitalize}.join
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/sicily/version.rb
CHANGED
data/sicily.gemspec
CHANGED
@@ -14,11 +14,17 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.homepage = "https://github.com/eunjae-lee/sicily"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
|
+
spec.metadata = {
|
18
|
+
'changelog_uri' => "https://github.com/eunjae-lee/sicily/blob/master/CHANGELOG.md"
|
19
|
+
}
|
20
|
+
|
17
21
|
spec.post_install_message = %q{
|
18
22
|
|
19
23
|
To finish installation, please execute the following:
|
20
24
|
$ npm install -g upload-gphotos
|
21
25
|
|
26
|
+
And Libgd is required for this gem. Please install it like the following:
|
27
|
+
$ brew install gd
|
22
28
|
|
23
29
|
}
|
24
30
|
|
@@ -29,13 +35,14 @@ Gem::Specification.new do |spec|
|
|
29
35
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
36
|
spec.require_paths = ["lib"]
|
31
37
|
|
32
|
-
spec.add_dependency "mini_magick", "~> 4.8.0"
|
33
38
|
spec.add_dependency "listen", "~> 3.1.5"
|
34
39
|
spec.add_dependency "god", "~> 0.13.7"
|
35
40
|
spec.add_dependency "whenever", "~> 0.10.0"
|
36
41
|
spec.add_dependency "terminal-notifier", "~> 2.0.0"
|
37
42
|
spec.add_dependency "concurrent-ruby", "~> 1.0.5"
|
38
43
|
spec.add_dependency "exifr", "~> 1.3.3"
|
44
|
+
spec.add_dependency "fastimage", "~> 2.1.1"
|
45
|
+
spec.add_dependency "fastimage_resize", "~> 2.0.3"
|
39
46
|
|
40
47
|
spec.add_development_dependency "bundler", "~> 1.16"
|
41
48
|
spec.add_development_dependency "rake", "~> 10.0"
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sicily
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: mini_magick
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 4.8.0
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 4.8.0
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: listen
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,6 +94,34 @@ dependencies:
|
|
108
94
|
- - "~>"
|
109
95
|
- !ruby/object:Gem::Version
|
110
96
|
version: 1.3.3
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: fastimage
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 2.1.1
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 2.1.1
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: fastimage_resize
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 2.0.3
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 2.0.3
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: bundler
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -176,24 +190,30 @@ files:
|
|
176
190
|
- lib/sicily/config.rb
|
177
191
|
- lib/sicily/file_processor.rb
|
178
192
|
- lib/sicily/monitor.rb
|
193
|
+
- lib/sicily/task/dummy_task.rb
|
179
194
|
- lib/sicily/task/file_task.rb
|
180
195
|
- lib/sicily/task/google_photo_task.rb
|
181
196
|
- lib/sicily/task/resize_task.rb
|
197
|
+
- lib/sicily/task_loader.rb
|
182
198
|
- lib/sicily/util/exif_util.rb
|
183
199
|
- lib/sicily/util/file_util.rb
|
200
|
+
- lib/sicily/util/image_util.rb
|
184
201
|
- lib/sicily/util/notification_util.rb
|
185
202
|
- lib/sicily/version.rb
|
186
203
|
- sicily.gemspec
|
187
204
|
homepage: https://github.com/eunjae-lee/sicily
|
188
205
|
licenses:
|
189
206
|
- MIT
|
190
|
-
metadata:
|
207
|
+
metadata:
|
208
|
+
changelog_uri: https://github.com/eunjae-lee/sicily/blob/master/CHANGELOG.md
|
191
209
|
post_install_message: |2+
|
192
210
|
|
193
211
|
|
194
212
|
To finish installation, please execute the following:
|
195
213
|
$ npm install -g upload-gphotos
|
196
214
|
|
215
|
+
And Libgd is required for this gem. Please install it like the following:
|
216
|
+
$ brew install gd
|
197
217
|
|
198
218
|
rdoc_options: []
|
199
219
|
require_paths:
|
@@ -210,7 +230,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
210
230
|
version: '0'
|
211
231
|
requirements: []
|
212
232
|
rubyforge_project:
|
213
|
-
rubygems_version: 2.6.
|
233
|
+
rubygems_version: 2.6.11
|
214
234
|
signing_key:
|
215
235
|
specification_version: 4
|
216
236
|
summary: A rule-based photo organizer written in Ruby
|