sicily 0.1.4 → 0.1.5
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 +4 -4
- data/.rubocop.yml +17 -0
- data/.ruby-version +1 -1
- data/Gemfile +4 -2
- data/Gemfile.lock +1 -1
- data/README.md +11 -6
- data/Rakefile +5 -3
- data/bin/console +6 -4
- data/exe/sicily +69 -69
- data/generator/god.rb +12 -10
- data/generator/google_photo.rb +18 -14
- data/generator/rules.rb +22 -13
- data/generator/schedule.rb +10 -8
- data/lib/sicily.rb +48 -22
- data/lib/sicily/batch_processor.rb +47 -26
- data/lib/sicily/config.rb +6 -4
- data/lib/sicily/error/monitor_error.rb +6 -0
- data/lib/sicily/file_processor.rb +9 -1
- data/lib/sicily/generator.rb +3 -1
- data/lib/sicily/logger.rb +51 -0
- data/lib/sicily/monitor.rb +26 -8
- data/lib/sicily/task/dummy_task.rb +4 -2
- data/lib/sicily/task/file_task.rb +24 -13
- data/lib/sicily/task/google_photo_task.rb +33 -10
- data/lib/sicily/task/resize_task.rb +11 -11
- data/lib/sicily/task_loader.rb +30 -10
- data/lib/sicily/util/exif_util.rb +4 -2
- data/lib/sicily/util/file_util.rb +10 -7
- data/lib/sicily/util/image_util.rb +3 -1
- data/lib/sicily/util/notification_util.rb +19 -6
- data/lib/sicily/version.rb +3 -1
- data/sicily.gemspec +34 -35
- metadata +37 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a629cc27f49bb182ca951daf71ea7ee3d2331d5
|
4
|
+
data.tar.gz: 234f34293f5ed0c91de1faf3edf057fb7fc2aaca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d2374a89542c67d991116e4cba6cffb3328d94f091e68fbacc023c7a6901e299090761d3e7d75b89723fc0a363471f9e3daf9832d1be87c90871294ec551441
|
7
|
+
data.tar.gz: 51f67a612250656c27aeaf0b1a744c5201aa759ebd6e586ee99df6bcf0de7a740057c6730fdbe30a70fb6b33a2e6659e6270360c9699744d4037a6d8302f65d4
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Documentation:
|
2
|
+
Enabled: false
|
3
|
+
Metrics/LineLength:
|
4
|
+
Max: 100
|
5
|
+
Metrics/BlockLength:
|
6
|
+
Exclude:
|
7
|
+
- 'sicily.gemspec'
|
8
|
+
- "**/*_spec.rb"
|
9
|
+
Metrics/ModuleLength:
|
10
|
+
Exclude:
|
11
|
+
- "**/*_spec.rb"
|
12
|
+
Metrics/MethodLength:
|
13
|
+
Max: 5
|
14
|
+
Metrics/ParameterLists:
|
15
|
+
Max: 4
|
16
|
+
Style/GlobalVars:
|
17
|
+
AllowedVariables: ['$SICILY_LOG_TO_FILE']
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.3.1
|
data/Gemfile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
6
|
|
5
7
|
# Specify your gem's dependencies in sicily.gemspec
|
6
8
|
gemspec
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -34,24 +34,29 @@ Go to your project path, and then execute:
|
|
34
34
|
|
35
35
|
### Modify the generated files
|
36
36
|
|
37
|
-
|
37
|
+
`./config/google_photo.rb`
|
38
38
|
|
39
39
|
Sicily.configure_google do |config|
|
40
40
|
config.id = "your id"
|
41
41
|
config.pw = "your pw"
|
42
42
|
end
|
43
43
|
|
44
|
-
|
44
|
+
`./config/rules.rb`
|
45
45
|
|
46
|
-
Sicily.on
|
46
|
+
Sicily.on '~/your_folder' do
|
47
47
|
fit_if_photo 2000, 2000
|
48
48
|
google_photo
|
49
|
-
mv
|
49
|
+
mv '~/your_another_folder/%Y/%m/%d'
|
50
50
|
end
|
51
51
|
|
52
|
-
Sicily.on
|
52
|
+
Sicily.on '~/your_folder2' do
|
53
53
|
fit_if_photo 1000, 1000
|
54
|
-
cp
|
54
|
+
cp '~/your_another_folder/%Y/%m/%d'
|
55
|
+
end
|
56
|
+
|
57
|
+
Sicily.on '~/your_folder3' do
|
58
|
+
google_photo
|
59
|
+
rm
|
55
60
|
end
|
56
61
|
|
57
62
|
### Start & Stop
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
require 'bundler/setup'
|
6
|
+
require 'sicily'
|
5
7
|
|
6
8
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
9
|
# with your gem easier. You can also use a different console, if you like.
|
8
10
|
|
9
11
|
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require
|
12
|
+
# require 'pry'
|
11
13
|
# Pry.start
|
12
14
|
|
13
|
-
require
|
15
|
+
require 'irb'
|
14
16
|
IRB.start(__FILE__)
|
data/exe/sicily
CHANGED
@@ -1,84 +1,84 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
3
|
+
# frozen_string_literal: true
|
4
4
|
|
5
|
-
|
5
|
+
$SICILY_LOG_TO_FILE = (ENV['SICILY_LOG'] == 'file')
|
6
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), ['..', 'lib'])
|
6
7
|
|
8
|
+
require 'sicily'
|
7
9
|
|
8
10
|
command = ARGV[0]
|
9
11
|
|
10
12
|
case command
|
11
|
-
|
12
|
-
|
13
|
-
|
13
|
+
when 'generate'
|
14
|
+
require 'fileutils'
|
15
|
+
require 'sicily/generator'
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
|
17
|
+
Dir['./generator/*.rb'].each do |file|
|
18
|
+
require file
|
19
|
+
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
+
FileUtils.rm_rf './config'
|
22
|
+
FileUtils.mkdir_p './config'
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
files_to_edit = Sicily.generators.map { |t| t.filename }.select { |t| not t.start_with?(".") }
|
27
|
-
messages_to_display = Sicily.generators.map { |t| t.post_generate_message }.select { |t| not t.to_s.empty? }
|
24
|
+
Sicily.generators.each do |generator|
|
25
|
+
File.write("./config/#{generator.filename}", generator.content)
|
26
|
+
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
files_to_edit.each do |file|
|
32
|
-
puts " ./config/#{file}"
|
33
|
-
end
|
34
|
-
end
|
28
|
+
files_to_edit = Sicily.generators.map(&:filename).reject { |t| t.start_with?('.') }
|
29
|
+
messages_to_display = Sicily.generators.map(&:post_generate_message).reject { |t| t.to_s.empty? }
|
35
30
|
|
36
|
-
|
37
|
-
|
38
|
-
|
31
|
+
unless files_to_edit.empty?
|
32
|
+
puts 'Try edit the following files:'
|
33
|
+
files_to_edit.each do |file|
|
34
|
+
puts " ./config/#{file}"
|
39
35
|
end
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
36
|
+
end
|
37
|
+
|
38
|
+
unless messages_to_display.empty?
|
39
|
+
puts ''
|
40
|
+
puts messages_to_display.join('\n')
|
41
|
+
end
|
42
|
+
when 'monitor'
|
43
|
+
`echo test >> monitor.log`
|
44
|
+
necessary_config_files = ['rules.rb']
|
45
|
+
config_files_to_load = ['google_photo.rb', 'rules.rb']
|
46
|
+
|
47
|
+
necessary_config_files.each do |file|
|
48
|
+
next if File.exist? "./config/#{file}"
|
49
|
+
|
50
|
+
puts "./config/#{file} is missing!"
|
51
|
+
puts ' Type: `sicily generate`'
|
52
|
+
exit
|
53
|
+
end
|
54
|
+
|
55
|
+
config_files_to_load.each do |filename|
|
56
|
+
path = "./config/#{filename}"
|
57
|
+
load(path) if File.exist?(path)
|
58
|
+
end
|
59
|
+
|
60
|
+
sleep
|
61
|
+
when 'start'
|
62
|
+
command1 = 'whenever --load-file ./config/.schedule.rb --update-crontab'
|
63
|
+
`#{command1}`
|
64
|
+
|
65
|
+
god_file = File.expand_path('./config/.sicily.god')
|
66
|
+
command2 = "god -c #{god_file}"
|
67
|
+
`#{command2}`
|
68
|
+
when 'stop'
|
69
|
+
`god stop sicily`
|
70
|
+
`whenever --load-file ./config/.schedule.rb --clear-crontab`
|
71
|
+
else
|
72
|
+
banner = <<~BANNER
|
73
|
+
Usage:
|
74
|
+
Generating config files:
|
75
|
+
sicily generate
|
76
|
+
Start monitoring in this terminal session:
|
77
|
+
sicily monitor
|
78
|
+
Start monitoring forever:
|
79
|
+
sicily start
|
80
|
+
Stop monitoring forever:
|
81
|
+
sicily stop
|
82
|
+
BANNER
|
83
|
+
puts banner
|
82
84
|
end
|
83
|
-
|
84
|
-
|
data/generator/god.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Sicily
|
2
4
|
Sicily.register_generator do |generator|
|
3
|
-
generator.filename =
|
4
|
-
generator.content =
|
5
|
-
God.watch do |w|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
11
|
-
|
5
|
+
generator.filename = '.sicily.god'
|
6
|
+
generator.content = <<~CONTENT
|
7
|
+
God.watch do |w|
|
8
|
+
w.name = 'sicily'
|
9
|
+
w.start = 'SICILY_LOG=file sicily monitor'
|
10
|
+
w.dir = File.expand_path("\#{File.dirname(__FILE__)}/..")
|
11
|
+
w.keepalive
|
12
|
+
end
|
13
|
+
CONTENT
|
12
14
|
end
|
13
|
-
end
|
15
|
+
end
|
data/generator/google_photo.rb
CHANGED
@@ -1,17 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Sicily
|
2
4
|
Sicily.register_generator do |generator|
|
3
|
-
generator.filename =
|
4
|
-
generator.content =
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
5
|
+
generator.filename = 'google_photo.rb'
|
6
|
+
generator.content = <<~CONTENT
|
7
|
+
# frozen_string_literal: true
|
8
|
+
|
9
|
+
Sicily.configure_google do |config|
|
10
|
+
config.id = 'your id'
|
11
|
+
config.pw = 'your pw'
|
12
|
+
end
|
13
|
+
CONTENT
|
14
|
+
generator.post_generate_message = <<~MESSAGE
|
15
|
+
To upload to Google Photos,
|
16
|
+
turn on "Allowing less secure apps to access your account"
|
17
|
+
: https://support.google.com/accounts/answer/6010255
|
18
|
+
*USE AT YOUR OWN RISK*
|
19
|
+
MESSAGE
|
16
20
|
end
|
17
|
-
end
|
21
|
+
end
|
data/generator/rules.rb
CHANGED
@@ -1,17 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Sicily
|
2
4
|
Sicily.register_generator do |generator|
|
3
|
-
generator.filename =
|
4
|
-
generator.content =
|
5
|
-
|
6
|
-
fit_if_photo 2000, 2000
|
7
|
-
google_photo
|
8
|
-
mv "~/your_another_folder/%Y/%m/%d"
|
9
|
-
end
|
5
|
+
generator.filename = 'rules.rb'
|
6
|
+
generator.content = <<~CONTENT
|
7
|
+
# frozen_string_literal: true
|
10
8
|
|
11
|
-
Sicily.on
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
Sicily.on '~/your_folder' do
|
10
|
+
fit_if_photo 2000, 2000
|
11
|
+
google_photo
|
12
|
+
mv '~/your_another_folder/%Y/%m/%d'
|
13
|
+
end
|
14
|
+
|
15
|
+
Sicily.on '~/your_folder2' do
|
16
|
+
fit_if_photo 1000, 1000
|
17
|
+
cp '~/your_another_folder/%Y/%m/%d'
|
18
|
+
end
|
19
|
+
|
20
|
+
Sicily.on '~/your_folder3' do
|
21
|
+
google_photo
|
22
|
+
rm
|
23
|
+
end
|
24
|
+
CONTENT
|
16
25
|
end
|
17
|
-
end
|
26
|
+
end
|
data/generator/schedule.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Sicily
|
2
4
|
Sicily.register_generator do |generator|
|
3
|
-
generator.filename =
|
4
|
-
generator.content =
|
5
|
-
every :hour do
|
6
|
-
|
7
|
-
|
8
|
-
end
|
9
|
-
|
5
|
+
generator.filename = '.schedule.rb'
|
6
|
+
generator.content = <<~CONTENT
|
7
|
+
every :hour do
|
8
|
+
god_file = File.expand_path("\#{File.dirname(__FILE__)}/.sicily.god")
|
9
|
+
command "god -c \#{god_file}"
|
10
|
+
end
|
11
|
+
CONTENT
|
10
12
|
end
|
11
|
-
end
|
13
|
+
end
|
data/lib/sicily.rb
CHANGED
@@ -1,33 +1,59 @@
|
|
1
|
-
|
2
|
-
require "sicily/config"
|
3
|
-
require "sicily/monitor"
|
4
|
-
require "sicily/util/file_util"
|
5
|
-
require "sicily/task_loader"
|
1
|
+
# frozen_string_literal: true
|
6
2
|
|
7
|
-
|
8
|
-
|
3
|
+
require 'sicily/version'
|
4
|
+
require 'sicily/logger'
|
5
|
+
require 'sicily/config'
|
6
|
+
require 'sicily/monitor'
|
7
|
+
require 'sicily/util/file_util'
|
8
|
+
require 'sicily/task_loader'
|
9
|
+
require 'sicily/error/monitor_error'
|
9
10
|
|
11
|
+
module Sicily
|
10
12
|
TaskLoader.new.load_all_tasks
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
class MonitorWrapper
|
15
|
+
@monitored_paths = []
|
16
|
+
|
17
|
+
def self.on(path, &user_rule_block)
|
18
|
+
if can_monitor?(@monitored_paths, path)
|
19
|
+
store_path_and_start_monitor(path, &user_rule_block)
|
20
|
+
else
|
21
|
+
Sicily.logger.error "Monitor Failed. Path duplicated : #{path}"
|
22
|
+
end
|
17
23
|
end
|
18
|
-
end
|
19
24
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
25
|
+
def self.store_path_and_start_monitor(path, &user_rule_block)
|
26
|
+
store_monitored_path(path)
|
27
|
+
start_monitor!(path, &user_rule_block)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.start_monitor!(path, &user_rule_block)
|
31
|
+
Monitor.new.on(path, &user_rule_block)
|
32
|
+
rescue MonitorError => e
|
33
|
+
Sicily.logger.error e.message
|
34
|
+
end
|
24
35
|
|
25
|
-
|
26
|
-
|
27
|
-
return false if Util::FileUtil.is_related?(prev_path, new_path) ||
|
28
|
-
Util::FileUtil.is_related?(new_path, prev_path)
|
36
|
+
def self.store_monitored_path(path)
|
37
|
+
@monitored_paths << File.expand_path(path)
|
29
38
|
end
|
30
39
|
|
31
|
-
|
40
|
+
def self.can_monitor?(prev_paths, new_path)
|
41
|
+
prev_paths.each do |prev_path|
|
42
|
+
return false if somehow_related?(prev_path, new_path)
|
43
|
+
end
|
44
|
+
|
45
|
+
true
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.somehow_related?(path1, path2)
|
49
|
+
parent_child_relationship = Util::FileUtil.related?(path1, path2)
|
50
|
+
child_parent_relationship = Util::FileUtil.related?(path2, path1)
|
51
|
+
|
52
|
+
parent_child_relationship || child_parent_relationship
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.on(path, &user_rule_block)
|
57
|
+
MonitorWrapper.on path, &user_rule_block
|
32
58
|
end
|
33
59
|
end
|