dircat 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 gf
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,44 @@
1
+ = DIRCAT: Utilities per la gestione di cataloghi e di directory
2
+
3
+ == dircat_build
4
+
5
+ Costruisce un catalogo a partire da una directory
6
+
7
+ Esempio:
8
+
9
+ Per costruire un catalogo di una directory dir1
10
+
11
+ DirCatBuild -o nome catalogo dir1
12
+
13
+ == dircat_cfr
14
+
15
+ Confronta due cataloghi
16
+
17
+ == dircat_cmp
18
+
19
+ == dircat_query
20
+
21
+ Interroga un catalogo
22
+
23
+ == DESCRIPTION:
24
+
25
+ == FEATURES/PROBLEMS:
26
+
27
+ * FIX (list of features or problems)
28
+
29
+ == SYNOPSIS:
30
+
31
+ FIX (code sample of usage)
32
+
33
+ == REQUIREMENTS:
34
+
35
+ * utilizza la libreria abstract di kwartz
36
+ * gui: dipende da fxruby e/o wxruby
37
+
38
+ == INSTALL:
39
+
40
+ * FIX (sudo gem install, anything else)
41
+
42
+ == Copyright
43
+
44
+ Copyright (c) 2009 gf. See LICENSE for details.
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $DIRCAT_HOME = File.expand_path( File.join( File.dirname( __FILE__), "..") )
4
+ $:.unshift( File.join($DIRCAT_HOME, "lib" ) )
5
+
6
+ require 'dircat/cli/dircat_build.rb'
7
+
8
+ DirCatBuild.run
data/bin/dircat-cfr.rb ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $DIRCAT_HOME = File.expand_path( File.join( File.dirname( __FILE__), "..") )
4
+ $:.unshift( File.join($DIRCAT_HOME, "lib" ) )
5
+
6
+ require 'dircat/cli/dircat_cfr.rb'
7
+
8
+ DirCatCfr.run
data/bin/dircat-cmp.rb ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $DIRCAT_HOME = File.expand_path( File.join( File.dirname( __FILE__), "..") )
4
+ $:.unshift( File.join($DIRCAT_HOME, "lib" ) )
5
+
6
+ require 'dircat/cli/dircat_cmp.rb'
7
+
8
+ DirCatCmp.run
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $DIRCAT_HOME = File.expand_path( File.join( File.dirname( __FILE__), "..") )
4
+ $:.unshift( File.join($DIRCAT_HOME, "lib" ) )
5
+
6
+ require 'dircat/cli/dircat_query.rb'
7
+
8
+ DirCatQuery.run
@@ -0,0 +1,105 @@
1
+ # stdlib
2
+ require 'optparse'
3
+
4
+ # dircat
5
+ require 'dircat/dircat.rb'
6
+
7
+ #
8
+ # Build a catalogue starting from a directory
9
+ #
10
+ class DirCatBuild
11
+
12
+ def self.run
13
+ self.new.parse_args( ARGV )
14
+ end
15
+
16
+ def parse_args( argv )
17
+ options = { :verbose => true, :force => false }
18
+ opts = OptionParser.new
19
+ opts.banner << "Usage: dircat_build [options]\n"
20
+ opts.banner << "\n"
21
+ opts.banner << "Build a catalogue starting from a directory\n";
22
+ opts.banner << "\n"
23
+
24
+ opts.on("-h", "--help", "Print this message") do
25
+ puts opts
26
+ return
27
+ end
28
+
29
+ opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
30
+ options[:verbose] = v
31
+ end
32
+
33
+ opts.on("-q", "--quiet", "quiet mode as --no-verbose") do |v|
34
+ options[:verbose] = false
35
+ end
36
+
37
+ opts.on("-f", "--force", "force write on existent file") do |v|
38
+ options[:force] = true
39
+ end
40
+
41
+ opts.on("-o [FILE]", "--output [FILE]",String) do |v|
42
+ options[:output] = v
43
+ end
44
+
45
+ rest = opts.parse(argv)
46
+
47
+ # p options
48
+ # p ARGV
49
+
50
+ if rest.length < 1
51
+ puts "inserire il nome della directory di cui creare il catalogo"
52
+ puts "-h to print help"
53
+ return
54
+ end
55
+
56
+ dirname = rest[0]
57
+ dirname = File.expand_path( dirname )
58
+ if not FileTest.directory?(dirname)
59
+ puts "directory "#{dirname} not exists or is not a directory"
60
+ return
61
+ end
62
+
63
+ #
64
+ # option verbose
65
+ #
66
+
67
+ if options.has_key?(:verbose)
68
+ if options[:verbose]
69
+ $VERBOSE_LEVEL = 1
70
+ end
71
+ end
72
+
73
+ #
74
+ # option: output, force
75
+ #
76
+ output = $stdout
77
+ if options.has_key?(:output)
78
+ if options[:output]
79
+ filename = options[:output]
80
+ else
81
+ filename = "cat_" + File.basename( dirname ) + "_" + Date.today.strftime("%Y%m%d") + ".yaml"
82
+ end
83
+ if File.exist?(filename) and not options[:force]
84
+ puts "File #{filename} exists use --force or -f to overwrite"
85
+ return
86
+ end
87
+ output = File.open(filename, "w")
88
+ end
89
+
90
+ start_datetime = DateTime.now
91
+ s = DirCat.loadfromdir(dirname)
92
+ end_datetime = DateTime.now
93
+
94
+ # s.pr
95
+ # f.puts s.to_yaml
96
+ s.savetofile( output )
97
+
98
+ if output != $stdout
99
+ output.close
100
+ end
101
+ $stderr.puts s.report
102
+ $stderr.puts "tempo: #{end_datetime - start_datetime}"
103
+ end
104
+
105
+ end
@@ -0,0 +1,69 @@
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
@@ -0,0 +1,65 @@
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
@@ -0,0 +1,59 @@
1
+ require 'optparse'
2
+ require 'dircat/dircat.rb'
3
+
4
+ #
5
+ # DirCatQuery
6
+ #
7
+ class DirCatQuery
8
+
9
+ def self.run
10
+ self.new.parse_args( ARGV)
11
+ end
12
+
13
+ def parse_args( args )
14
+ options = {}
15
+ opts = OptionParser.new
16
+ opts.banner =
17
+ "Usage: dircat_query [options] <filedircat> <command>\n" +
18
+ "mostra informazioni su un dircat\n"
19
+
20
+ opts.on("-h", "--help", "Print this message") do
21
+ puts opts
22
+ return
23
+ end
24
+
25
+ opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
26
+ options[:verbose] = v
27
+ end
28
+
29
+ rest = opts.parse( args )
30
+
31
+ # p options
32
+ # p ARGV
33
+
34
+ if rest.length < 2
35
+ puts "inserire il nome del catalogo da interrogare e il comando da eseguire"
36
+ puts "-h to print help"
37
+ return
38
+ end
39
+
40
+ cat_filename = rest[0]
41
+ command = rest[1]
42
+
43
+ #
44
+ # option verbose
45
+ #
46
+ if options.has_key?(:verbose)
47
+ if options[:verbose]
48
+ $VERBOSE_LEVEL = 1
49
+ end
50
+ end
51
+
52
+ s = DirCat.loadfromfile( cat_filename )
53
+
54
+ #case command
55
+ #else
56
+ puts s.send( command.to_sym )
57
+ #end
58
+ end
59
+ end
@@ -0,0 +1,263 @@
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
data/lib/dircat.rb ADDED
@@ -0,0 +1,3 @@
1
+ class Dircat
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,81 @@
1
+ $DIRCAT_HOME = File.expand_path( File.join( File.dirname( __FILE__), "..", "..") )
2
+ $:.unshift( File.join($DIRCAT_HOME, "lib" ) )
3
+
4
+ require 'test/unit'
5
+ require 'dircat/dircat.rb'
6
+
7
+ # dir1 contiene 2 file
8
+ # aggiunto un file a dir1
9
+ # dir2 contiene 3 file (uno in piu' di dir2)
10
+
11
+ # dir 3 contiene file duplicati
12
+
13
+ #
14
+ # data/
15
+ # |-- dir1
16
+ # | |-- file1.txt
17
+ # | |-- file2.txt
18
+ # | `-- subdir
19
+ # | `-- file3.txt
20
+ # `-- dir2
21
+ # |-- file1.txt
22
+ # `-- subdir
23
+ # `-- file3.txt
24
+
25
+
26
+ class TC_DirCat < Test::Unit::TestCase
27
+
28
+ def setup
29
+ @data_dir = File.join($DIRCAT_HOME, "test", "dircat", "data")
30
+ @tmp_dir = File.join( @data_dir, "tmp" )
31
+ end
32
+
33
+ def teardown
34
+ end
35
+
36
+ def test_dircat1
37
+ dircat1 = DirCat.loadfromdir( File.join(@data_dir, "dir1") )
38
+ assert_equal(2, dircat1.size )
39
+ assert_equal(4, dircat1.bytes )
40
+ end
41
+
42
+ def test_dircat2
43
+ dircat2 = DirCat.loadfromdir( File.join(@data_dir, "dir2") )
44
+ assert_equal(3, dircat2.size )
45
+ assert_equal(6, dircat2.bytes )
46
+ end
47
+
48
+ def test_diff_dir1_dir2
49
+ dircat1 = DirCat.loadfromdir( File.join(@data_dir, "dir1") )
50
+ dircat2 = DirCat.loadfromdir( File.join(@data_dir, "dir2") )
51
+ # dir1 contiene tutti i file di dir2
52
+ cat_diff = dircat1 - dircat2
53
+ assert_equal(0, cat_diff.size)
54
+ end
55
+
56
+ def test_diff_dir2_dir1
57
+ dircat1 = DirCat.loadfromdir( File.join(@data_dir, "dir1") )
58
+ dircat2 = DirCat.loadfromdir( File.join(@data_dir, "dir2") )
59
+
60
+ # dir2 contiene un file in piu' di dir1
61
+ cat_diff = dircat2 - dircat1
62
+ assert_equal(1, cat_diff.size)
63
+ end
64
+
65
+ def test_dir1_ser
66
+ dircat1 = DirCat.loadfromdir( File.join(@data_dir, "dir1") )
67
+ not_existent_file = File.join(@tmp_dir, "not_existent", "dircat1.yaml")
68
+ tmp_file = File.join(@tmp_dir, "dircat1.yaml")
69
+
70
+ assert_raise DirCatException do
71
+ dircat1.savetofile( not_existent_file )
72
+ end
73
+
74
+ dircat1.savetofile( tmp_file )
75
+
76
+ dircat1_bis = DirCat.loadfromfile( tmp_file )
77
+ assert_equal( 0, (dircat1 - dircat1_bis).size )
78
+ assert_equal( 0, (dircat1_bis - dircat1).size )
79
+ end
80
+
81
+ end
@@ -0,0 +1,41 @@
1
+ $DIRCAT_HOME = File.expand_path( File.join( File.dirname( __FILE__), "..", "..") )
2
+ $:.unshift( File.join($DIRCAT_HOME, "lib" ) )
3
+
4
+ # stdlib
5
+ require 'test/unit'
6
+
7
+ # dircat
8
+ require 'dircat/dircat.rb'
9
+ require 'dircat/cli/dircat_build.rb'
10
+
11
+ class TC_DirCatBuild < Test::Unit::TestCase
12
+
13
+ def setup
14
+ @testdata_dirname = File.join( $DIRCAT_HOME, "test", "dircat", "data")
15
+ @dir1_dirname = File.join( @testdata_dirname, "dir1" )
16
+ @dir2_dirname = File.join( @testdata_dirname, "dir2" )
17
+ @certified_output_dirname = File.join( @testdata_dirname, "certified_output" )
18
+ @tmp_output_dirname = File.join( @testdata_dirname, "tmp" )
19
+ end
20
+
21
+ def test_help
22
+ args = "-h"
23
+ DirCatBuild.new.parse_args( args.split )
24
+ end
25
+
26
+ def test_dir1
27
+ expect_filename = File.join( @certified_output_dirname, "dircat1.yaml" )
28
+ result_filename = File.join( @tmp_output_dirname, "dircat1.yaml")
29
+ args = "-f -o #{result_filename} #{@dir1_dirname}"
30
+ DirCatBuild.new.parse_args( args.split )
31
+
32
+ cat_expect = DirCat.loadfromfile( expect_filename )
33
+ cat_result = DirCat.loadfromfile( result_filename )
34
+
35
+ assert_equal( 0, (cat_result - cat_result).size )
36
+
37
+ assert_equal( 0, (cat_result - cat_expect).size )
38
+ assert_equal( 0, (cat_expect - cat_result).size )
39
+ end
40
+
41
+ end
@@ -0,0 +1,6 @@
1
+ $DIRCAT_HOME = File.expand_path( File.join( File.dirname( __FILE__), ".." ) )
2
+ $:.unshift( File.join($DIRCAT_HOME, "lib" ) )
3
+ $:.unshift( File.join($DIRCAT_HOME, "test" ) )
4
+
5
+ require 'dircat/tc_dircat.rb'
6
+ require 'dircat/tc_dircat_build.rb'
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dircat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - gf
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-23 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: tree_visitor
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description:
26
+ email: giovanni.ferro@gmail.com
27
+ executables:
28
+ - dircat-cfr.rb
29
+ - dircat-query.rb
30
+ - dircat-cmp.rb
31
+ - dircat-build.rb
32
+ extensions: []
33
+
34
+ extra_rdoc_files:
35
+ - LICENSE
36
+ - README.rdoc
37
+ files:
38
+ - lib/dircat.rb
39
+ - lib/dircat/cli/dircat_build.rb
40
+ - lib/dircat/cli/dircat_cfr.rb
41
+ - lib/dircat/cli/dircat_cmp.rb
42
+ - lib/dircat/cli/dircat_query.rb
43
+ - lib/dircat/dircat.rb
44
+ - LICENSE
45
+ - README.rdoc
46
+ has_rdoc: true
47
+ homepage: http://github.com/gf/tree_visitor
48
+ post_install_message:
49
+ rdoc_options:
50
+ - --charset=UTF-8
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ requirements: []
66
+
67
+ rubyforge_project: ralbum
68
+ rubygems_version: 1.3.1
69
+ signing_key:
70
+ specification_version: 2
71
+ summary: TODO
72
+ test_files:
73
+ - test/dircat/tc_dircat.rb
74
+ - test/dircat/tc_dircat_build.rb
75
+ - test/test_dircat.rb