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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c3b5be431300e6ce68436d6126064a6187563139
4
- data.tar.gz: fa017687e400cf32704eb3bbc4476e7315165b2f
3
+ metadata.gz: 4a629cc27f49bb182ca951daf71ea7ee3d2331d5
4
+ data.tar.gz: 234f34293f5ed0c91de1faf3edf057fb7fc2aaca
5
5
  SHA512:
6
- metadata.gz: e8b827f0e3f9aa7278a596185cd8bbf30d62af0ea02c9e6937befc6a23a6a27d4d5ad6b65fcc1e19ce89bfde7bf8428b4fc5eea834c3396393ae159f945abbdd
7
- data.tar.gz: 5a41679daa4924a591c7c66160f2aae3d26744423b880f2cd0eceb9b8094a14c697598ae72d5dd4a1bd50b39048351572dde148d6eb5131c5e0fa2eb083de548
6
+ metadata.gz: 6d2374a89542c67d991116e4cba6cffb3328d94f091e68fbacc023c7a6901e299090761d3e7d75b89723fc0a363471f9e3daf9832d1be87c90871294ec551441
7
+ data.tar.gz: 51f67a612250656c27aeaf0b1a744c5201aa759ebd6e586ee99df6bcf0de7a740057c6730fdbe30a70fb6b33a2e6659e6270360c9699744d4037a6d8302f65d4
@@ -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']
@@ -1 +1 @@
1
- 2.4.1
1
+ 2.3.1
data/Gemfile CHANGED
@@ -1,6 +1,8 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sicily (0.1.4)
4
+ sicily (0.1.5)
5
5
  concurrent-ruby (~> 1.0.5)
6
6
  exifr (~> 1.3.3)
7
7
  fastimage (~> 2.1.1)
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
- ./config/google_photo.rb
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
- ./config/rules.rb
44
+ `./config/rules.rb`
45
45
 
46
- Sicily.on "~/your_folder" do
46
+ Sicily.on '~/your_folder' do
47
47
  fit_if_photo 2000, 2000
48
48
  google_photo
49
- mv "~/your_another_folder/%Y/%m/%d"
49
+ mv '~/your_another_folder/%Y/%m/%d'
50
50
  end
51
51
 
52
- Sicily.on "~/your_folder2" do
52
+ Sicily.on '~/your_folder2' do
53
53
  fit_if_photo 1000, 1000
54
- cp "~/your_another_folder/%Y/%m/%d"
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
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
@@ -1,14 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "sicily"
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 "pry"
12
+ # require 'pry'
11
13
  # Pry.start
12
14
 
13
- require "irb"
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
- $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
3
+ # frozen_string_literal: true
4
4
 
5
- require "sicily"
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
- when "generate"
12
- require "fileutils"
13
- require "sicily/generator"
13
+ when 'generate'
14
+ require 'fileutils'
15
+ require 'sicily/generator'
14
16
 
15
- Dir["./generator/*.rb"].each {|file|
16
- require file
17
- }
17
+ Dir['./generator/*.rb'].each do |file|
18
+ require file
19
+ end
18
20
 
19
- FileUtils.rm_rf "./config"
20
- FileUtils.mkdir_p "./config"
21
+ FileUtils.rm_rf './config'
22
+ FileUtils.mkdir_p './config'
21
23
 
22
- Sicily.generators.each do |generator|
23
- File.write("./config/#{generator.filename}", generator.content)
24
- end
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
- if files_to_edit.size > 0
30
- puts "Try edit the following files:"
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
- if messages_to_display.size > 0
37
- puts ""
38
- puts messages_to_display.join("\n")
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
- when "monitor"
41
- `echo test >> monitor.log`
42
- necessary_config_files = ["rules.rb"]
43
- config_files_to_load = ["google_photo.rb", "rules.rb"]
44
-
45
- necessary_config_files.each { |file|
46
- unless File.exists? "./config/#{file}"
47
- puts "./config/#{file} is missing!"
48
- puts " Type: `sicily generate`"
49
- exit
50
- end
51
- }
52
-
53
- config_files_to_load.each { |filename|
54
- path = "./config/#{filename}"
55
- load(path) if File.exists?(path)
56
- }
57
-
58
- sleep
59
- when "start"
60
- command1 = "whenever --load-file ./config/.schedule.rb --update-crontab"
61
- `#{command1}`
62
-
63
- god_file = File.expand_path("./config/.sicily.god")
64
- command2 = "god -c #{god_file}"
65
- `#{command2}`
66
- when "stop"
67
- `god stop sicily`
68
- `whenever --load-file ./config/.schedule.rb --clear-crontab`
69
- else
70
- banner = <<-EOF
71
- Usage:
72
- Generating config files:
73
- sicily generate
74
- Start monitoring in this terminal session:
75
- sicily monitor
76
- Start monitoring forever:
77
- sicily start
78
- Stop monitoring forever:
79
- sicily stop
80
- EOF
81
- puts banner
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
-
@@ -1,13 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Sicily
2
4
  Sicily.register_generator do |generator|
3
- generator.filename = ".sicily.god"
4
- generator.content = <<-EOF
5
- God.watch do |w|
6
- w.name = "sicily"
7
- w.start = "sicily monitor"
8
- w.dir = File.expand_path("\#{File.dirname(__FILE__)}/..")
9
- w.keepalive
10
- end
11
- EOF
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
@@ -1,17 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Sicily
2
4
  Sicily.register_generator do |generator|
3
- generator.filename = "google_photo.rb"
4
- generator.content = <<-EOF
5
- Sicily.configure_google do |config|
6
- config.id = "your id"
7
- config.pw = "your pw"
8
- end
9
- EOF
10
- generator.post_generate_message = <<-EOF
11
- To upload to Google Photos,
12
- turn on "Allowing less secure apps to access your account"
13
- : https://support.google.com/accounts/answer/6010255
14
- *USE AT YOUR OWN RISK*
15
- EOF
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
@@ -1,17 +1,26 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Sicily
2
4
  Sicily.register_generator do |generator|
3
- generator.filename = "rules.rb"
4
- generator.content = <<-EOF
5
- Sicily.on "~/your_folder" do
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 "~/your_folder2" do
12
- fit_if_photo 1000, 1000
13
- cp "~/your_another_folder/%Y/%m/%d"
14
- end
15
- EOF
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
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Sicily
2
4
  Sicily.register_generator do |generator|
3
- generator.filename = ".schedule.rb"
4
- generator.content = <<-EOF
5
- every :hour do
6
- god_file = File.expand_path("\#{File.dirname(__FILE__)}/.sicily.god")
7
- command "god -c \#{god_file}"
8
- end
9
- EOF
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
@@ -1,33 +1,59 @@
1
- require "sicily/version"
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
- module Sicily
8
- @monitored_paths = []
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
- def self.on(path, &block)
13
- if self.can_monitor?(@monitored_paths, path)
14
- self.start_monitor!(path, &block)
15
- else
16
- puts "cannot monitor : #{path}"
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
- def self.start_monitor!(path, &block)
21
- @monitored_paths << File.expand_path(path)
22
- Monitor.new.on(path, &block)
23
- end
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
- def self.can_monitor?(prev_paths, new_path)
26
- prev_paths.each do |prev_path|
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
- true
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