sicily 0.1.6 → 0.1.7
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 +4 -1
- data/CHANGELOG.md +9 -6
- data/Gemfile.lock +1 -1
- data/exe/sicily +5 -24
- data/generator/application.rb +16 -0
- data/generator/google_photo.rb +1 -2
- data/generator/rules.rb +0 -2
- data/lib/sicily.rb +4 -43
- data/lib/sicily/batch_processor.rb +2 -2
- data/lib/sicily/config.rb +21 -5
- data/lib/sicily/generator.rb +15 -4
- data/lib/sicily/monitor.rb +1 -1
- data/lib/sicily/monitor_wrapper.rb +45 -0
- data/lib/sicily/task/file_task.rb +2 -0
- data/lib/sicily/task_loader.rb +4 -0
- data/lib/sicily/util/file_util.rb +11 -5
- data/lib/sicily/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7094d97b1de208a0611c56df43b83fd88e4c8b13
|
4
|
+
data.tar.gz: f53c938f8af3acb212eeb532b673bb7deeec62e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: caa5b53a90727e9df8300b7ad288dd865c58f6e82f0b0f664d550d400adbee72c4c1d101ded387f03c05887760325dda7e9ccee8381699a13851a3c031418731
|
7
|
+
data.tar.gz: 7c6dd99942a135234e7ba9392f30daca58c422cd2402d7a6d1b4aff42149b9fb40a396c5de54c92027a0fb56f980467c5ec8758f8a2809a54657f07bb7376426
|
data/.rubocop.yml
CHANGED
@@ -14,4 +14,7 @@ Metrics/MethodLength:
|
|
14
14
|
Metrics/ParameterLists:
|
15
15
|
Max: 4
|
16
16
|
Style/GlobalVars:
|
17
|
-
AllowedVariables: ['$SICILY_LOG_TO_FILE']
|
17
|
+
AllowedVariables: ['$SICILY_LOG_TO_FILE', '$SICILY_LOAD_USER_CONFIGS']
|
18
|
+
Lint/RescueException:
|
19
|
+
Exclude:
|
20
|
+
- 'lib/sicily/batch_processor.rb'
|
data/CHANGELOG.md
CHANGED
@@ -1,25 +1,28 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.1.7
|
4
|
+
* Fix a bug that getting wrong creation time of file.
|
5
|
+
|
3
6
|
## 0.1.6
|
4
7
|
* It consumes already existing files on start-up.
|
5
8
|
|
6
9
|
## 0.1.5
|
7
|
-
* It waits 10 seconds before taking actions in case when file is still changing
|
10
|
+
* It waits 10 seconds before taking actions in case when file is still changing.
|
8
11
|
|
9
12
|
## 0.1.4
|
10
|
-
* Add required ruby version
|
13
|
+
* Add required ruby version.
|
11
14
|
* It's now easy to add new generator.
|
12
15
|
|
13
16
|
## 0.1.3
|
14
17
|
* It's now easy to create new task.
|
15
18
|
|
16
19
|
## 0.1.2
|
17
|
-
* Add `rm
|
20
|
+
* Add `rm`.
|
18
21
|
|
19
22
|
## 0.1.1
|
20
|
-
* Extract time and use it for evaluating dest path
|
23
|
+
* Extract time and use it for evaluating dest path.
|
21
24
|
* ex> `~/dest_folder/%Y/%m/%d`
|
22
|
-
* Add `cp
|
25
|
+
* Add `cp`.
|
23
26
|
|
24
27
|
## 0.1.0
|
25
|
-
Initial deployment
|
28
|
+
Initial deployment.
|
data/Gemfile.lock
CHANGED
data/exe/sicily
CHANGED
@@ -5,18 +5,15 @@
|
|
5
5
|
$SICILY_LOG_TO_FILE = (ENV['SICILY_LOG'] == 'file')
|
6
6
|
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), ['..', 'lib'])
|
7
7
|
|
8
|
-
require 'sicily'
|
9
|
-
|
10
8
|
command = ARGV[0]
|
11
9
|
|
10
|
+
$SICILY_LOAD_USER_CONFIGS = (command == 'monitor')
|
11
|
+
|
12
|
+
require 'sicily'
|
13
|
+
|
12
14
|
case command
|
13
15
|
when 'generate'
|
14
16
|
require 'fileutils'
|
15
|
-
require 'sicily/generator'
|
16
|
-
|
17
|
-
Dir['./generator/*.rb'].each do |file|
|
18
|
-
require file
|
19
|
-
end
|
20
17
|
|
21
18
|
FileUtils.rm_rf './config'
|
22
19
|
FileUtils.mkdir_p './config'
|
@@ -40,23 +37,7 @@ when 'generate'
|
|
40
37
|
puts messages_to_display.join('\n')
|
41
38
|
end
|
42
39
|
when 'monitor'
|
43
|
-
|
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
|
-
|
40
|
+
load './config/rules.rb'
|
60
41
|
sleep
|
61
42
|
when 'start'
|
62
43
|
command1 = 'whenever --load-file ./config/.schedule.rb --update-crontab'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sicily
|
4
|
+
Sicily.register_generator do |generator|
|
5
|
+
generator.filename = '.application.rb'
|
6
|
+
generator.load_on_start = true
|
7
|
+
generator.content = <<~CONTENT
|
8
|
+
Sicily.configure do |config|
|
9
|
+
config.forbid_new_file_in_subfolder = true
|
10
|
+
config.num_thread_pool = 10
|
11
|
+
config.delay_on_file_monitoring = 10
|
12
|
+
config.consume_on_start = true
|
13
|
+
end
|
14
|
+
CONTENT
|
15
|
+
end
|
16
|
+
end
|
data/generator/google_photo.rb
CHANGED
@@ -3,9 +3,8 @@
|
|
3
3
|
module Sicily
|
4
4
|
Sicily.register_generator do |generator|
|
5
5
|
generator.filename = 'google_photo.rb'
|
6
|
+
generator.load_on_start = true
|
6
7
|
generator.content = <<~CONTENT
|
7
|
-
# frozen_string_literal: true
|
8
|
-
|
9
8
|
Sicily.configure_google do |config|
|
10
9
|
config.id = 'your id'
|
11
10
|
config.pw = 'your pw'
|
data/generator/rules.rb
CHANGED
data/lib/sicily.rb
CHANGED
@@ -4,54 +4,15 @@ require 'sicily/version'
|
|
4
4
|
require 'sicily/logger'
|
5
5
|
require 'sicily/config'
|
6
6
|
require 'sicily/monitor'
|
7
|
+
require 'sicily/monitor_wrapper'
|
8
|
+
require 'sicily/generator'
|
7
9
|
require 'sicily/util/file_util'
|
8
10
|
require 'sicily/task_loader'
|
9
11
|
require 'sicily/error/monitor_error'
|
10
12
|
|
11
13
|
module Sicily
|
12
|
-
|
13
|
-
|
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
|
23
|
-
end
|
24
|
-
|
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
|
35
|
-
|
36
|
-
def self.store_monitored_path(path)
|
37
|
-
@monitored_paths << File.expand_path(path)
|
38
|
-
end
|
39
|
-
|
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
|
14
|
+
Sicily.load_all_tasks
|
15
|
+
Sicily.load_all_configs
|
55
16
|
|
56
17
|
def self.on(path, &user_rule_block)
|
57
18
|
MonitorWrapper.on path, &user_rule_block
|
@@ -48,8 +48,8 @@ module Sicily
|
|
48
48
|
file_processor = FileProcessor.new(file)
|
49
49
|
file_processor.instance_eval(&user_rule_block)
|
50
50
|
file_processor.info 'Done'
|
51
|
-
rescue
|
52
|
-
Sicily.logger.error e.
|
51
|
+
rescue Exception => e
|
52
|
+
Sicily.logger.error e.inspect
|
53
53
|
end
|
54
54
|
|
55
55
|
def notify_done
|
data/lib/sicily/config.rb
CHANGED
@@ -6,18 +6,34 @@ module Sicily
|
|
6
6
|
end
|
7
7
|
|
8
8
|
class Config
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
attr_accessor :forbid_new_file_in_subfolder,
|
10
|
+
:num_thread_pool,
|
11
|
+
:delay_on_file_monitoring,
|
12
|
+
:consume_on_start
|
13
13
|
|
14
14
|
def initialize
|
15
15
|
@forbid_new_file_in_subfolder = true
|
16
|
-
@num_thread_pool =
|
16
|
+
@num_thread_pool = 10
|
17
17
|
@delay_on_file_monitoring = 10
|
18
18
|
@consume_on_start = true
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
Sicily.config = Config.new
|
23
|
+
|
24
|
+
def self.configure(&block)
|
25
|
+
block.call Sicily.config if block_given?
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.load_all_configs
|
29
|
+
return unless $SICILY_LOAD_USER_CONFIGS
|
30
|
+
|
31
|
+
Sicily.logger.debug "#{Sicily.generators.size} generators found."
|
32
|
+
Sicily.generators.each do |generator|
|
33
|
+
path = File.expand_path "#{File.dirname(__FILE__)}/../../config/#{generator.filename}"
|
34
|
+
next unless generator.load_on_start
|
35
|
+
Sicily.logger.debug "ConfigLoader : #{path}"
|
36
|
+
load path
|
37
|
+
end
|
38
|
+
end
|
23
39
|
end
|
data/lib/sicily/generator.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Sicily
|
4
|
-
class Generator
|
5
|
-
attr_accessor :filename, :content, :post_generate_message
|
6
|
-
end
|
7
|
-
|
8
4
|
class << self
|
9
5
|
attr_accessor :generators
|
10
6
|
end
|
7
|
+
|
11
8
|
Sicily.generators = []
|
12
9
|
|
10
|
+
class Generator
|
11
|
+
attr_accessor :filename, :content, :post_generate_message, :load_on_start
|
12
|
+
end
|
13
|
+
|
13
14
|
def self.register_generator(&block)
|
14
15
|
return unless block_given?
|
15
16
|
|
@@ -17,4 +18,14 @@ module Sicily
|
|
17
18
|
block.call generator
|
18
19
|
Sicily.generators << generator
|
19
20
|
end
|
21
|
+
|
22
|
+
def self.load_generators
|
23
|
+
Dir["#{File.dirname(__FILE__)}/../../generator/*.rb"].each do |file|
|
24
|
+
file = File.expand_path file
|
25
|
+
Sicily.logger.debug "Load generator : #{file}"
|
26
|
+
require file
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
load_generators
|
20
31
|
end
|
data/lib/sicily/monitor.rb
CHANGED
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Sicily
|
4
|
+
class MonitorWrapper
|
5
|
+
@monitored_paths = []
|
6
|
+
|
7
|
+
def self.on(path, &user_rule_block)
|
8
|
+
if can_monitor?(@monitored_paths, path)
|
9
|
+
store_path_and_start_monitor(path, &user_rule_block)
|
10
|
+
else
|
11
|
+
Sicily.logger.error "Monitor Failed. Path duplicated : #{path}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.store_path_and_start_monitor(path, &user_rule_block)
|
16
|
+
store_monitored_path(path)
|
17
|
+
start_monitor!(path, &user_rule_block)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.start_monitor!(path, &user_rule_block)
|
21
|
+
Monitor.new.on(path, &user_rule_block)
|
22
|
+
rescue MonitorError => e
|
23
|
+
Sicily.logger.error e.inspect
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.store_monitored_path(path)
|
27
|
+
@monitored_paths << File.expand_path(path)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.can_monitor?(prev_paths, new_path)
|
31
|
+
prev_paths.each do |prev_path|
|
32
|
+
return false if somehow_related?(prev_path, new_path)
|
33
|
+
end
|
34
|
+
|
35
|
+
true
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.somehow_related?(path1, path2)
|
39
|
+
parent_child_relationship = Util::FileUtil.related?(path1, path2)
|
40
|
+
child_parent_relationship = Util::FileUtil.related?(path2, path1)
|
41
|
+
|
42
|
+
parent_child_relationship || child_parent_relationship
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -37,12 +37,14 @@ module Sicily
|
|
37
37
|
def mv(path_dest)
|
38
38
|
info "mv to #{path_dest}"
|
39
39
|
path_dest = Base.prepare_dest_path(@path, path_dest)
|
40
|
+
info " #{path_dest}"
|
40
41
|
FileUtils.mv @path, path_dest
|
41
42
|
end
|
42
43
|
|
43
44
|
def cp(path_dest)
|
44
45
|
info "cp to #{path_dest}"
|
45
46
|
path_dest = Base.prepare_dest_path(@path, path_dest)
|
47
|
+
info " #{path_dest}"
|
46
48
|
FileUtils.cp @path, path_dest
|
47
49
|
end
|
48
50
|
|
data/lib/sicily/task_loader.rb
CHANGED
@@ -19,12 +19,18 @@ module Sicily
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def self.extract_time(path)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
exif_time = jpeg?(path) && ExifUtil.extract_time_from_jpeg(path)
|
23
|
+
exif_time || extract_time_from_file_stat(path)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.jpeg?(path)
|
27
|
+
%w[.jpg .jpeg].include? File.extname(path).downcase
|
28
|
+
end
|
26
29
|
|
27
|
-
|
30
|
+
def self.extract_time_from_file_stat(path)
|
31
|
+
File.birthtime(path)
|
32
|
+
rescue NotImplementedError
|
33
|
+
File.mtime(path)
|
28
34
|
end
|
29
35
|
end
|
30
36
|
end
|
data/lib/sicily/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Eunjae Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -187,6 +187,7 @@ files:
|
|
187
187
|
- bin/console
|
188
188
|
- bin/setup
|
189
189
|
- exe/sicily
|
190
|
+
- generator/application.rb
|
190
191
|
- generator/god.rb
|
191
192
|
- generator/google_photo.rb
|
192
193
|
- generator/rules.rb
|
@@ -199,6 +200,7 @@ files:
|
|
199
200
|
- lib/sicily/generator.rb
|
200
201
|
- lib/sicily/logger.rb
|
201
202
|
- lib/sicily/monitor.rb
|
203
|
+
- lib/sicily/monitor_wrapper.rb
|
202
204
|
- lib/sicily/task/dummy_task.rb
|
203
205
|
- lib/sicily/task/file_task.rb
|
204
206
|
- lib/sicily/task/google_photo_task.rb
|