dutiful 0.0.7 → 0.0.8
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/lib/dutiful/application.rb +25 -10
 - data/lib/dutiful/commands.rb +2 -0
 - data/lib/dutiful/commands/backup.rb +23 -0
 - data/lib/dutiful/commands/main.rb +4 -14
 - data/lib/dutiful/commands/restore.rb +23 -0
 - data/lib/dutiful/storage.rb +11 -3
 - data/lib/dutiful/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: 2e0b17aa6b4926b3c741b9178b4081ef72ed5684
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 0deafa16d607c75dec399bba7a8cb102468b3a35
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 93094fe71f0c948abf0f553bcd02a7284fe30e22ef25105787b24245e57d631385d0cc41fa6dc46dfa8a0c19d4df4adf1f2279c2b1209a4cda2d983bc0c8d636
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: f9605865f58cc59cc49a636763bbcb0dca10d15d2c71531c52c4cfb6f4c5a3c2ef3d1310f7bb16d7bdb81b4d7d79fceaecc82ab2eeaf2c6020e2e815de829bbd
         
     | 
    
        data/lib/dutiful/application.rb
    CHANGED
    
    | 
         @@ -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  
     | 
| 
       15 
     | 
    
         
            -
                 
     | 
| 
      
 10 
     | 
    
         
            +
              def name
         
     | 
| 
      
 11 
     | 
    
         
            +
                content[:application][:name]
         
     | 
| 
       16 
12 
     | 
    
         
             
              end
         
     | 
| 
       17 
13 
     | 
    
         | 
| 
       18 
     | 
    
         
            -
              def  
     | 
| 
       19 
     | 
    
         
            -
                 
     | 
| 
      
 14 
     | 
    
         
            +
              def backup(&block)
         
     | 
| 
      
 15 
     | 
    
         
            +
                sync backup_only: true, &block
         
     | 
| 
       20 
16 
     | 
    
         
             
              end
         
     | 
| 
       21 
17 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
              def  
     | 
| 
      
 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 =  
     | 
| 
      
 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
         
     | 
    
        data/lib/dutiful/commands.rb
    CHANGED
    
    
| 
         @@ -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 ' 
     | 
| 
       8 
     | 
    
         
            -
              subcommand 'list', 
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
              subcommand ' 
     | 
| 
       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
         
     | 
    
        data/lib/dutiful/storage.rb
    CHANGED
    
    | 
         @@ -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 
     | 
    
         
            -
                     
     | 
| 
      
 50 
     | 
    
         
            +
                    restore file
         
     | 
| 
       43 
51 
     | 
    
         
             
                  else
         
     | 
| 
       44 
     | 
    
         
            -
                     
     | 
| 
      
 52 
     | 
    
         
            +
                    backup file
         
     | 
| 
       45 
53 
     | 
    
         
             
                  end
         
     | 
| 
       46 
54 
     | 
    
         
             
                else
         
     | 
| 
       47 
     | 
    
         
            -
                   
     | 
| 
      
 55 
     | 
    
         
            +
                  restore file
         
     | 
| 
       48 
56 
     | 
    
         
             
                end
         
     | 
| 
       49 
57 
     | 
    
         
             
              end
         
     | 
| 
       50 
58 
     | 
    
         | 
    
        data/lib/dutiful/version.rb
    CHANGED
    
    
    
        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. 
     | 
| 
      
 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. 
     | 
| 
      
 159 
     | 
    
         
            +
            summary: dutiful-0.0.8
         
     | 
| 
       158 
160 
     | 
    
         
             
            test_files: []
         
     |