sicily 0.1.0 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c8376a664b3749b235782f42fefc7c29525516e
4
- data.tar.gz: ceddf6ebb51c6b01df9edb5bbeb6357e5ed65755
3
+ metadata.gz: 432b38f3655122f0e77004cf6617b441da0dd434
4
+ data.tar.gz: 021d5745791b343d38b7f176fc554fd2d9484fa4
5
5
  SHA512:
6
- metadata.gz: 0c54423dca2dcd2b2d6d0363cca7d33c432ae0488dfc84fe7115dd9a2038c55b9559af1de0b80e800dd97bef8201634d25282df7bd09c57fdb8f55d82414206c
7
- data.tar.gz: 4dd1b915b7ce46d2674458f174dbb150225d6b63beca68b7e2c3d73a1f13441dd5359116b414ebea3fc45fab033c2644afdb8f6ebb0011a54e4bc9daf1cfcb4f
6
+ metadata.gz: 28110fe847ee56f8b433d34984739aaa269427b961ffc35f1b005c7a1be3090dbcee5720454693db4e98bec56440ef8ca5d495034c6cbdd32fcbbb8ef8f765ee
7
+ data.tar.gz: fe244290789b35435ed9000226bf9627b88b032425578e60227c0c695c2550e9cf2ae90b342baaaeddb8ecfc84ac4eea84d987d5abd051feb67b199e4451730a
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sicily (0.1.0)
4
+ sicily (0.1.1)
5
5
  concurrent-ruby (~> 1.0.5)
6
+ exifr (~> 1.3.3)
6
7
  god (~> 0.13.7)
7
8
  listen (~> 3.1.5)
8
9
  mini_magick (~> 4.8.0)
@@ -15,6 +16,7 @@ GEM
15
16
  chronic (0.10.2)
16
17
  concurrent-ruby (1.0.5)
17
18
  diff-lcs (1.3)
19
+ exifr (1.3.3)
18
20
  ffi (1.9.21)
19
21
  god (0.13.7)
20
22
  listen (3.1.5)
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # Sicily
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sicily`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ A rule-based photo organizer written in Ruby
6
4
 
7
5
  ## Installation
8
6
 
@@ -20,32 +18,32 @@ Or install it yourself as:
20
18
 
21
19
  $ gem install sicily
22
20
 
23
- config/config.rb
24
-
25
- Sicily.configure do |config|
26
- config.forbid_mv_to_children_folder = true
27
- config.notify_when_done = true
28
- config.num_thread_pool = 50
29
- end
21
+ And install a node package as:
22
+
23
+ $ npm install -g upload-gphotos
30
24
 
31
- config/.google_photo.rb
25
+ ## Usage
32
26
 
33
- Sicily.configure_google do |config|
34
- config.id = "abcd"
35
- config.pw = "def"
36
- end
27
+ Go to your project path, and then execute:
37
28
 
38
- config/rules.rb
29
+ $ sicily generate
30
+
31
+ Modify the generated files:
39
32
 
40
- Sicily.on "/Users/paul/Downloads" do
41
- fit_if_photo 2000, 2000
42
- google_photo
43
- mv "/Users/paul/Desktop/testfolder"
44
- end
33
+ ./config/google_photo.rb
34
+ ./config/rules.rb
45
35
 
46
- ## Usage
36
+ If you want to monitor just during the current terminal session, then execute:
47
37
 
48
- TODO: Write usage instructions here
38
+ $ sicily monitor
39
+
40
+ If you want to run a background job which runs forever, then execute:
41
+
42
+ $ sicily start
43
+
44
+ If you want to stop that background job, then execute:
45
+
46
+ $ sicily stop
49
47
 
50
48
  ## Development
51
49
 
@@ -53,6 +51,10 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
53
51
 
54
52
  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).
55
53
 
54
+ ## TODO
55
+ * error handling
56
+ * logging
57
+
56
58
  ## Contributing
57
59
 
58
60
  Bug reports and pull requests are welcome on GitHub at https://github.com/eunjae-lee/sicily. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
data/exe/sicily CHANGED
@@ -36,7 +36,12 @@ EOF
36
36
  Sicily.on "~/your_folder" do
37
37
  fit_if_photo 2000, 2000
38
38
  google_photo
39
- mv "~/your_another_folder"
39
+ mv "~/your_another_folder/%Y/%m/%d"
40
+ end
41
+
42
+ Sicily.on "~/your_folder2" do
43
+ fit_if_photo 1000, 1000
44
+ cp "~/your_another_folder/%Y/%m/%d"
40
45
  end
41
46
  EOF
42
47
 
@@ -1,32 +1,30 @@
1
1
  require "sicily/version"
2
2
  require "sicily/config"
3
3
  require "sicily/monitor"
4
- require "pathname"
4
+ require "sicily/util/file_util"
5
5
 
6
6
  module Sicily
7
7
  @monitored_paths = []
8
8
 
9
9
  def self.on(path, &block)
10
10
  if self.can_monitor?(@monitored_paths, path)
11
- self.start_monitor(path, &block)
11
+ self.start_monitor!(path, &block)
12
12
  else
13
13
  puts "cannot monitor : #{path}"
14
14
  end
15
15
  end
16
16
 
17
- def self.start_monitor(path, &block)
17
+ def self.start_monitor!(path, &block)
18
18
  @monitored_paths << File.expand_path(path)
19
19
  Monitor.new.on(path, &block)
20
20
  end
21
21
 
22
22
  def self.can_monitor?(prev_paths, new_path)
23
- expanded_new_path = File.expand_path(new_path)
24
23
  prev_paths.each do |prev_path|
25
- is_sub_folder = Pathname.new(prev_path).fnmatch?(File.join(expanded_new_path, "**")) ||
26
- Pathname.new(expanded_new_path).fnmatch?(File.join(prev_path, "**"))
27
- return false if is_sub_folder
24
+ return false if Util::FileUtil.is_related?(prev_path, new_path) ||
25
+ Util::FileUtil.is_related?(new_path, prev_path)
28
26
  end
29
27
 
30
- return true
28
+ true
31
29
  end
32
30
  end
@@ -1,6 +1,6 @@
1
1
  require "sicily/config"
2
2
  require "sicily/file_processor"
3
- require "sicily/notification_util"
3
+ require "sicily/util/notification_util"
4
4
 
5
5
  module Sicily
6
6
  class BatchProcessor
@@ -32,7 +32,7 @@ module Sicily
32
32
  end
33
33
 
34
34
  def notify(files)
35
- NotificationUtil.notify(files)
35
+ Util::NotificationUtil.notify(files)
36
36
  end
37
37
  end
38
38
  end
@@ -12,12 +12,12 @@ module Sicily
12
12
 
13
13
  class Config
14
14
  include Singleton
15
- attr_accessor :forbid_mv_to_children_folder,
15
+ attr_accessor :forbid_new_file_in_subfolder,
16
16
  :notify_when_done,
17
17
  :num_thread_pool
18
18
 
19
19
  def initialize
20
- @forbid_mv_to_children_folder = true
20
+ @forbid_new_file_in_subfolder = true
21
21
  @notify_when_done = true
22
22
  @num_thread_pool = 50
23
23
  end
@@ -1,6 +1,7 @@
1
1
  require "sicily/task/resize_task"
2
2
  require "sicily/task/google_photo_task"
3
3
  require "sicily/task/file_task"
4
+ require "sicily/util/file_util"
4
5
 
5
6
  module Sicily
6
7
  class FileProcessor
@@ -17,7 +18,29 @@ module Sicily
17
18
  end
18
19
 
19
20
  def mv(dest_path)
20
- Task::FileTask.mv @path, 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
+ private
29
+ def file_task_op(op, dest_path)
30
+ cannot_op = Sicily.config.forbid_new_file_in_subfolder &&
31
+ Util::FileUtil.is_related?(@path, dest_path)
32
+
33
+ if cannot_op
34
+ raise [
35
+ "Cannot #{op} to child folder",
36
+ " src : #{@path}",
37
+ " dest : #{dest_path}",
38
+ ].join("\n")
39
+ return
40
+ end
41
+
42
+ final_dest_path = Util::FileUtil.eval_dest_path(@path, dest_path)
43
+ Task::FileTask.public_send op, @path, final_dest_path
21
44
  end
22
45
  end
23
46
  end
@@ -5,23 +5,20 @@ module Sicily
5
5
  module Task
6
6
  class FileTask
7
7
  def self.mv(path_src, path_dest)
8
+ file_op :mv, path_src, path_dest
9
+ end
10
+
11
+ def self.cp(path_src, path_dest)
12
+ file_op :cp, path_src, path_dest
13
+ end
14
+
15
+ private
16
+ def self.file_op(op, path_src, path_dest)
8
17
  path_src = File.expand_path path_src
9
18
  path_dest = File.expand_path path_dest
10
19
 
11
- if Sicily.config.forbid_mv_to_children_folder
12
- dir_src = File.dirname path_src
13
- if path_dest.start_with? dir_src
14
- raise [
15
- "Cannot move to children folder",
16
- " src : #{dir_src}",
17
- " dest : #{path_dest}",
18
- ].join("\n")
19
- return
20
- end
21
- end
22
-
23
20
  FileUtils.mkdir_p path_dest
24
- FileUtils.mv path_src, path_dest
21
+ FileUtils.public_send op, path_src, path_dest
25
22
  end
26
23
  end
27
24
  end
@@ -0,0 +1,11 @@
1
+ require "exifr/jpeg"
2
+
3
+ module Sicily
4
+ module Util
5
+ class ExifUtil
6
+ def self.extract_time_from_jpeg(path)
7
+ EXIFR::JPEG.new(path).date_time
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,28 @@
1
+ require "sicily/util/exif_util"
2
+ require "pathname"
3
+
4
+ module Sicily
5
+ module Util
6
+ class FileUtil
7
+ def self.is_related?(maybe_parent_path, maybe_child_path)
8
+ expanded_parent_path = File.expand_path(maybe_parent_path)
9
+ expanded_child_path = File.expand_path(maybe_child_path)
10
+ Pathname.new(expanded_child_path).fnmatch? File.join(expanded_parent_path, "**")
11
+ end
12
+
13
+ def self.eval_dest_path(src_path, dest_path)
14
+ time = self.extract_time(src_path)
15
+ time.strftime(dest_path)
16
+ end
17
+
18
+ def self.extract_time(path)
19
+ if [".jpg", ".jpeg"].include? File.extname(path).downcase
20
+ time_from_exif = ExifUtil.extract_time_from_jpeg(path)
21
+ return time_from_exif unless time_from_exif.nil?
22
+ end
23
+
24
+ File.ctime(path)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,14 @@
1
+ require "terminal-notifier"
2
+
3
+ module Sicily
4
+ module Util
5
+ class NotificationUtil
6
+ def self.notify(files)
7
+ msg = files.map { |file|
8
+ File.basename(file)
9
+ }.join(", ")
10
+ TerminalNotifier.notify(msg, :title => "Finished processing #{files.size} file(s)")
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module Sicily
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -35,6 +35,7 @@ Gem::Specification.new do |spec|
35
35
  spec.add_dependency "whenever", "~> 0.10.0"
36
36
  spec.add_dependency "terminal-notifier", "~> 2.0.0"
37
37
  spec.add_dependency "concurrent-ruby", "~> 1.0.5"
38
+ spec.add_dependency "exifr", "~> 1.3.3"
38
39
 
39
40
  spec.add_development_dependency "bundler", "~> 1.16"
40
41
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sicily
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
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-13 00:00:00.000000000 Z
11
+ date: 2018-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mini_magick
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 1.0.5
97
+ - !ruby/object:Gem::Dependency
98
+ name: exifr
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.3.3
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.3.3
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: bundler
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -161,10 +175,12 @@ files:
161
175
  - lib/sicily/config.rb
162
176
  - lib/sicily/file_processor.rb
163
177
  - lib/sicily/monitor.rb
164
- - lib/sicily/notification_util.rb
165
178
  - lib/sicily/task/file_task.rb
166
179
  - lib/sicily/task/google_photo_task.rb
167
180
  - lib/sicily/task/resize_task.rb
181
+ - lib/sicily/util/exif_util.rb
182
+ - lib/sicily/util/file_util.rb
183
+ - lib/sicily/util/notification_util.rb
168
184
  - lib/sicily/version.rb
169
185
  - sicily.gemspec
170
186
  homepage: https://github.com/eunjae-lee/sicily
@@ -1,12 +0,0 @@
1
- require "terminal-notifier"
2
-
3
- module Sicily
4
- class NotificationUtil
5
- def self.notify(files)
6
- msg = files.map { |file|
7
- File.basename(file)
8
- }.join(", ")
9
- TerminalNotifier.notify(msg, :title => "Finished processing #{files.size} file(s)")
10
- end
11
- end
12
- end