dircat 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,30 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
2
+
3
+ describe CliDirCat do
4
+
5
+ before do
6
+ @dir1_dirname = File.join(TEST_DIR, "dir1")
7
+ @dir2_dirname = File.join(TEST_DIR, "dir2")
8
+ @certified_output_dirname = File.join(TEST_DIR, "certified_output")
9
+ @tmp_output_dirname = File.join(TEST_DIR, "tmp")
10
+ end
11
+
12
+ context "common args" do
13
+ it "should accept -h (-help) option" do
14
+ out = with_stdout_captured do
15
+ args = %w{-h}
16
+ CliDirCat.new.parse_and_execute(args)
17
+ end
18
+ out.should match /Usage:/
19
+ end
20
+
21
+ it "should accept --version option" do
22
+ out = with_stdout_captured do
23
+ args = %w{--version}
24
+ CliDirCat.new.parse_and_execute(args)
25
+ end
26
+ out.should match /#{DirCat::version}/
27
+ end
28
+ end
29
+
30
+ end
@@ -0,0 +1,49 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
2
+
3
+ describe CommandBuild do
4
+
5
+ before do
6
+ @dir1_dirname = File.join(TEST_DIR, "dir1")
7
+ @dir2_dirname = File.join(TEST_DIR, "dir2")
8
+ @certified_output_dirname = File.join(TEST_DIR, "certified_output")
9
+ @tmp_output_dirname = File.join(TEST_DIR, "tmp")
10
+ end
11
+
12
+ it "should accept -h (-help) option" do
13
+ out = with_stdout_captured do
14
+ args = %w{build -h}
15
+ CliDirCat.new.parse_and_execute(args)
16
+ end
17
+ out.should match /Usage:/
18
+ end
19
+
20
+ it "should not accept more then -o options" do
21
+ out = with_stdout_captured do
22
+ args = "build -f -o filename -o filename1"
23
+ CliDirCat.new.parse_and_execute(args.split)
24
+ end
25
+ out.should match /only one file/
26
+ end
27
+
28
+
29
+ it "should build a catalog from a directory" do
30
+ expect_filename = File.join(@certified_output_dirname, "dircat1.yaml")
31
+ result_filename = File.join(@tmp_output_dirname, "dircat1.yaml")
32
+
33
+ out = with_stdout_captured do
34
+ args = "build -f -o #{result_filename} #{@dir1_dirname}"
35
+ CliDirCat.new.parse_and_execute(args.split)
36
+ end
37
+
38
+ cat_expect = Cat.from_file(expect_filename)
39
+ cat_result = Cat.from_file(result_filename)
40
+
41
+ (cat_result - cat_result).size.should == 0
42
+
43
+ (cat_result - cat_expect).size.should == 0
44
+ (cat_expect - cat_result).size.should == 0
45
+
46
+ FileUtils.rm(result_filename)
47
+ end
48
+
49
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path( File.join(File.dirname(__FILE__), "..", "..", "spec_helper") )
2
+
3
+ describe CommandDiff do
4
+
5
+ it "should accept -h (help) option" do
6
+ out = with_stdout_captured do
7
+ args = %w{diff -h}
8
+ CliDirCat.new.parse_and_execute(args)
9
+ end
10
+ out.should match /Usage:/
11
+ end
12
+
13
+ end
@@ -0,0 +1,26 @@
1
+ require File.expand_path( File.join(File.dirname(__FILE__), "..", "..", "spec_helper") )
2
+
3
+ describe CommandQuery do
4
+
5
+ before do
6
+ @certified_output_dirname = File.join( TEST_DIR, "certified_output" )
7
+ end
8
+
9
+ it "should accept -h (help) option" do
10
+ out = with_stdout_captured do
11
+ args = %w{query -h}
12
+ CliDirCat.new.parse_and_execute(args)
13
+ end
14
+ out.should match /Usage:/
15
+ end
16
+
17
+ it "should show catalogs info" do
18
+ cat_filename = File.join( @certified_output_dirname, "dircat1.yaml" )
19
+ out = with_stdout_captured do
20
+ args = "query #{cat_filename}"
21
+ CliDirCat.new.parse_and_execute(args.split)
22
+ end
23
+ out.should match /file: 2/
24
+ out.should match /Bytes: 4/
25
+ end
26
+ end
@@ -6,7 +6,7 @@ describe "MD5" do
6
6
 
7
7
  it "test_simple_md5" do
8
8
  file_name = File.join( TEST_FILE )
9
- MD5.file( file_name ).to_s.should == "8777d9d35da17496e21dcc8a4f9f8191"
9
+ MD5.file( file_name ).to_s.should == "eb29e47aba9693862895688422171221"
10
10
  end
11
11
 
12
12
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 4
9
- version: 0.1.4
8
+ - 5
9
+ version: 0.1.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Tokiro
@@ -14,11 +14,11 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-17 00:00:00 +01:00
18
- default_executable:
17
+ date: 2011-01-16 00:00:00 +01:00
18
+ default_executable: dircat
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: jeweler
21
+ name: treevisitor
22
22
  requirement: &id001 !ruby/object:Gem::Requirement
23
23
  none: false
24
24
  requirements:
@@ -27,24 +27,26 @@ dependencies:
27
27
  segments:
28
28
  - 0
29
29
  version: "0"
30
- type: :development
30
+ type: :runtime
31
31
  prerelease: false
32
32
  version_requirements: *id001
33
33
  - !ruby/object:Gem::Dependency
34
- name: rake
34
+ name: optparse-command
35
35
  requirement: &id002 !ruby/object:Gem::Requirement
36
36
  none: false
37
37
  requirements:
38
- - - ">="
38
+ - - "="
39
39
  - !ruby/object:Gem::Version
40
40
  segments:
41
41
  - 0
42
- version: "0"
43
- type: :development
42
+ - 1
43
+ - 0
44
+ version: 0.1.0
45
+ type: :runtime
44
46
  prerelease: false
45
47
  version_requirements: *id002
46
48
  - !ruby/object:Gem::Dependency
47
- name: yard
49
+ name: jeweler
48
50
  requirement: &id003 !ruby/object:Gem::Requirement
49
51
  none: false
50
52
  requirements:
@@ -57,7 +59,7 @@ dependencies:
57
59
  prerelease: false
58
60
  version_requirements: *id003
59
61
  - !ruby/object:Gem::Dependency
60
- name: bundler
62
+ name: rake
61
63
  requirement: &id004 !ruby/object:Gem::Requirement
62
64
  none: false
63
65
  requirements:
@@ -70,7 +72,7 @@ dependencies:
70
72
  prerelease: false
71
73
  version_requirements: *id004
72
74
  - !ruby/object:Gem::Dependency
73
- name: rspec
75
+ name: yard
74
76
  requirement: &id005 !ruby/object:Gem::Requirement
75
77
  none: false
76
78
  requirements:
@@ -82,12 +84,36 @@ dependencies:
82
84
  type: :development
83
85
  prerelease: false
84
86
  version_requirements: *id005
87
+ - !ruby/object:Gem::Dependency
88
+ name: bundler
89
+ requirement: &id006 !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ type: :development
98
+ prerelease: false
99
+ version_requirements: *id006
100
+ - !ruby/object:Gem::Dependency
101
+ name: rspec
102
+ requirement: &id007 !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ segments:
108
+ - 0
109
+ version: "0"
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *id007
85
113
  description: "\n command line utilites to manage catalogs of directory\n "
86
114
  email: tokiro.oyama@gmail.com
87
115
  executables:
88
- - dircat-build
89
- - dircat-diff
90
- - dircat-query
116
+ - dircat
91
117
  extensions: []
92
118
 
93
119
  extra_rdoc_files:
@@ -102,17 +128,19 @@ files:
102
128
  - examples/example.rb
103
129
  - lib/dircat.rb
104
130
  - lib/dircat/cat.rb
105
- - lib/dircat/cli/dircat_build.rb
106
- - lib/dircat/cli/dircat_diff.rb
107
- - lib/dircat/cli/dircat_query.rb
131
+ - lib/dircat/cli/cli_dircat.rb
132
+ - lib/dircat/cli/command_build.rb
133
+ - lib/dircat/cli/command_diff.rb
134
+ - lib/dircat/cli/command_query.rb
108
135
  - lib/dircat/entry.rb
109
136
  - lib/dircat/extension_md5.rb
110
137
  - lib/dircat/extension_numeric.rb
111
138
  - lib/dircat/report.rb
112
139
  - 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
140
+ - spec/dircat/cli/cli_dircat_spec.rb
141
+ - spec/dircat/cli/command_build_spec.rb
142
+ - spec/dircat/cli/command_diff_spec.rb
143
+ - spec/dircat/cli/command_query_spec.rb
116
144
  - spec/dircat/md5_spec.rb
117
145
  - spec/dircat/numeric_spec.rb
118
146
  - spec/fixtures/certified_output/dircat1.yaml
@@ -126,9 +154,7 @@ files:
126
154
  - spec/fixtures/dir3/subdir/file1.txt
127
155
  - spec/fixtures/tmp/dummy.txt
128
156
  - spec/spec_helper.rb
129
- - bin/dircat-build
130
- - bin/dircat-diff
131
- - bin/dircat-query
157
+ - bin/dircat
132
158
  has_rdoc: true
133
159
  homepage: http://github.com/tokiro/dircat
134
160
  licenses: []
@@ -163,9 +189,10 @@ specification_version: 3
163
189
  summary: command line utilites to manage catalogs of directory
164
190
  test_files:
165
191
  - 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
192
+ - spec/dircat/cli/cli_dircat_spec.rb
193
+ - spec/dircat/cli/command_build_spec.rb
194
+ - spec/dircat/cli/command_diff_spec.rb
195
+ - spec/dircat/cli/command_query_spec.rb
169
196
  - spec/dircat/md5_spec.rb
170
197
  - spec/dircat/numeric_spec.rb
171
198
  - spec/fixtures/certified_output/dircat1.yaml
data/bin/dircat-build DELETED
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env ruby
2
- $:.unshift File.join( File.dirname( __FILE__), "..", "lib" )
3
-
4
- require 'dircat'
5
- include DirCat
6
- exit DirCatBuild.run
data/bin/dircat-diff DELETED
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env ruby
2
- $:.unshift File.join( File.dirname( __FILE__), "..", "lib" )
3
-
4
- require 'dircat'
5
- include DirCat
6
- exit DirCatDiff.run
data/bin/dircat-query DELETED
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env ruby
2
- $:.unshift(File.join( File.dirname( __FILE__), "..", "lib" ))
3
-
4
- require 'dircat'
5
- include DirCat
6
- exit DirCatQuery.run
@@ -1,114 +0,0 @@
1
- module DirCat
2
- #
3
- # Build a catalogue starting from a directory
4
- #
5
- class DirCatBuild
6
-
7
- def self.run
8
- return self.new.parse_args( ARGV )
9
- end
10
-
11
- def parse_args( argv )
12
- options = { :verbose => true, :force => false }
13
- opts = OptionParser.new
14
- opts.banner << "Usage: dircat-build [options]\n"
15
- opts.banner << "\n"
16
- opts.banner << "Build a catalogue starting from a directory\n";
17
- opts.banner << "\n"
18
-
19
- opts.on("-h", "--help", "Print this message") do
20
- puts opts
21
- return 0
22
- end
23
-
24
- opts.on("--version", "show the dircat version") do
25
- puts "dircat version #{DirCat::version}"
26
- return 0
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
- if options[:output]
43
- puts "only one file of output can be used"
44
- return 1
45
- end
46
- options[:output] = v
47
- end
48
-
49
- rest = opts.parse(argv)
50
-
51
- # p options
52
- # p ARGV
53
-
54
- if rest.length < 1
55
- puts "directory (from which build catalog) is missing"
56
- puts "-h to print help"
57
- return 0
58
- end
59
-
60
- dirname = rest[0]
61
- dirname = File.expand_path( dirname )
62
- cat_opts = {}
63
-
64
- if not FileTest.directory?(dirname)
65
- puts "'#{dirname}' not exists or is not a directory"
66
- return 0
67
- end
68
-
69
- #
70
- # option verbose
71
- #
72
-
73
- if options.has_key?(:verbose)
74
- if options[:verbose]
75
- cat_opts[:verbose_level] = 1
76
- end
77
- end
78
-
79
- #
80
- # option: output, force
81
- #
82
- output = $stdout
83
- if options.has_key?(:output)
84
- if options[:output]
85
- filename = options[:output]
86
- else
87
- filename = "cat_" + File.basename( dirname ) + "_" + Date.today.strftime("%Y%m%d") + ".yaml"
88
- end
89
- if File.exist?(filename) and not options[:force]
90
- puts "catalog '#{filename}' exists use --force or -f to overwrite"
91
- return 0
92
- end
93
- output = File.open(filename, "w")
94
- end
95
-
96
- start_time = Time.now
97
- s = Cat.from_dir(dirname)
98
- end_time = Time.now
99
-
100
- # s.pr
101
- # f.puts s.to_yaml
102
- s.save_to( output )
103
-
104
- if output != $stdout
105
- output.close
106
- end
107
- $stderr.puts s.report
108
- $stderr.puts "elapsed: #{end_time - start_time}"
109
-
110
- 0
111
- end
112
-
113
- end
114
- end
@@ -1,85 +0,0 @@
1
- module DirCat
2
-
3
- class DirCatDiff
4
-
5
- def self.run
6
- return self.new.parse_args( ARGV )
7
- end
8
-
9
- def parse_args( args )
10
- options = {}
11
- opts = OptionParser.new
12
- opts.banner =
13
- "Usage: dircat_cfr.rb [options] <filedircat1> <filedircat2>\n\n" +
14
- "fa la differenza fra il primo catalog e il secondo\n" +
15
- "<filedircat1> - <filedircat2>\n" +
16
- "e stampa sull'output con un formato\n"
17
-
18
- opts.on("-h", "--help", "Print this message") do
19
- puts opts
20
- return 0
21
- end
22
-
23
- opts.on("--version", "show the dircat version") do
24
- puts "dircat version #{DirCat::version}"
25
- return 0
26
- end
27
-
28
- opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
29
- options[:verbose] = v
30
- end
31
-
32
- opts.on("-f FORMAT", "--fmt FORMAT", "formato") do |v|
33
- options[:fmt] = v
34
- end
35
- rest = opts.parse( args )
36
-
37
- # p options
38
- # p ARGV
39
-
40
- if rest.length < 2
41
- puts "you must provide two args (catalogs or directory)"
42
- puts "dircat_cfr -h to print help"
43
- exit
44
- end
45
-
46
- cat_filename1 = rest[0]
47
- cat_filename2 = rest[1]
48
-
49
- if File.exists?( cat_filename1 )
50
- puts "load catalog #{cat_filename1}"
51
- s1 = Cat.from_file(cat_filename1)
52
- elsif File.directory?(cat_filename1)
53
- puts "build first set from directory #{cat_filename1}"
54
- s1 = Cat.from_dir(cat_filename1)
55
- else
56
- puts "#{cat_filename1} is not a catalog file or directory"
57
- return 1
58
- end
59
-
60
- if File.exists?( cat_filename2 )
61
- puts "load catalog #{cat_filename2}"
62
- s2 = Cat.from_file(cat_filename2)
63
- elsif File.directory?(cat_filename2)
64
- puts "build first set from directory #{cat_filename2}"
65
- s2 = Cat.from_dir(cat_filename2)
66
- else
67
- puts "#{cat_filename2} is not a catalog file or directory"
68
- return 1
69
- end
70
-
71
- puts "build difference"
72
- s3 = s1 - s2
73
-
74
- case options[:fmt]
75
- when "simple"
76
- s3.fmt_simple
77
- when "ruby"
78
- s3.fmt_ruby( "." )
79
- else
80
- s3.fmt_simple
81
- end
82
- 0
83
- end
84
- end
85
- end
@@ -1,69 +0,0 @@
1
- module DirCat
2
-
3
- class DirCatQuery
4
-
5
- def self.run
6
- return self.new.parse_args( ARGV)
7
- end
8
-
9
- def parse_args( args )
10
- options = {}
11
- opts = OptionParser.new
12
- opts.banner =
13
- "Usage: dircat-query [options] <filedircat> [<command>]\n" +
14
- "show info on dircat catalogs\n"
15
-
16
- opts.on("--version", "show the dircat version") do
17
- puts "dircat version #{DirCat::version}"
18
- return 0
19
- end
20
-
21
- opts.on("-h", "--help", "Print this message") do
22
- puts opts
23
- return 0
24
- end
25
-
26
- opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
27
- options[:verbose] = v
28
- end
29
-
30
- rest = opts.parse( args )
31
-
32
- # p options
33
- # p ARGV
34
-
35
- if rest.length < 1
36
- puts "missing catalog!"
37
- puts "-h to print help"
38
- return 0
39
- end
40
-
41
- cat_opts = {}
42
- cat_filename = rest[0]
43
- unless File.exists?(cat_filename)
44
- puts "first args must be a catalogue"
45
- return 1
46
- end
47
-
48
- if rest.length > 1
49
- command = rest[1]
50
- else
51
- command = "report"
52
- end
53
-
54
- #
55
- # option verbose
56
- #
57
- if options.has_key?(:verbose)
58
- if options[:verbose]
59
- cat_opts[:verbose_level] = 1
60
- end
61
- end
62
-
63
- s = Cat.from_file( cat_filename, cat_opts )
64
-
65
- puts s.send( command.to_sym )
66
- 0
67
- end
68
- end
69
- end
@@ -1,59 +0,0 @@
1
- require File.expand_path( File.join(File.dirname(__FILE__), "..", "..", "spec_helper") )
2
-
3
- describe DirCatBuild do
4
-
5
- before do
6
- @testdata_dirname = TEST_DIR
7
- @dir1_dirname = File.join( @testdata_dirname, "dir1" )
8
- @dir2_dirname = File.join( @testdata_dirname, "dir2" )
9
- @certified_output_dirname = File.join( @testdata_dirname, "certified_output" )
10
- @tmp_output_dirname = File.join( @testdata_dirname, "tmp" )
11
- end
12
-
13
- it "should accept -h (-help) option" do
14
- out = with_stdout_captured do
15
- args = %w{-h}
16
- DirCatBuild.new.parse_args(args)
17
- end
18
- out.should match /Usage:/
19
- end
20
-
21
- it "should accept --version option" do
22
- out = with_stdout_captured do
23
- args = %w{--version}
24
- DirCatBuild.new.parse_args(args)
25
- end
26
- out.should match /#{DirCat::version}/
27
- end
28
-
29
- it "should not accept more then -o options" do
30
- out = with_stdout_captured do
31
- args = "-f -o filename -o filename1"
32
- DirCatBuild.new.parse_args( args.split )
33
- end
34
- out.should match /only one file/
35
- end
36
-
37
-
38
- it "should build a catalog from a directory" do
39
- expect_filename = File.join( @certified_output_dirname, "dircat1.yaml" )
40
- result_filename = File.join( @tmp_output_dirname, "dircat1.yaml")
41
-
42
- out = with_stdout_captured do
43
- args = "-f -o #{result_filename} #{@dir1_dirname}"
44
- DirCatBuild.new.parse_args( args.split )
45
- end
46
- # out.should match /Usage:/
47
-
48
- cat_expect = Cat.from_file( expect_filename )
49
- cat_result = Cat.from_file( result_filename )
50
-
51
- (cat_result - cat_result).size.should == 0
52
-
53
- (cat_result - cat_expect).size.should == 0
54
- (cat_expect - cat_result).size.should == 0
55
-
56
- FileUtils.rm(result_filename)
57
- end
58
-
59
- end
@@ -1,26 +0,0 @@
1
- require File.expand_path( File.join(File.dirname(__FILE__), "..", "..", "spec_helper") )
2
-
3
- describe DirCatDiff do
4
-
5
- before do
6
- @testdata_dirname = TEST_DIR
7
- @certified_output_dirname = File.join( @testdata_dirname, "certified_output" )
8
- end
9
-
10
- it "should accept -h (help) option" do
11
- out = with_stdout_captured do
12
- args = %w{-h}
13
- DirCatDiff.new.parse_args(args)
14
- end
15
- out.should match /Usage:/
16
- end
17
-
18
- it "should accept --version option" do
19
- out = with_stdout_captured do
20
- args = %w{--version}
21
- DirCatDiff.new.parse_args(args)
22
- end
23
- out.should match /#{DirCat::version}/
24
- end
25
-
26
- end