sicily 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0c8376a664b3749b235782f42fefc7c29525516e
4
+ data.tar.gz: ceddf6ebb51c6b01df9edb5bbeb6357e5ed65755
5
+ SHA512:
6
+ metadata.gz: 0c54423dca2dcd2b2d6d0363cca7d33c432ae0488dfc84fe7115dd9a2038c55b9559af1de0b80e800dd97bef8201634d25282df7bd09c57fdb8f55d82414206c
7
+ data.tar.gz: 4dd1b915b7ce46d2674458f174dbb150225d6b63beca68b7e2c3d73a1f13441dd5359116b414ebea3fc45fab033c2644afdb8f6ebb0011a54e4bc9daf1cfcb4f
data/.gitignore ADDED
@@ -0,0 +1,232 @@
1
+ config/
2
+
3
+ .idea/
4
+
5
+ # rspec failure tracking
6
+ .rspec_status
7
+
8
+ # Created by https://www.gitignore.io/api/ruby,node,rubymine,jetbrains
9
+
10
+ ### JetBrains ###
11
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
12
+ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
13
+
14
+ # User-specific stuff:
15
+ .idea/**/workspace.xml
16
+ .idea/**/tasks.xml
17
+ .idea/dictionaries
18
+
19
+ # Sensitive or high-churn files:
20
+ .idea/**/dataSources/
21
+ .idea/**/dataSources.ids
22
+ .idea/**/dataSources.xml
23
+ .idea/**/dataSources.local.xml
24
+ .idea/**/sqlDataSources.xml
25
+ .idea/**/dynamic.xml
26
+ .idea/**/uiDesigner.xml
27
+
28
+ # Gradle:
29
+ .idea/**/gradle.xml
30
+ .idea/**/libraries
31
+
32
+ # CMake
33
+ cmake-build-debug/
34
+
35
+ # Mongo Explorer plugin:
36
+ .idea/**/mongoSettings.xml
37
+
38
+ ## File-based project format:
39
+ *.iws
40
+
41
+ ## Plugin-specific files:
42
+
43
+ # IntelliJ
44
+ /out/
45
+
46
+ # mpeltonen/sbt-idea plugin
47
+ .idea_modules/
48
+
49
+ # JIRA plugin
50
+ atlassian-ide-plugin.xml
51
+
52
+ # Cursive Clojure plugin
53
+ .idea/replstate.xml
54
+
55
+ # Ruby plugin and RubyMine
56
+ /.rakeTasks
57
+
58
+ # Crashlytics plugin (for Android Studio and IntelliJ)
59
+ com_crashlytics_export_strings.xml
60
+ crashlytics.properties
61
+ crashlytics-build.properties
62
+ fabric.properties
63
+
64
+ ### JetBrains Patch ###
65
+ # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
66
+
67
+ # *.iml
68
+ # modules.xml
69
+ # .idea/misc.xml
70
+ # *.ipr
71
+
72
+ # Sonarlint plugin
73
+ .idea/sonarlint
74
+
75
+ ### Node ###
76
+ # Logs
77
+ logs
78
+ *.log
79
+ npm-debug.log*
80
+ yarn-debug.log*
81
+ yarn-error.log*
82
+
83
+ # Runtime data
84
+ pids
85
+ *.pid
86
+ *.seed
87
+ *.pid.lock
88
+
89
+ # Directory for instrumented libs generated by jscoverage/JSCover
90
+ lib-cov
91
+
92
+ # Coverage directory used by tools like istanbul
93
+ coverage
94
+
95
+ # nyc test coverage
96
+ .nyc_output
97
+
98
+ # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
99
+ .grunt
100
+
101
+ # Bower dependency directory (https://bower.io/)
102
+ bower_components
103
+
104
+ # node-waf configuration
105
+ .lock-wscript
106
+
107
+ # Compiled binary addons (http://nodejs.org/api/addons.html)
108
+ build/Release
109
+
110
+ # Dependency directories
111
+ node_modules/
112
+ jspm_packages/
113
+
114
+ # Typescript v1 declaration files
115
+ typings/
116
+
117
+ # Optional npm cache directory
118
+ .npm
119
+
120
+ # Optional eslint cache
121
+ .eslintcache
122
+
123
+ # Optional REPL history
124
+ .node_repl_history
125
+
126
+ # Output of 'npm pack'
127
+ *.tgz
128
+
129
+ # Yarn Integrity file
130
+ .yarn-integrity
131
+
132
+ # dotenv environment variables file
133
+ .env
134
+
135
+
136
+ ### Ruby ###
137
+ *.gem
138
+ *.rbc
139
+ /.config
140
+ /coverage/
141
+ /InstalledFiles
142
+ /pkg/
143
+ /spec/reports/
144
+ /spec/examples.txt
145
+ /test/tmp/
146
+ /test/version_tmp/
147
+ /tmp/
148
+
149
+ # rspec failure tracking
150
+ .rspec_status
151
+
152
+ # Used by dotenv library to load environment variables.
153
+ # .env
154
+
155
+ ## Specific to RubyMotion:
156
+ .dat*
157
+ .repl_history
158
+ build/
159
+ *.bridgesupport
160
+ build-iPhoneOS/
161
+ build-iPhoneSimulator/
162
+
163
+ ## Specific to RubyMotion (use of CocoaPods):
164
+ #
165
+ # We recommend against adding the Pods directory to your .gitignore. However
166
+ # you should judge for yourself, the pros and cons are mentioned at:
167
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
168
+ #
169
+ # vendor/Pods/
170
+
171
+ ## Documentation cache and generated files:
172
+ /.yardoc/
173
+ /_yardoc/
174
+ /doc/
175
+ /rdoc/
176
+
177
+ ## Environment normalization:
178
+ /.bundle/
179
+ /vendor/bundle
180
+ /lib/bundler/man/
181
+
182
+ # for a library or gem, you might want to ignore these files since the code is
183
+ # intended to run in multiple environments; otherwise, check them in:
184
+ # Gemfile.lock
185
+ # .ruby-version
186
+ # .ruby-gemset
187
+
188
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
189
+ .rvmrc
190
+
191
+ ### RubyMine ###
192
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
193
+ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
194
+
195
+ # User-specific stuff:
196
+
197
+ # Sensitive or high-churn files:
198
+
199
+ # Gradle:
200
+
201
+ # CMake
202
+
203
+ # Mongo Explorer plugin:
204
+
205
+ ## File-based project format:
206
+
207
+ ## Plugin-specific files:
208
+
209
+ # IntelliJ
210
+
211
+ # mpeltonen/sbt-idea plugin
212
+
213
+ # JIRA plugin
214
+
215
+ # Cursive Clojure plugin
216
+
217
+ # Ruby plugin and RubyMine
218
+
219
+ # Crashlytics plugin (for Android Studio and IntelliJ)
220
+
221
+ ### RubyMine Patch ###
222
+ # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
223
+
224
+ # *.iml
225
+ # modules.xml
226
+ # .idea/misc.xml
227
+ # *.ipr
228
+
229
+ # Sonarlint plugin
230
+
231
+
232
+ # End of https://www.gitignore.io/api/ruby,node,rubymine,jetbrains
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.16.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at paul@valuepotion.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in sicily.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,57 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sicily (0.1.0)
5
+ concurrent-ruby (~> 1.0.5)
6
+ god (~> 0.13.7)
7
+ listen (~> 3.1.5)
8
+ mini_magick (~> 4.8.0)
9
+ terminal-notifier (~> 2.0.0)
10
+ whenever (~> 0.10.0)
11
+
12
+ GEM
13
+ remote: https://rubygems.org/
14
+ specs:
15
+ chronic (0.10.2)
16
+ concurrent-ruby (1.0.5)
17
+ diff-lcs (1.3)
18
+ ffi (1.9.21)
19
+ god (0.13.7)
20
+ listen (3.1.5)
21
+ rb-fsevent (~> 0.9, >= 0.9.4)
22
+ rb-inotify (~> 0.9, >= 0.9.7)
23
+ ruby_dep (~> 1.2)
24
+ mini_magick (4.8.0)
25
+ rake (10.5.0)
26
+ rb-fsevent (0.10.2)
27
+ rb-inotify (0.9.10)
28
+ ffi (>= 0.5.0, < 2)
29
+ rspec (3.7.0)
30
+ rspec-core (~> 3.7.0)
31
+ rspec-expectations (~> 3.7.0)
32
+ rspec-mocks (~> 3.7.0)
33
+ rspec-core (3.7.1)
34
+ rspec-support (~> 3.7.0)
35
+ rspec-expectations (3.7.0)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.7.0)
38
+ rspec-mocks (3.7.0)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.7.0)
41
+ rspec-support (3.7.1)
42
+ ruby_dep (1.5.0)
43
+ terminal-notifier (2.0.0)
44
+ whenever (0.10.0)
45
+ chronic (>= 0.6.3)
46
+
47
+ PLATFORMS
48
+ ruby
49
+
50
+ DEPENDENCIES
51
+ bundler (~> 1.16)
52
+ rake (~> 10.0)
53
+ rspec (~> 3.0)
54
+ sicily!
55
+
56
+ BUNDLED WITH
57
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Paul Lee
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # Sicily
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
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'sicily'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install sicily
22
+
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
30
+
31
+ config/.google_photo.rb
32
+
33
+ Sicily.configure_google do |config|
34
+ config.id = "abcd"
35
+ config.pw = "def"
36
+ end
37
+
38
+ config/rules.rb
39
+
40
+ Sicily.on "/Users/paul/Downloads" do
41
+ fit_if_photo 2000, 2000
42
+ google_photo
43
+ mv "/Users/paul/Desktop/testfolder"
44
+ end
45
+
46
+ ## Usage
47
+
48
+ TODO: Write usage instructions here
49
+
50
+ ## Development
51
+
52
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
53
+
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).
55
+
56
+ ## Contributing
57
+
58
+ 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.
59
+
60
+ ## License
61
+
62
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
63
+
64
+ ## Code of Conduct
65
+
66
+ Everyone interacting in the Sicily project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/eunjae-lee/sicily/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sicily"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/sicily ADDED
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
4
+
5
+ require "sicily"
6
+
7
+
8
+ command = ARGV[0]
9
+
10
+ case command
11
+ when "generate"
12
+ require "fileutils"
13
+ FileUtils.mkdir_p "./config"
14
+
15
+ god_content = <<-EOF
16
+ God.watch do |w|
17
+ w.name = "sicily"
18
+ w.start = "sicily monitor"
19
+ w.dir = File.expand_path("\#{File.dirname(__FILE__)}/..")
20
+ w.keepalive
21
+ end
22
+ EOF
23
+ schedule_content = <<-EOF
24
+ every :hour do
25
+ god_file = File.expand_path("\#{File.dirname(__FILE__)}/.sicily.god")
26
+ command "god -c \#{god_file}"
27
+ end
28
+ EOF
29
+ google_photo_content = <<-EOF
30
+ Sicily.configure_google do |config|
31
+ config.id = "your id"
32
+ config.pw = "your pw"
33
+ end
34
+ EOF
35
+ rules_content = <<-EOF
36
+ Sicily.on "~/your_folder" do
37
+ fit_if_photo 2000, 2000
38
+ google_photo
39
+ mv "~/your_another_folder"
40
+ end
41
+ EOF
42
+
43
+ File.write("./config/.sicily.god", god_content)
44
+ File.write("./config/.schedule.rb", schedule_content)
45
+ File.write("./config/google_photo.rb", google_photo_content)
46
+ File.write("./config/rules.rb", rules_content)
47
+
48
+ puts "Try edit the following files:"
49
+ puts " ./config/google_photo.rb"
50
+ puts " ./config/rules.rb"
51
+ puts ""
52
+ puts "To upload to Google Photos,"
53
+ puts " turn on \"Allowing less secure apps to access your account\""
54
+ puts " : https://support.google.com/accounts/answer/6010255"
55
+ puts " *USE AT YOUR OWN RISK*"
56
+ when "monitor"
57
+ `echo test >> monitor.log`
58
+ necessary_config_files = ["rules.rb"]
59
+ config_files_to_load = ["google_photo.rb", "rules.rb"]
60
+
61
+ necessary_config_files.each { |file|
62
+ unless File.exists? "./config/#{file}"
63
+ puts "./config/#{file} is missing!"
64
+ puts " Type: `sicily generate`"
65
+ exit
66
+ end
67
+ }
68
+
69
+ config_files_to_load.each { |filename|
70
+ path = "./config/#{filename}"
71
+ load(path) if File.exists?(path)
72
+ }
73
+
74
+ sleep
75
+ when "start"
76
+ command1 = "whenever --load-file ./config/.schedule.rb --update-crontab"
77
+ `#{command1}`
78
+
79
+ god_file = File.expand_path("./config/.sicily.god")
80
+ command2 = "god -c #{god_file}"
81
+ `#{command2}`
82
+ when "stop"
83
+ `god stop sicily`
84
+ `whenever --load-file ./config/.schedule.rb --clear-crontab`
85
+ else
86
+ banner = <<-EOF
87
+ Usage:
88
+ Generating config files:
89
+ sicily generate
90
+ Start monitoring in this terminal session:
91
+ sicily monitor
92
+ Start monitoring forever:
93
+ sicily start
94
+ Stop monitoring forever:
95
+ sicily stop
96
+ EOF
97
+ puts banner
98
+ end
99
+
100
+
data/lib/sicily.rb ADDED
@@ -0,0 +1,32 @@
1
+ require "sicily/version"
2
+ require "sicily/config"
3
+ require "sicily/monitor"
4
+ require "pathname"
5
+
6
+ module Sicily
7
+ @monitored_paths = []
8
+
9
+ def self.on(path, &block)
10
+ if self.can_monitor?(@monitored_paths, path)
11
+ self.start_monitor(path, &block)
12
+ else
13
+ puts "cannot monitor : #{path}"
14
+ end
15
+ end
16
+
17
+ def self.start_monitor(path, &block)
18
+ @monitored_paths << File.expand_path(path)
19
+ Monitor.new.on(path, &block)
20
+ end
21
+
22
+ def self.can_monitor?(prev_paths, new_path)
23
+ expanded_new_path = File.expand_path(new_path)
24
+ 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
28
+ end
29
+
30
+ return true
31
+ end
32
+ end
@@ -0,0 +1,38 @@
1
+ require "sicily/config"
2
+ require "sicily/file_processor"
3
+ require "sicily/notification_util"
4
+
5
+ module Sicily
6
+ class BatchProcessor
7
+ def run(files, &block)
8
+ return if files.empty?
9
+
10
+ notify_when_done = Sicily.config.notify_when_done
11
+ pool = Concurrent::FixedThreadPool.new(Sicily.config.num_thread_pool)
12
+ latch = Concurrent::CountDownLatch.new(files.size)
13
+ files.each do |file|
14
+ pool.post do
15
+ begin
16
+ process_added_file(file, &block)
17
+ rescue Exception => e
18
+ # FIXME : need to log `e.message`
19
+ end
20
+ latch.count_down
21
+ end
22
+ end
23
+
24
+ pool.post do
25
+ latch.wait
26
+ notify(files) if notify_when_done
27
+ end
28
+ end
29
+
30
+ def process_added_file(file, &block)
31
+ FileProcessor.new(file).instance_eval(&block)
32
+ end
33
+
34
+ def notify(files)
35
+ NotificationUtil.notify(files)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,30 @@
1
+ require "singleton"
2
+
3
+ module Sicily
4
+ def self.configure_google(&block)
5
+ return if block.nil?
6
+ block.call GoogleCredential.instance
7
+ end
8
+
9
+ def self.config
10
+ Config.instance
11
+ end
12
+
13
+ class Config
14
+ include Singleton
15
+ attr_accessor :forbid_mv_to_children_folder,
16
+ :notify_when_done,
17
+ :num_thread_pool
18
+
19
+ def initialize
20
+ @forbid_mv_to_children_folder = true
21
+ @notify_when_done = true
22
+ @num_thread_pool = 50
23
+ end
24
+ end
25
+
26
+ class GoogleCredential
27
+ include Singleton
28
+ attr_accessor :id, :pw
29
+ end
30
+ end
@@ -0,0 +1,23 @@
1
+ require "sicily/task/resize_task"
2
+ require "sicily/task/google_photo_task"
3
+ require "sicily/task/file_task"
4
+
5
+ module Sicily
6
+ class FileProcessor
7
+ def initialize(path)
8
+ @path = path
9
+ end
10
+
11
+ def fit_if_photo(width, height)
12
+ Task::ResizeTask.fit_if_photo @path, width, height
13
+ end
14
+
15
+ def google_photo
16
+ Task::GooglePhotoTask.upload @path
17
+ end
18
+
19
+ def mv(dest_path)
20
+ Task::FileTask.mv @path, dest_path
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ require "listen"
2
+ require "concurrent"
3
+ require "sicily/batch_processor"
4
+
5
+ module Sicily
6
+ class Monitor
7
+ def on(path, &block)
8
+ path = File.expand_path(path)
9
+ raise "Unknown path : #{path}" unless File.exists?(path)
10
+ listener = Listen.to(path) do |modified, added, removed|
11
+ BatchProcessor.new.run(added, &block)
12
+ end
13
+ listener.start
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,12 @@
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
@@ -0,0 +1,28 @@
1
+ require "fileutils"
2
+ require "sicily/config"
3
+
4
+ module Sicily
5
+ module Task
6
+ class FileTask
7
+ def self.mv(path_src, path_dest)
8
+ path_src = File.expand_path path_src
9
+ path_dest = File.expand_path path_dest
10
+
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
+ FileUtils.mkdir_p path_dest
24
+ FileUtils.mv path_src, path_dest
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,19 @@
1
+ require "sicily/config"
2
+
3
+ module Sicily
4
+ module Task
5
+ class GooglePhotoTask
6
+ def self.upload(path)
7
+ id = GoogleCredential.instance.id
8
+ pw = GoogleCredential.instance.pw
9
+
10
+ if id.to_s.empty? or pw.to_s.empty?
11
+ raise "no google credential"
12
+ else
13
+ cmd = "upload-gphotos \"#{path}\" -u #{id} -p #{pw}"
14
+ `#{cmd}`
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ require "mini_magick"
2
+
3
+ module Sicily
4
+ module Task
5
+ class ResizeTask
6
+ def self.fit_if_photo(path, width, height)
7
+ image = MiniMagick::Image.new(path)
8
+ if image.valid?
9
+ image.resize "#{width}x#{height}>"
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module Sicily
2
+ VERSION = "0.1.0"
3
+ end
data/sicily.gemspec ADDED
@@ -0,0 +1,42 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "sicily/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sicily"
8
+ spec.version = Sicily::VERSION
9
+ spec.authors = ["Paul Lee"]
10
+ spec.email = ["paul@valuepotion.com"]
11
+
12
+ spec.summary = "A rule-based photo organizer written in Ruby"
13
+ spec.description = spec.summary
14
+ spec.homepage = "https://github.com/eunjae-lee/sicily"
15
+ spec.license = "MIT"
16
+
17
+ spec.post_install_message = %q{
18
+
19
+ To finish installation, please execute the following:
20
+ $ npm install -g upload-gphotos
21
+
22
+
23
+ }
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_dependency "mini_magick", "~> 4.8.0"
33
+ spec.add_dependency "listen", "~> 3.1.5"
34
+ spec.add_dependency "god", "~> 0.13.7"
35
+ spec.add_dependency "whenever", "~> 0.10.0"
36
+ spec.add_dependency "terminal-notifier", "~> 2.0.0"
37
+ spec.add_dependency "concurrent-ruby", "~> 1.0.5"
38
+
39
+ spec.add_development_dependency "bundler", "~> 1.16"
40
+ spec.add_development_dependency "rake", "~> 10.0"
41
+ spec.add_development_dependency "rspec", "~> 3.0"
42
+ end
metadata ADDED
@@ -0,0 +1,200 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sicily
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Paul Lee
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-02-13 00:00:00.000000000 Z
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
+ - !ruby/object:Gem::Dependency
28
+ name: listen
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.1.5
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.1.5
41
+ - !ruby/object:Gem::Dependency
42
+ name: god
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.13.7
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.13.7
55
+ - !ruby/object:Gem::Dependency
56
+ name: whenever
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.10.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.10.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: terminal-notifier
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.0.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.0.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: concurrent-ruby
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.0.5
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.0.5
97
+ - !ruby/object:Gem::Dependency
98
+ name: bundler
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.16'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.16'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '10.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '10.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.0'
139
+ description: A rule-based photo organizer written in Ruby
140
+ email:
141
+ - paul@valuepotion.com
142
+ executables:
143
+ - sicily
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".gitignore"
148
+ - ".rspec"
149
+ - ".travis.yml"
150
+ - CODE_OF_CONDUCT.md
151
+ - Gemfile
152
+ - Gemfile.lock
153
+ - LICENSE.txt
154
+ - README.md
155
+ - Rakefile
156
+ - bin/console
157
+ - bin/setup
158
+ - exe/sicily
159
+ - lib/sicily.rb
160
+ - lib/sicily/batch_processor.rb
161
+ - lib/sicily/config.rb
162
+ - lib/sicily/file_processor.rb
163
+ - lib/sicily/monitor.rb
164
+ - lib/sicily/notification_util.rb
165
+ - lib/sicily/task/file_task.rb
166
+ - lib/sicily/task/google_photo_task.rb
167
+ - lib/sicily/task/resize_task.rb
168
+ - lib/sicily/version.rb
169
+ - sicily.gemspec
170
+ homepage: https://github.com/eunjae-lee/sicily
171
+ licenses:
172
+ - MIT
173
+ metadata: {}
174
+ post_install_message: |2+
175
+
176
+
177
+ To finish installation, please execute the following:
178
+ $ npm install -g upload-gphotos
179
+
180
+
181
+ rdoc_options: []
182
+ require_paths:
183
+ - lib
184
+ required_ruby_version: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - ">="
187
+ - !ruby/object:Gem::Version
188
+ version: '0'
189
+ required_rubygems_version: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ requirements: []
195
+ rubyforge_project:
196
+ rubygems_version: 2.6.11
197
+ signing_key:
198
+ specification_version: 4
199
+ summary: A rule-based photo organizer written in Ruby
200
+ test_files: []