tms 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/.gitignore +4 -0
  2. data/VERSION +1 -1
  3. data/bin/tms +8 -0
  4. data/lib/tms/backup.rb +34 -9
  5. data/tms.gemspec +2 -2
  6. metadata +4 -4
data/.gitignore CHANGED
@@ -3,3 +3,7 @@ pkg
3
3
  doc
4
4
  *.gem
5
5
  *.swp
6
+ ext/Makefile
7
+ ext/*.o
8
+ ext/*.bundle
9
+ lib/*.bundle
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.1.0
data/bin/tms CHANGED
@@ -21,6 +21,14 @@ Usege:
21
21
  op.on('-d', '--directory DIRECTORY', 'Use backup directory') do |dir|
22
22
  Tms::Backup.backups_dir = dir
23
23
  end
24
+
25
+ op.on('-f', '--filter DIRECTORY', 'Show diff starting from directory') do |dir|
26
+ Tms::Backup.filter_dir = dir
27
+ end
28
+
29
+ op.on('-p', '--progress', 'Show backups in progress') do
30
+ Tms::Backup.show_in_progress = true
31
+ end
24
32
  end.parse!(options)
25
33
 
26
34
  ids = ids.map(&:to_i)
@@ -18,18 +18,38 @@ class Tms::Backup
18
18
  @backups_dir = Pathname(dir)
19
19
  end
20
20
 
21
+ attr_accessor :filter_dir
22
+ attr_accessor :show_in_progress
23
+
21
24
  def list
22
25
  @list ||= begin
23
- backups_dir.children.select do |path|
24
- path.basename.to_s =~ /^\d{4}-\d{2}-\d{2}-\d{6}$/
25
- end.map(&method(:new)).sort_by(&:number)
26
+ backups = []
27
+ backups_dir.children.each do |path|
28
+ case path.basename.to_s
29
+ when /^\d{4}-\d{2}-\d{2}-\d{6}$/
30
+ backups << new(path)
31
+ when /^\d{4}-\d{2}-\d{2}-\d{6}\.inProgress$/
32
+ if show_in_progress
33
+ path.children.select(&:directory?).each do |path_in_progress|
34
+ backups << new(path_in_progress, true)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ backups.sort
26
40
  end
27
41
  end
28
42
 
29
43
  def diff(a, b)
30
44
  total = 0
31
- (a.path.children(false) | b.path.children(false)).reject{ |child| child.to_s[0, 1] == '.' }.sort.each do |path|
32
- total += compare(a.path + path, b.path + path, Pathname('/') + path)
45
+ if filter_dir
46
+ root_dir = (a.path.children + b.path.children).select(&:directory?).select{ |child| Pathname(File.join(child, filter_dir)).exist? }.map(&:basename).uniq
47
+ root_dir = File.join(root_dir, filter_dir)
48
+ total += compare(a.path + root_dir, b.path + root_dir, Pathname('/') + root_dir)
49
+ else
50
+ (a.path.children(false) | b.path.children(false)).reject{ |child| child.to_s[0, 1] == '.' }.sort.each do |path|
51
+ total += compare(a.path + path, b.path + path, Pathname('/') + path)
52
+ end
33
53
  end
34
54
  puts "#{'Total:'.bold} #{Tms::Space.space(total, :color => true)}"
35
55
  end
@@ -69,13 +89,14 @@ class Tms::Backup
69
89
  end
70
90
  end
71
91
 
72
- attr_reader :path
73
- def initialize(path)
92
+ attr_reader :path, :in_progress
93
+ def initialize(path, in_progress = false)
74
94
  @path = path
95
+ @in_progress = in_progress
75
96
  end
76
97
 
77
98
  def name
78
- @name ||= path.basename.to_s
99
+ @name ||= in_progress ? "#{path.dirname.basename}/#{path.basename}" : path.basename.to_s
79
100
  end
80
101
 
81
102
  def started_at
@@ -95,11 +116,15 @@ class Tms::Backup
95
116
  }.each do |name, attr|
96
117
  class_eval <<-src
97
118
  def #{name}
98
- @#{name} ||= xattr.get('#{attr}').to_i
119
+ @#{name} ||= xattr.get('#{attr}').to_i rescue '-'
99
120
  end
100
121
  src
101
122
  end
102
123
 
124
+ def <=>(other)
125
+ name <=> other.name
126
+ end
127
+
103
128
  private
104
129
 
105
130
  def xattr
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{tms}
8
- s.version = "1.0.1"
8
+ s.version = "1.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Boba Fat"]
12
- s.date = %q{2010-11-11}
12
+ s.date = %q{2010-11-20}
13
13
  s.default_executable = %q{tms}
14
14
  s.description = %q{View avaliable Time Machine backups and show diff}
15
15
  s.executables = ["tms"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tms
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 0
9
8
  - 1
10
- version: 1.0.1
9
+ - 0
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Boba Fat
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-11 00:00:00 +03:00
18
+ date: 2010-11-20 00:00:00 +03:00
19
19
  default_executable: tms
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency