dircat 0.0.5 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/README.rdoc +1 -1
- data/Rakefile +9 -0
- data/VERSION.yml +5 -0
- data/bin/dircat-build +6 -0
- data/bin/dircat-diff +6 -0
- data/bin/dircat-query +6 -0
- data/dircat.gemspec +88 -0
- data/examples/example.rb +10 -0
- data/lib/dircat/cat.rb +192 -0
- data/lib/dircat/cli/dircat_build.rb +92 -83
- data/lib/dircat/cli/dircat_diff.rb +85 -0
- data/lib/dircat/cli/dircat_query.rb +53 -43
- data/lib/dircat/entry.rb +60 -0
- data/lib/dircat/extension_md5.rb +24 -0
- data/lib/dircat/extension_numeric.rb +17 -0
- data/lib/dircat/report.rb +61 -0
- data/lib/dircat.rb +29 -2
- data/spec/dircat/cat_spec.rb +71 -0
- data/spec/dircat/cli/dircat_build_spec.rb +59 -0
- data/spec/dircat/cli/dircat_query_diff_spec.rb +26 -0
- data/spec/dircat/cli/dircat_query_spec.rb +35 -0
- data/spec/dircat/md5_spec.rb +12 -0
- data/spec/dircat/numeric_spec.rb +11 -0
- data/spec/spec_helper.rb +25 -0
- metadata +136 -40
- data/bin/dircat-build.rb +0 -8
- data/bin/dircat-cfr.rb +0 -8
- data/bin/dircat-cmp.rb +0 -8
- data/bin/dircat-query.rb +0 -8
- data/lib/dircat/cli/dircat_cfr.rb +0 -69
- data/lib/dircat/cli/dircat_cmp.rb +0 -65
- data/lib/dircat/dircat.rb +0 -263
- data/test/dircat/tc_dircat.rb +0 -83
- data/test/dircat/tc_dircat_build.rb +0 -43
- data/test/test_dircat.rb +0 -6
- /data/{test_data/dircat/data → spec/fixtures}/certified_output/dircat1.yaml +0 -0
- /data/{test_data/dircat/data → spec/fixtures}/certified_output/dircat2.yaml +0 -0
- /data/{test_data/dircat/data → spec/fixtures}/dir1/file1.txt +0 -0
- /data/{test_data/dircat/data → spec/fixtures}/dir1/subdir/file3.txt +0 -0
- /data/{test_data/dircat/data → spec/fixtures}/dir2/file1.txt +0 -0
- /data/{test_data/dircat/data → spec/fixtures}/dir2/file2.txt +0 -0
- /data/{test_data/dircat/data → spec/fixtures}/dir2/subdir/file3.txt +0 -0
- /data/{test_data/dircat/data → spec/fixtures}/dir3/file1.txt +0 -0
- /data/{test_data/dircat/data → spec/fixtures}/dir3/subdir/file1.txt +0 -0
- /data/{test_data/dircat/data → spec/fixtures}/tmp/dummy.txt +0 -0
metadata
CHANGED
@@ -1,85 +1,181 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dircat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 4
|
9
|
+
version: 0.1.4
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
|
-
-
|
12
|
+
- Tokiro
|
8
13
|
autorequire:
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date:
|
17
|
+
date: 2010-12-17 00:00:00 +01:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
name: jeweler
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
23
29
|
version: "0"
|
24
|
-
|
25
|
-
|
26
|
-
|
30
|
+
type: :development
|
31
|
+
prerelease: false
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rake
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
segments:
|
41
|
+
- 0
|
42
|
+
version: "0"
|
43
|
+
type: :development
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: *id002
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: yard
|
48
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
segments:
|
54
|
+
- 0
|
55
|
+
version: "0"
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *id003
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: bundler
|
61
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
type: :development
|
70
|
+
prerelease: false
|
71
|
+
version_requirements: *id004
|
72
|
+
- !ruby/object:Gem::Dependency
|
73
|
+
name: rspec
|
74
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: *id005
|
85
|
+
description: "\n command line utilites to manage catalogs of directory\n "
|
86
|
+
email: tokiro.oyama@gmail.com
|
27
87
|
executables:
|
28
|
-
- dircat-
|
29
|
-
- dircat-
|
30
|
-
- dircat-
|
31
|
-
- dircat-build.rb
|
88
|
+
- dircat-build
|
89
|
+
- dircat-diff
|
90
|
+
- dircat-query
|
32
91
|
extensions: []
|
33
92
|
|
34
93
|
extra_rdoc_files:
|
35
94
|
- LICENSE
|
36
95
|
- README.rdoc
|
37
96
|
files:
|
97
|
+
- LICENSE
|
98
|
+
- README.rdoc
|
99
|
+
- Rakefile
|
100
|
+
- VERSION.yml
|
101
|
+
- dircat.gemspec
|
102
|
+
- examples/example.rb
|
38
103
|
- lib/dircat.rb
|
104
|
+
- lib/dircat/cat.rb
|
39
105
|
- lib/dircat/cli/dircat_build.rb
|
40
|
-
- lib/dircat/cli/
|
41
|
-
- lib/dircat/cli/dircat_cmp.rb
|
106
|
+
- lib/dircat/cli/dircat_diff.rb
|
42
107
|
- lib/dircat/cli/dircat_query.rb
|
43
|
-
- lib/dircat/
|
44
|
-
-
|
45
|
-
-
|
46
|
-
-
|
47
|
-
-
|
48
|
-
-
|
49
|
-
-
|
50
|
-
-
|
51
|
-
-
|
52
|
-
-
|
53
|
-
-
|
54
|
-
-
|
55
|
-
-
|
108
|
+
- lib/dircat/entry.rb
|
109
|
+
- lib/dircat/extension_md5.rb
|
110
|
+
- lib/dircat/extension_numeric.rb
|
111
|
+
- lib/dircat/report.rb
|
112
|
+
- spec/dircat/cat_spec.rb
|
113
|
+
- spec/dircat/cli/dircat_build_spec.rb
|
114
|
+
- spec/dircat/cli/dircat_query_diff_spec.rb
|
115
|
+
- spec/dircat/cli/dircat_query_spec.rb
|
116
|
+
- spec/dircat/md5_spec.rb
|
117
|
+
- spec/dircat/numeric_spec.rb
|
118
|
+
- spec/fixtures/certified_output/dircat1.yaml
|
119
|
+
- spec/fixtures/certified_output/dircat2.yaml
|
120
|
+
- spec/fixtures/dir1/file1.txt
|
121
|
+
- spec/fixtures/dir1/subdir/file3.txt
|
122
|
+
- spec/fixtures/dir2/file1.txt
|
123
|
+
- spec/fixtures/dir2/file2.txt
|
124
|
+
- spec/fixtures/dir2/subdir/file3.txt
|
125
|
+
- spec/fixtures/dir3/file1.txt
|
126
|
+
- spec/fixtures/dir3/subdir/file1.txt
|
127
|
+
- spec/fixtures/tmp/dummy.txt
|
128
|
+
- spec/spec_helper.rb
|
129
|
+
- bin/dircat-build
|
130
|
+
- bin/dircat-diff
|
131
|
+
- bin/dircat-query
|
56
132
|
has_rdoc: true
|
57
|
-
homepage: http://github.com/
|
133
|
+
homepage: http://github.com/tokiro/dircat
|
134
|
+
licenses: []
|
135
|
+
|
58
136
|
post_install_message:
|
59
|
-
rdoc_options:
|
60
|
-
|
137
|
+
rdoc_options: []
|
138
|
+
|
61
139
|
require_paths:
|
62
140
|
- lib
|
63
141
|
required_ruby_version: !ruby/object:Gem::Requirement
|
142
|
+
none: false
|
64
143
|
requirements:
|
65
144
|
- - ">="
|
66
145
|
- !ruby/object:Gem::Version
|
146
|
+
segments:
|
147
|
+
- 0
|
67
148
|
version: "0"
|
68
|
-
version:
|
69
149
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
|
+
none: false
|
70
151
|
requirements:
|
71
152
|
- - ">="
|
72
153
|
- !ruby/object:Gem::Version
|
154
|
+
segments:
|
155
|
+
- 0
|
73
156
|
version: "0"
|
74
|
-
version:
|
75
157
|
requirements: []
|
76
158
|
|
77
|
-
rubyforge_project:
|
78
|
-
rubygems_version: 1.3.
|
159
|
+
rubyforge_project:
|
160
|
+
rubygems_version: 1.3.7
|
79
161
|
signing_key:
|
80
|
-
specification_version:
|
162
|
+
specification_version: 3
|
81
163
|
summary: command line utilites to manage catalogs of directory
|
82
164
|
test_files:
|
83
|
-
-
|
84
|
-
-
|
85
|
-
-
|
165
|
+
- spec/dircat/cat_spec.rb
|
166
|
+
- spec/dircat/cli/dircat_build_spec.rb
|
167
|
+
- spec/dircat/cli/dircat_query_diff_spec.rb
|
168
|
+
- spec/dircat/cli/dircat_query_spec.rb
|
169
|
+
- spec/dircat/md5_spec.rb
|
170
|
+
- spec/dircat/numeric_spec.rb
|
171
|
+
- spec/fixtures/certified_output/dircat1.yaml
|
172
|
+
- spec/fixtures/certified_output/dircat2.yaml
|
173
|
+
- spec/fixtures/dir1/file1.txt
|
174
|
+
- spec/fixtures/dir1/subdir/file3.txt
|
175
|
+
- spec/fixtures/dir2/file1.txt
|
176
|
+
- spec/fixtures/dir2/file2.txt
|
177
|
+
- spec/fixtures/dir2/subdir/file3.txt
|
178
|
+
- spec/fixtures/dir3/file1.txt
|
179
|
+
- spec/fixtures/dir3/subdir/file1.txt
|
180
|
+
- spec/fixtures/tmp/dummy.txt
|
181
|
+
- spec/spec_helper.rb
|
data/bin/dircat-build.rb
DELETED
data/bin/dircat-cfr.rb
DELETED
data/bin/dircat-cmp.rb
DELETED
data/bin/dircat-query.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
# stdlib
|
2
|
-
require 'optparse'
|
3
|
-
|
4
|
-
# dircat
|
5
|
-
require 'dircat/dircat.rb'
|
6
|
-
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
class DirCatCfr
|
11
|
-
|
12
|
-
def self.run
|
13
|
-
self.new.parse_args( ARGV )
|
14
|
-
end
|
15
|
-
|
16
|
-
def parse_args( args )
|
17
|
-
options = {}
|
18
|
-
opts = OptionParser.new
|
19
|
-
opts.banner =
|
20
|
-
"Usage: dircat_cfr.rb [options] <filedircat1> <filedircat2>\n\n" +
|
21
|
-
"fa la differenza fra il primo catalog e il secondo\n" +
|
22
|
-
"<filedircat1> - <filedircat2>\n" +
|
23
|
-
"e stampa sull'output con un formato\n"
|
24
|
-
|
25
|
-
opts.on("-h", "--help", "Print this message") do
|
26
|
-
puts opts
|
27
|
-
return
|
28
|
-
end
|
29
|
-
|
30
|
-
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
31
|
-
options[:verbose] = v
|
32
|
-
end
|
33
|
-
|
34
|
-
opts.on("-f FORMAT", "--fmt FORMAT", "formato") do |v|
|
35
|
-
options[:fmt] = v
|
36
|
-
end
|
37
|
-
rest = opts.parse( args )
|
38
|
-
|
39
|
-
# p options
|
40
|
-
# p ARGV
|
41
|
-
|
42
|
-
if rest.length < 2
|
43
|
-
puts "inserire il nome di due cataloghi da confrontare"
|
44
|
-
puts "dircat_cfr -h to print help"
|
45
|
-
exit
|
46
|
-
end
|
47
|
-
|
48
|
-
cat_filename1 = rest[0]
|
49
|
-
cat_filename2 = rest[1]
|
50
|
-
|
51
|
-
puts "build first set"
|
52
|
-
s1 = DirCat.loadfromfile(cat_filename1)
|
53
|
-
|
54
|
-
puts "build second set"
|
55
|
-
s2 = DirCat.loadfromfile(cat_filename2)
|
56
|
-
|
57
|
-
puts "build difference"
|
58
|
-
s3 = s1 - s2
|
59
|
-
|
60
|
-
case options[:fmt]
|
61
|
-
when "simple"
|
62
|
-
s3.fmt_simple
|
63
|
-
when "ruby"
|
64
|
-
s3.fmt_ruby( "." )
|
65
|
-
else
|
66
|
-
s3.fmt_simple
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
require 'optparse'
|
2
|
-
require 'dircat/dircat.rb'
|
3
|
-
|
4
|
-
#
|
5
|
-
# MAIN
|
6
|
-
#
|
7
|
-
|
8
|
-
class DirCatCmp
|
9
|
-
|
10
|
-
def self.run
|
11
|
-
self.new.parse_args( ARGV )
|
12
|
-
end
|
13
|
-
|
14
|
-
def parse_args(args)
|
15
|
-
options = {}
|
16
|
-
opts = OptionParser.new
|
17
|
-
opts.banner = "Usage: example.rb [options]"
|
18
|
-
|
19
|
-
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
20
|
-
options[:verbose] = v
|
21
|
-
end
|
22
|
-
rest = opts.parse( args )
|
23
|
-
|
24
|
-
# p options
|
25
|
-
# p ARGV
|
26
|
-
|
27
|
-
if rest.length < 1
|
28
|
-
puts "inserire il nome di due directory da confrontare"
|
29
|
-
return
|
30
|
-
end
|
31
|
-
|
32
|
-
dirname1 = rest[0]
|
33
|
-
dirname2 = rest[1] if rest[1]
|
34
|
-
|
35
|
-
if dirname2
|
36
|
-
twoset( dirname1, dirname2 )
|
37
|
-
return
|
38
|
-
end
|
39
|
-
|
40
|
-
if dirname1
|
41
|
-
oneset( dirname1 )
|
42
|
-
return
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def oneset( dirname )
|
47
|
-
puts "build set"
|
48
|
-
s = DirCat.loadfromdir(dirname)
|
49
|
-
# s.pr
|
50
|
-
puts s.to_yaml
|
51
|
-
end
|
52
|
-
|
53
|
-
def twoset( dirname1, dirname2 )
|
54
|
-
puts "build first set"
|
55
|
-
s1 = DirCat.loadfromdir(dirname1)
|
56
|
-
|
57
|
-
puts "build second set"
|
58
|
-
s2 = DirCat.loadfromdir(dirname2)
|
59
|
-
|
60
|
-
puts "build difference"
|
61
|
-
s3 = s1 - s2
|
62
|
-
|
63
|
-
s3.pr
|
64
|
-
end
|
65
|
-
end
|
data/lib/dircat/dircat.rb
DELETED
@@ -1,263 +0,0 @@
|
|
1
|
-
# stdlib
|
2
|
-
require 'fileutils'
|
3
|
-
require 'tmpdir'
|
4
|
-
require 'yaml'
|
5
|
-
require 'ostruct'
|
6
|
-
|
7
|
-
# dircat
|
8
|
-
require 'rubygems'
|
9
|
-
require 'gf_utility/md5'
|
10
|
-
require 'gf_utility/numeric'
|
11
|
-
|
12
|
-
#
|
13
|
-
# GLOBAL VAR
|
14
|
-
#
|
15
|
-
|
16
|
-
$VERBOSE_LEVEL = 0
|
17
|
-
|
18
|
-
class EntrySer < OpenStruct
|
19
|
-
end
|
20
|
-
|
21
|
-
#
|
22
|
-
# Entry
|
23
|
-
#
|
24
|
-
class Entry
|
25
|
-
|
26
|
-
attr_reader :md5
|
27
|
-
attr_reader :name
|
28
|
-
attr_reader :path
|
29
|
-
attr_reader :size
|
30
|
-
attr_reader :mtime
|
31
|
-
|
32
|
-
def from_filename( filename )
|
33
|
-
# puts "Entry::initialize #f"
|
34
|
-
if $VERBOSE_LEVEL > 0
|
35
|
-
cr = "\r"
|
36
|
-
clear = "\e[K"
|
37
|
-
print "#{cr}#{filename}#{clear}"
|
38
|
-
end
|
39
|
-
@name = File.basename(filename)
|
40
|
-
@path = File.dirname(filename)
|
41
|
-
stat = File.stat(filename)
|
42
|
-
@size = stat.size
|
43
|
-
@mtime = stat.mtime
|
44
|
-
# self.md5 = Digest::MD5.hexdigest(File.read( f ))
|
45
|
-
@md5 = MD5.file( filename ).hexdigest
|
46
|
-
self
|
47
|
-
end
|
48
|
-
|
49
|
-
def from_ser( entry_ser )
|
50
|
-
@md5 = entry_ser.md5
|
51
|
-
@name = entry_ser.name
|
52
|
-
@path = entry_ser.path
|
53
|
-
@size = entry_ser.size
|
54
|
-
@mtime = entry_ser.mtime
|
55
|
-
self
|
56
|
-
end
|
57
|
-
|
58
|
-
def to_ser
|
59
|
-
entry_ser = EntrySer.new
|
60
|
-
entry_ser.md5 = @md5
|
61
|
-
entry_ser.name = @name
|
62
|
-
entry_ser.path = @path
|
63
|
-
entry_ser.size = @size
|
64
|
-
entry_ser.mtime = @mtime
|
65
|
-
entry_ser
|
66
|
-
end
|
67
|
-
|
68
|
-
def to_s
|
69
|
-
@md5 + " " + @name + "\t " + @path + "\n"
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
class DirCatSer < OpenStruct
|
75
|
-
end
|
76
|
-
|
77
|
-
|
78
|
-
class DirCatException < RuntimeError
|
79
|
-
|
80
|
-
end
|
81
|
-
|
82
|
-
#
|
83
|
-
# DirCat
|
84
|
-
#
|
85
|
-
class DirCat
|
86
|
-
|
87
|
-
attr_reader :dirname
|
88
|
-
# data di creazione
|
89
|
-
attr_reader :ctime
|
90
|
-
attr_writer :ctime
|
91
|
-
# attr_reader :entries
|
92
|
-
|
93
|
-
def from_dirname( dirname )
|
94
|
-
# puts "#{self.class.name}#initialize"
|
95
|
-
@dirname = dirname
|
96
|
-
@ctime = DateTime.now
|
97
|
-
@entries = Array.new
|
98
|
-
@md5ToEntries = Hash.new
|
99
|
-
self
|
100
|
-
end
|
101
|
-
|
102
|
-
def from_ser( dircat_ser )
|
103
|
-
@dirname = dircat_ser.dirname
|
104
|
-
@ctime = dircat_ser.ctime
|
105
|
-
@entries = Array.new
|
106
|
-
@md5ToEntries = Hash.new
|
107
|
-
dircat_ser.entries.each{ |entry_ser|
|
108
|
-
add_entry( Entry.new.from_ser( entry_ser ) )
|
109
|
-
}
|
110
|
-
self
|
111
|
-
end
|
112
|
-
|
113
|
-
def to_ser
|
114
|
-
dircat_ser = DirCatSer.new
|
115
|
-
dircat_ser.version = 0.1
|
116
|
-
dircat_ser.dirname = @dirname
|
117
|
-
dircat_ser.ctime = @ctime
|
118
|
-
dircat_ser.entries = []
|
119
|
-
@entries.each { |entry|
|
120
|
-
dircat_ser.entries << entry.to_ser
|
121
|
-
}
|
122
|
-
dircat_ser
|
123
|
-
end
|
124
|
-
|
125
|
-
def self.loadfromdir( dirname )
|
126
|
-
# puts "#{self.class.name}#loadfromdir( #{dirname} )"
|
127
|
-
if not File.directory?( dirname )
|
128
|
-
raise "'#{dirname}' non e' una directory o non esiste"
|
129
|
-
end
|
130
|
-
|
131
|
-
s = self.new
|
132
|
-
s.from_dirname( File.expand_path( dirname ) )
|
133
|
-
s._loadfromdir
|
134
|
-
end
|
135
|
-
|
136
|
-
def _loadfromdir()
|
137
|
-
old_dirname = Dir.pwd
|
138
|
-
Dir.chdir( @dirname )
|
139
|
-
Dir["**/*"].each { |f|
|
140
|
-
# puts "#{self.class.name}#loadfromdir #{f}"
|
141
|
-
next if File.directory?( f )
|
142
|
-
add_entry( Entry.new.from_filename( f ) )
|
143
|
-
}
|
144
|
-
if $VERBOSE_LEVEL > 0
|
145
|
-
print "\n"
|
146
|
-
end
|
147
|
-
Dir.chdir( old_dirname )
|
148
|
-
self
|
149
|
-
end
|
150
|
-
|
151
|
-
def self.loadfromfile( filename )
|
152
|
-
if not File.exist?( filename )
|
153
|
-
raise DirCatException.new, "'#{filename}' not exists"
|
154
|
-
end
|
155
|
-
dircat_ser = YAML::load( File.open( filename ) )
|
156
|
-
DirCat.new.from_ser( dircat_ser )
|
157
|
-
end
|
158
|
-
|
159
|
-
def savetofile( file )
|
160
|
-
if file.kind_of?(String)
|
161
|
-
begin
|
162
|
-
File.open( file, "w" ) do |f|
|
163
|
-
f.puts to_ser.to_yaml
|
164
|
-
end
|
165
|
-
rescue Errno::ENOENT
|
166
|
-
raise DirCatException.new, "DirCat: cannot write into '#{file}'", caller
|
167
|
-
end
|
168
|
-
else
|
169
|
-
file.puts to_ser.to_yaml
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
def size
|
174
|
-
@entries.size
|
175
|
-
end
|
176
|
-
|
177
|
-
def bytes
|
178
|
-
@entries.inject(0) {|sum, entry| sum + entry.size }
|
179
|
-
end
|
180
|
-
|
181
|
-
def report
|
182
|
-
dups = duplicates
|
183
|
-
s = "Directory base: #@dirname\n" +
|
184
|
-
"Nr. file #{size}\n" +
|
185
|
-
"Bytes #{bytes.with_separator}"
|
186
|
-
if duplicates.size > 0
|
187
|
-
s+= "\n duplicates #{dups.size}"
|
188
|
-
end
|
189
|
-
s
|
190
|
-
end
|
191
|
-
|
192
|
-
def add_entry( e )
|
193
|
-
@entries.push( e )
|
194
|
-
if @md5ToEntries.has_key?( e.md5 )
|
195
|
-
# puts "Entry duplicata!!!"
|
196
|
-
@md5ToEntries[ e.md5 ].push( e )
|
197
|
-
else
|
198
|
-
@md5ToEntries[ e.md5 ] = [ e ]
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
def contains( e )
|
203
|
-
@md5ToEntries.has_key?( e.md5 )
|
204
|
-
end
|
205
|
-
|
206
|
-
def -(s)
|
207
|
-
result = DirCat.new.from_dirname( @dirname )
|
208
|
-
@entries.each { |e|
|
209
|
-
result.add_entry(e) unless s.contains(e)
|
210
|
-
}
|
211
|
-
result
|
212
|
-
end
|
213
|
-
|
214
|
-
def duplicates
|
215
|
-
list = []
|
216
|
-
@md5ToEntries.each_value do |ee|
|
217
|
-
next if ee.size < 2
|
218
|
-
list.push( ee )
|
219
|
-
end
|
220
|
-
list
|
221
|
-
end
|
222
|
-
|
223
|
-
def fmt_simple
|
224
|
-
@entries.each { |e|
|
225
|
-
print e.to_s
|
226
|
-
}
|
227
|
-
end
|
228
|
-
|
229
|
-
def fmt_ruby( dst )
|
230
|
-
puts "require 'fileutils'"
|
231
|
-
@entries.each { |entry|
|
232
|
-
src = File.join( @dirname, entry.path, entry.name );
|
233
|
-
puts "FileUtils.cp( \"#{src}\", \"#{dst}\" )"
|
234
|
-
}
|
235
|
-
end
|
236
|
-
|
237
|
-
def list_dup
|
238
|
-
r = ""
|
239
|
-
duplicates.flatten.each { |e|
|
240
|
-
r += e.to_s + "\n"
|
241
|
-
}
|
242
|
-
r
|
243
|
-
end
|
244
|
-
|
245
|
-
def script_dup
|
246
|
-
r = "require 'fileutils'\n"
|
247
|
-
duplicates.each { |entries|
|
248
|
-
flg_first = true
|
249
|
-
r += "\n"
|
250
|
-
entries.each{ |entry|
|
251
|
-
src = File.join( @dirname, entry.path, entry.name );
|
252
|
-
if flg_first
|
253
|
-
flg_first = false
|
254
|
-
r += "# FileUtils.mv( \"#{src}\", \"#{Dir.tmpdir}\" )\n"
|
255
|
-
else
|
256
|
-
r += "FileUtils.mv( \"#{src}\", \"#{Dir.tmpdir}\" )\n"
|
257
|
-
end
|
258
|
-
}
|
259
|
-
}
|
260
|
-
r
|
261
|
-
end
|
262
|
-
|
263
|
-
end
|