dutiful 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7c4ff77357fdd7e791b53d6f82c7cbef2940a2f1
4
- data.tar.gz: 2d3bcf04350bb48e0f41f8ad04395b54024547bc
3
+ metadata.gz: 2e0b17aa6b4926b3c741b9178b4081ef72ed5684
4
+ data.tar.gz: 0deafa16d607c75dec399bba7a8cb102468b3a35
5
5
  SHA512:
6
- metadata.gz: 80a690af56ded5e3278396feda4da1aa49744012f7169b19089673492a9a8cade27a8a6ee2c757bb5d2e6d17ebd1209671f28ba5942ec67c71f8cb143d05e907
7
- data.tar.gz: 3f0234c53031fc8020aa4ed1c43356f830606aec3651b1e23521d2264a8e8f13a01eee3b702d81e7a4bb1c4d0ac070062aea29c277582ba4e4b2d07d9def0bcc
6
+ metadata.gz: 93094fe71f0c948abf0f553bcd02a7284fe30e22ef25105787b24245e57d631385d0cc41fa6dc46dfa8a0c19d4df4adf1f2279c2b1209a4cda2d983bc0c8d636
7
+ data.tar.gz: f9605865f58cc59cc49a636763bbcb0dca10d15d2c71531c52c4cfb6f4c5a3c2ef3d1310f7bb16d7bdb81b4d7d79fceaecc82ab2eeaf2c6020e2e815de829bbd
@@ -3,26 +3,33 @@ class Dutiful::Application
3
3
  @path = path
4
4
  end
5
5
 
6
- def name
7
- content[:application][:name]
8
- end
9
-
10
6
  def files
11
7
  content[:file].map { |file| Dutiful::ApplicationFile.new file[:path], file[:condition] }
12
8
  end
13
9
 
14
- def exist?
15
- files.any? &:exist?
10
+ def name
11
+ content[:application][:name]
16
12
  end
17
13
 
18
- def has_backup?
19
- files.any? &:has_backup?
14
+ def backup(&block)
15
+ sync backup_only: true, &block
20
16
  end
21
17
 
22
- def sync
18
+ def restore(&block)
19
+ sync restore_only: true, &block
20
+ end
21
+
22
+ def sync(backup_only: false, restore_only: false)
23
23
  files.each do |file|
24
24
  if file.should_sync?
25
- result = Dutiful::Config.storage.sync(file)
25
+ result = if backup_only && file.exist?
26
+ Dutiful::Config.storage.backup(file)
27
+ elsif restore_only && file.has_backup?
28
+ Dutiful::Config.storage.restore(file)
29
+ else
30
+ Dutiful::Config.storage.sync(file)
31
+ end
32
+
26
33
  yield file, result if block_given?
27
34
  else
28
35
  yield file if block_given?
@@ -30,6 +37,14 @@ class Dutiful::Application
30
37
  end
31
38
  end
32
39
 
40
+ def exist?
41
+ files.any? &:exist?
42
+ end
43
+
44
+ def has_backup?
45
+ files.any? &:has_backup?
46
+ end
47
+
33
48
  def should_sync?
34
49
  exist? || has_backup?
35
50
  end
@@ -1,6 +1,8 @@
1
1
  module Dutiful::Command; end
2
2
 
3
3
  require 'clamp'
4
+ require 'dutiful/commands/backup'
4
5
  require 'dutiful/commands/list'
6
+ require 'dutiful/commands/restore'
5
7
  require 'dutiful/commands/sync'
6
8
  require 'dutiful/commands/main'
@@ -0,0 +1,23 @@
1
+ class Dutiful::Command::Backup < Clamp::Command
2
+ option ['-v', '--verbose'], :flag, 'Verbose mode'
3
+
4
+ def execute
5
+ puts "Storage: #{Dutiful::Config.storage.name}\n\n"
6
+
7
+ Dutiful::Application.each do |application|
8
+ puts "#{application.name}:\n" if application.should_sync? && application.exist? || verbose?
9
+
10
+ application.backup do |file, result|
11
+ if result
12
+ if result.success?
13
+ puts " #{file.path} ✔".green
14
+ else
15
+ puts " #{file.path} ✖ - #{result.error}".red
16
+ end
17
+ elsif verbose?
18
+ puts " #{file}"
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -4,18 +4,8 @@ class Dutiful::Command::Main < Clamp::Command
4
4
  exit 0
5
5
  end
6
6
 
7
- subcommand 'sync', 'Sync all preference files', Dutiful::Command::Sync
8
- subcommand 'list', 'List all preference files', Dutiful::Command::List
9
-
10
- subcommand 'restore', 'Restore all preference files' do
11
- def execute
12
- puts 'Not implemented yet'
13
- end
14
- end
15
-
16
- subcommand 'which', 'Display the full path to a preference file' do
17
- def execute
18
- puts 'Not implemented yet'
19
- end
20
- end
7
+ subcommand 'backup', 'Backup all preference files', Dutiful::Command::Backup
8
+ subcommand 'list', 'List all preference files', Dutiful::Command::List
9
+ subcommand 'restore', 'Restore all preference files', Dutiful::Command::Restore
10
+ subcommand 'sync', 'Sync all preference files', Dutiful::Command::Sync
21
11
  end
@@ -0,0 +1,23 @@
1
+ class Dutiful::Command::Restore < Clamp::Command
2
+ option ['-v', '--verbose'], :flag, 'Verbose mode'
3
+
4
+ def execute
5
+ puts "Storage: #{Dutiful::Config.storage.name}\n\n"
6
+
7
+ Dutiful::Application.each do |application|
8
+ puts "#{application.name}:\n" if application.should_sync? && application.has_backup? || verbose?
9
+
10
+ application.restore do |file, result|
11
+ if result
12
+ if result.success?
13
+ puts " #{file.path} ✔".green
14
+ else
15
+ puts " #{file.path} ✖ - #{result.error}".red
16
+ end
17
+ elsif verbose?
18
+ puts " #{file}"
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -34,17 +34,25 @@ class Dutiful::Storage
34
34
  end
35
35
  end
36
36
 
37
+ def backup(file)
38
+ Rsync.run file.full_path.shellescape, file.backup_path.shellescape, '--recursive'
39
+ end
40
+
41
+ def restore(file)
42
+ Rsync.run file.backup_path.shellescape, file.full_path.shellescape, '--recursive'
43
+ end
44
+
37
45
  def sync(file)
38
46
  create_dir file
39
47
 
40
48
  if file.exist?
41
49
  if file.has_backup? && file.backup_timestamp > file.timestamp
42
- Rsync.run file.backup_path.shellescape, file.full_path.shellescape, '--recursive'
50
+ restore file
43
51
  else
44
- Rsync.run file.full_path.shellescape, file.backup_path.shellescape, '--recursive'
52
+ backup file
45
53
  end
46
54
  else
47
- Rsync.run file.backup_path.shellescape, file.full_path.shellescape, '--recursive'
55
+ restore file
48
56
  end
49
57
  end
50
58
 
@@ -1,3 +1,3 @@
1
1
  module Dutiful
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dutiful
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno Pinto
@@ -125,8 +125,10 @@ files:
125
125
  - lib/dutiful/application.rb
126
126
  - lib/dutiful/application_file.rb
127
127
  - lib/dutiful/commands.rb
128
+ - lib/dutiful/commands/backup.rb
128
129
  - lib/dutiful/commands/list.rb
129
130
  - lib/dutiful/commands/main.rb
131
+ - lib/dutiful/commands/restore.rb
130
132
  - lib/dutiful/commands/sync.rb
131
133
  - lib/dutiful/config.rb
132
134
  - lib/dutiful/storage.rb
@@ -154,5 +156,5 @@ rubyforge_project:
154
156
  rubygems_version: 2.4.5
155
157
  signing_key:
156
158
  specification_version: 4
157
- summary: dutiful-0.0.7
159
+ summary: dutiful-0.0.8
158
160
  test_files: []