duplicati 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -4,3 +4,5 @@ require 'rspec/core/rake_task'
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
6
  task :default => :spec
7
+
8
+ task :release => :spec
@@ -52,7 +52,13 @@ class Duplicati
52
52
 
53
53
  def filters(type, filters)
54
54
  filters.reduce([]) do |memo, filter|
55
- memo << %Q[--#{type}-regexp="#{filter.source}"]
55
+ flag = "--#{type}"
56
+ if filter.is_a?(Regexp)
57
+ flag += %Q[-regexp="#{filter.source}"]
58
+ else
59
+ flag += %Q[="#{filter}"]
60
+ end
61
+ memo << flag
56
62
  end.join(" ")
57
63
  end
58
64
  end
@@ -1,3 +1,3 @@
1
1
  class Duplicati
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/duplicati.rb CHANGED
@@ -1,70 +1,70 @@
1
- require File.expand_path("duplicati/version", File.dirname(__FILE__))
2
- require File.expand_path("duplicati/backup", File.dirname(__FILE__))
3
- require File.expand_path("duplicati/notification/growl", File.dirname(__FILE__))
4
-
5
- class Duplicati
6
-
7
- class << self
8
- def backup(opts={})
9
- new(opts).backup
10
- end
11
- end
12
-
13
- attr_reader :opts, :execution_success
14
-
15
- def initialize(opts={})
16
- opts[:log_path] ||= "duplicati.log"
17
- opts[:duplicati_path] = duplicati_path(opts[:duplicati_path])
18
- opts[:notifications] ||= [Notification::Growl]
19
- opts[:inclusion_filters] ||= [opts[:inclusion_filter]].compact
20
- opts[:exclusion_filters] ||= [opts[:exclusion_filter]].compact
21
-
22
- if !opts[:inclusion_filters].empty? && opts[:exclusion_filters].empty?
23
- opts[:exclusion_filters] = [%r{.*[^\\/]}]
24
- end
25
-
26
- @opts = opts
27
- end
28
-
29
- def backup
30
- execute Backup.new(
31
- options :duplicati_path, :backup_paths, :backup_store_path,
32
- :backup_encryption_key, :inclusion_filters, :exclusion_filters, :log_path
33
- ).command
34
- end
35
-
36
- private
37
-
38
- def duplicati_path(path_from_options)
39
- path = path_from_options || ENV["DUPLICATI_PATH"] || "/Program Files/Duplicati"
40
- File.join(path, "Duplicati.CommandLine")
41
- end
42
-
43
- def execute(command)
44
- old_log_file_size = File.read(@opts[:log_path]).strip.size rescue 0
45
- formatted_command = format command
46
- puts formatted_command if $DEBUG
47
- @execution_success = system(formatted_command) && File.read(@opts[:log_path]).strip.size > old_log_file_size
48
- notify
49
- @execution_success
50
- end
51
-
52
- def options(*options_to_extract)
53
- options_to_extract.reduce({}) do |memo, option|
54
- memo[option] = @opts[option]
55
- memo
56
- end
57
- end
58
-
59
- def format(command)
60
- command.gsub($/, "").squeeze(" ")
61
- end
62
-
63
- def notify
64
- @opts[:notifications].each do |notification|
65
- notification.notify @execution_success
66
- end
67
- end
68
-
69
- end
70
-
1
+ require File.expand_path("duplicati/version", File.dirname(__FILE__))
2
+ require File.expand_path("duplicati/backup", File.dirname(__FILE__))
3
+ require File.expand_path("duplicati/notification/growl", File.dirname(__FILE__))
4
+
5
+ class Duplicati
6
+
7
+ class << self
8
+ def backup(opts={})
9
+ new(opts).backup
10
+ end
11
+ end
12
+
13
+ attr_reader :opts, :execution_success
14
+
15
+ def initialize(opts={})
16
+ opts[:log_path] ||= "duplicati.log"
17
+ opts[:duplicati_path] = duplicati_path(opts[:duplicati_path])
18
+ opts[:notifications] ||= [Notification::Growl]
19
+ opts[:inclusion_filters] ||= [opts[:inclusion_filter]].compact
20
+ opts[:exclusion_filters] ||= [opts[:exclusion_filter]].compact
21
+
22
+ if !opts[:inclusion_filters].empty? && opts[:exclusion_filters].empty?
23
+ opts[:exclusion_filters] = [%r{.*[^\\/]}]
24
+ end
25
+
26
+ @opts = opts
27
+ end
28
+
29
+ def backup
30
+ execute Backup.new(
31
+ options :duplicati_path, :backup_paths, :backup_store_path,
32
+ :backup_encryption_key, :inclusion_filters, :exclusion_filters, :log_path
33
+ ).command
34
+ end
35
+
36
+ private
37
+
38
+ def duplicati_path(path_from_options)
39
+ path = path_from_options || ENV["DUPLICATI_PATH"] || "/Program Files/Duplicati"
40
+ File.join(path, "Duplicati.CommandLine")
41
+ end
42
+
43
+ def execute(command)
44
+ old_log_file_size = File.read(@opts[:log_path]).strip.size rescue 0
45
+ formatted_command = format command
46
+ puts formatted_command if $DEBUG
47
+ @execution_success = system(formatted_command) && File.read(@opts[:log_path]).strip.size > old_log_file_size
48
+ notify
49
+ @execution_success
50
+ end
51
+
52
+ def options(*options_to_extract)
53
+ options_to_extract.reduce({}) do |memo, option|
54
+ memo[option] = @opts[option]
55
+ memo
56
+ end
57
+ end
58
+
59
+ def format(command)
60
+ command.gsub($/, "").squeeze(" ")
61
+ end
62
+
63
+ def notify
64
+ @opts[:notifications].each do |notification|
65
+ notification.notify @execution_success
66
+ end
67
+ end
68
+
69
+ end
70
+
@@ -88,6 +88,16 @@ describe Duplicati::Backup do
88
88
  command_parts[8].should == "--exclude-regexp=\"d\""
89
89
  end
90
90
 
91
+ it "works also with regular inclusion and exclusion filters" do
92
+ command_parts = Duplicati::Backup.new(:backup_paths => [], :backup_store_path => "", :inclusion_filters => ["a", /b/], :exclusion_filters => [/c/, "d"]).
93
+ command.split(" ")
94
+
95
+ command_parts[5].should == "--include=\"a\""
96
+ command_parts[6].should == "--include-regexp=\"b\""
97
+ command_parts[7].should == "--exclude-regexp=\"c\""
98
+ command_parts[8].should == "--exclude=\"d\""
99
+ end
100
+
91
101
  it "does not include filters into command when they're not specified" do
92
102
  command = Duplicati::Backup.new(:backup_paths => [], :backup_store_path => "").command
93
103
  command.should_not include("--include-regexp")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duplicati
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -81,12 +81,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
81
81
  - - ! '>='
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
+ segments:
85
+ - 0
86
+ hash: -687412045
84
87
  required_rubygems_version: !ruby/object:Gem::Requirement
85
88
  none: false
86
89
  requirements:
87
90
  - - ! '>='
88
91
  - !ruby/object:Gem::Version
89
92
  version: '0'
93
+ segments:
94
+ - 0
95
+ hash: -687412045
90
96
  requirements: []
91
97
  rubyforge_project:
92
98
  rubygems_version: 1.8.24
@@ -99,4 +105,3 @@ test_files:
99
105
  - spec/duplicati/notification/growl_spec.rb
100
106
  - spec/duplicati_spec.rb
101
107
  - spec/spec_helper.rb
102
- has_rdoc: