tree.rb 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/tree.rb +1 -1
- data/lib/tree_rb.rb +40 -0
- data/lib/tree_rb/cli/cli_tree.rb +7 -1
- data/lib/tree_rb/directory_walker.rb +2 -2
- data/lib/tree_rb/version.rb +1 -1
- data/lib/tree_rb/visitors/build_dir_tree_visitor.rb +11 -2
- data/lib/tree_rb_cli.rb +18 -0
- data/lib/treevisitor.rb +1 -39
- data/lib/treevisitor_cli.rb +2 -17
- metadata +49 -41
data/bin/tree.rb
CHANGED
data/lib/tree_rb.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
#
|
4
|
+
# std lib
|
5
|
+
#
|
6
|
+
require 'pathname'
|
7
|
+
require 'yaml'
|
8
|
+
|
9
|
+
#
|
10
|
+
# rubygems
|
11
|
+
#
|
12
|
+
# require 'rubygems' # rubygems must be loaded from binary file (tree.rb) so $LOAD_PATH is not modified
|
13
|
+
require 'json'
|
14
|
+
require 'ansi/code'
|
15
|
+
|
16
|
+
#
|
17
|
+
# treevisitor
|
18
|
+
#
|
19
|
+
|
20
|
+
require "tree_rb/version"
|
21
|
+
require "tree_rb/abs_node"
|
22
|
+
require 'tree_rb/leaf_node'
|
23
|
+
require 'tree_rb/tree_node'
|
24
|
+
require 'tree_rb/basic_tree_node_visitor'
|
25
|
+
require 'tree_rb/tree_node_visitor'
|
26
|
+
|
27
|
+
require 'tree_rb/directory_walker'
|
28
|
+
|
29
|
+
#
|
30
|
+
# visitors
|
31
|
+
#
|
32
|
+
require 'tree_rb/visitors/block_tree_node_visitor'
|
33
|
+
require 'tree_rb/visitors/build_dir_tree_visitor'
|
34
|
+
require 'tree_rb/visitors/callback_tree_node_visitor2'
|
35
|
+
require 'tree_rb/visitors/clone_tree_node_visitor'
|
36
|
+
require 'tree_rb/visitors/depth_tree_node_visitor'
|
37
|
+
require 'tree_rb/visitors/print_dir_tree_visitor'
|
38
|
+
require 'tree_rb/visitors/directory_to_hash_visitor'
|
39
|
+
|
40
|
+
require 'tree_rb/util/dir_processor'
|
data/lib/tree_rb/cli/cli_tree.rb
CHANGED
@@ -74,6 +74,10 @@ module TreeRb
|
|
74
74
|
# end colorize
|
75
75
|
#
|
76
76
|
|
77
|
+
opts.on("-s", "Print the size of each file in bytes along with the name.") do
|
78
|
+
options[:show_size] = true
|
79
|
+
end
|
80
|
+
|
77
81
|
begin
|
78
82
|
rest = opts.parse(argv)
|
79
83
|
rescue OptionParser::InvalidOption => e
|
@@ -106,9 +110,11 @@ module TreeRb
|
|
106
110
|
when 'build-dir'
|
107
111
|
# TODO: capture CTRL^C
|
108
112
|
# http://ruby-doc.org/core-1.9.3/Kernel.html#method-i-trap
|
109
|
-
|
113
|
+
Signal.trap('INT') { put "User interrupted exit"; exit }
|
110
114
|
|
111
115
|
visitor = BuildDirTreeVisitor.new
|
116
|
+
visitor.show_size = options[:show_size]
|
117
|
+
|
112
118
|
dtw.run(visitor)
|
113
119
|
|
114
120
|
puts visitor.root.to_str('', options[:colorize])
|
@@ -275,7 +275,7 @@ module TreeRb
|
|
275
275
|
|
276
276
|
|
277
277
|
@visitor.enter_node(dirname)
|
278
|
-
entries.each
|
278
|
+
entries.each do |basename|
|
279
279
|
begin
|
280
280
|
next if basename == "." or basename == ".." # ignore always "." and ".."
|
281
281
|
pathname = File.join(dirname, basename)
|
@@ -292,7 +292,7 @@ module TreeRb
|
|
292
292
|
rescue Errno::EPERM
|
293
293
|
$stderr.puts e
|
294
294
|
end
|
295
|
-
|
295
|
+
end
|
296
296
|
|
297
297
|
@visitor.exit_node(dirname)
|
298
298
|
end
|
data/lib/tree_rb/version.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
module TreeRb
|
3
|
+
|
3
4
|
#
|
4
5
|
# Builds a TreeNode from a filesystem directory
|
5
6
|
# It similar to CloneTreeNodeVisitor
|
@@ -13,13 +14,14 @@ module TreeRb
|
|
13
14
|
#
|
14
15
|
attr_reader :nr_directories
|
15
16
|
|
16
|
-
|
17
17
|
#
|
18
18
|
# Number of visited directory (nr_leaves)
|
19
19
|
# @see AbsNode#nr_leaves
|
20
20
|
#
|
21
21
|
attr_reader :nr_files
|
22
22
|
|
23
|
+
attr_accessor :show_size
|
24
|
+
|
23
25
|
def initialize
|
24
26
|
super
|
25
27
|
@root = nil
|
@@ -49,7 +51,14 @@ module TreeRb
|
|
49
51
|
def visit_leaf( pathname )
|
50
52
|
@nr_files += 1
|
51
53
|
# connect the leaf_node created to the last tree_node on the stack
|
52
|
-
|
54
|
+
stat = File.lstat(pathname)
|
55
|
+
# stat.symlink?
|
56
|
+
if show_size
|
57
|
+
str = "#{File.basename(pathname)} #{stat.size}"
|
58
|
+
else
|
59
|
+
str = "#{File.basename(pathname)}"
|
60
|
+
end
|
61
|
+
LeafNode.new( str, @stack.last )
|
53
62
|
end
|
54
63
|
|
55
64
|
end
|
data/lib/tree_rb_cli.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# cli
|
4
|
+
#
|
5
|
+
|
6
|
+
require 'optparse'
|
7
|
+
require 'treevisitor'
|
8
|
+
|
9
|
+
begin
|
10
|
+
require 'Win32/Console/ANSI' if RUBY_PLATFORM =~ /win32/
|
11
|
+
rescue LoadError
|
12
|
+
puts 'You must gem install win32console to use color on Windows'
|
13
|
+
end
|
14
|
+
|
15
|
+
#
|
16
|
+
# gem
|
17
|
+
#
|
18
|
+
require "tree_rb/cli/cli_tree"
|
data/lib/treevisitor.rb
CHANGED
@@ -1,40 +1,2 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
-
|
3
|
-
#
|
4
|
-
# std lib
|
5
|
-
#
|
6
|
-
require 'pathname'
|
7
|
-
require 'yaml'
|
8
|
-
|
9
|
-
#
|
10
|
-
# rubygems
|
11
|
-
#
|
12
|
-
# require 'rubygems' # rubygems must be loaded from binary file (tree.rb) so $LOAD_PATH is not modified
|
13
|
-
require 'json'
|
14
|
-
require 'ansi/code'
|
15
|
-
|
16
|
-
#
|
17
|
-
# treevisitor
|
18
|
-
#
|
19
|
-
|
20
|
-
require "tree_rb/version"
|
21
|
-
require "tree_rb/abs_node"
|
22
|
-
require 'tree_rb/leaf_node'
|
23
|
-
require 'tree_rb/tree_node'
|
24
|
-
require 'tree_rb/basic_tree_node_visitor'
|
25
|
-
require 'tree_rb/tree_node_visitor'
|
26
|
-
|
27
|
-
require 'tree_rb/directory_walker'
|
28
|
-
|
29
|
-
#
|
30
|
-
# visitors
|
31
|
-
#
|
32
|
-
require 'tree_rb/visitors/block_tree_node_visitor'
|
33
|
-
require 'tree_rb/visitors/build_dir_tree_visitor'
|
34
|
-
require 'tree_rb/visitors/callback_tree_node_visitor2'
|
35
|
-
require 'tree_rb/visitors/clone_tree_node_visitor'
|
36
|
-
require 'tree_rb/visitors/depth_tree_node_visitor'
|
37
|
-
require 'tree_rb/visitors/print_dir_tree_visitor'
|
38
|
-
require 'tree_rb/visitors/directory_to_hash_visitor'
|
39
|
-
|
40
|
-
require 'tree_rb/util/dir_processor'
|
2
|
+
require 'tree_rb'
|
data/lib/treevisitor_cli.rb
CHANGED
@@ -1,18 +1,3 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
-
|
3
|
-
|
4
|
-
#
|
5
|
-
|
6
|
-
require 'optparse'
|
7
|
-
require 'treevisitor'
|
8
|
-
|
9
|
-
begin
|
10
|
-
require 'Win32/Console/ANSI' if RUBY_PLATFORM =~ /win32/
|
11
|
-
rescue LoadError
|
12
|
-
puts 'You must gem install win32console to use color on Windows'
|
13
|
-
end
|
14
|
-
|
15
|
-
#
|
16
|
-
# gem
|
17
|
-
#
|
18
|
-
require "tree_rb/cli/cli_tree"
|
2
|
+
warn "use require 'tree_rb_cli' instead of require 'treevisitor_cli'"
|
3
|
+
require 'tree_rb_cli'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tree.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
@@ -124,55 +124,57 @@ files:
|
|
124
124
|
- Rakefile
|
125
125
|
- tree.rb.gemspec
|
126
126
|
- .gemtest
|
127
|
-
- lib/
|
127
|
+
- lib/treevisitor.rb
|
128
128
|
- lib/tree_visitor.rb
|
129
|
-
- lib/
|
129
|
+
- lib/tree_rb_cli.rb
|
130
130
|
- lib/tree_rb/util/dir_processor.rb
|
131
|
+
- lib/tree_rb/abs_node.rb
|
132
|
+
- lib/tree_rb/version.rb
|
131
133
|
- lib/tree_rb/directory_walker.rb
|
132
|
-
- lib/tree_rb/
|
134
|
+
- lib/tree_rb/tree_node.rb
|
135
|
+
- lib/tree_rb/basic_tree_node_visitor.rb
|
136
|
+
- lib/tree_rb/tree_node_visitor.rb
|
137
|
+
- lib/tree_rb/cli/cli_tree.rb
|
138
|
+
- lib/tree_rb/visitors/block_tree_node_visitor.rb
|
139
|
+
- lib/tree_rb/visitors/flat_print_tree_node_visitors.rb
|
140
|
+
- lib/tree_rb/visitors/clone_tree_node_visitor.rb
|
133
141
|
- lib/tree_rb/visitors/build_dir_tree_visitor.rb
|
142
|
+
- lib/tree_rb/visitors/directory_to_hash_visitor.rb
|
134
143
|
- lib/tree_rb/visitors/depth_tree_node_visitor.rb
|
135
|
-
- lib/tree_rb/visitors/print_tree_node_visitor.rb
|
136
144
|
- lib/tree_rb/visitors/callback_tree_node_visitor2.rb
|
137
|
-
- lib/tree_rb/visitors/
|
138
|
-
- lib/tree_rb/visitors/
|
139
|
-
- lib/tree_rb/visitors/block_tree_node_visitor.rb
|
140
|
-
- lib/tree_rb/visitors/clone_tree_node_visitor.rb
|
141
|
-
- lib/tree_rb/abs_node.rb
|
145
|
+
- lib/tree_rb/visitors/print_tree_node_visitor.rb
|
146
|
+
- lib/tree_rb/visitors/print_dir_tree_visitor.rb
|
142
147
|
- lib/tree_rb/leaf_node.rb
|
143
|
-
- lib/tree_rb
|
144
|
-
- lib/
|
145
|
-
- lib/tree_rb/basic_tree_node_visitor.rb
|
146
|
-
- lib/tree_rb/version.rb
|
147
|
-
- lib/treevisitor.rb
|
148
|
+
- lib/tree_rb.rb
|
149
|
+
- lib/treevisitor_cli.rb
|
148
150
|
- tasks/rspec.rake
|
149
151
|
- tasks/yard.rake
|
150
|
-
- examples/directory_walker/print_files.rb
|
151
152
|
- examples/directory_walker/directory_without_subdirectory.rb
|
152
153
|
- examples/directory_walker/find_files.rb
|
153
|
-
- examples/
|
154
|
+
- examples/directory_walker/print_files.rb
|
155
|
+
- examples/protovis/treevisitor.js
|
154
156
|
- examples/protovis/protovis-r3.2.js
|
155
157
|
- examples/protovis/index.html
|
156
|
-
- examples/protovis/treevisitor.
|
158
|
+
- examples/protovis/treevisitor.png
|
157
159
|
- examples/protovis/directory_to_json_visitor.rb
|
158
|
-
- spec/
|
159
|
-
- spec/tree_rb/cli/cli_tree_spec.rb
|
160
|
+
- spec/tree_rb/tree_node_paths_spec.rb
|
160
161
|
- spec/tree_rb/util/dir_processor_spec.rb
|
161
|
-
- spec/tree_rb/
|
162
|
-
- spec/tree_rb/visitors/callback_tree_node_visitor2_spec.rb
|
163
|
-
- spec/tree_rb/visitors/block_tree_node_visitor_spec.rb
|
164
|
-
- spec/tree_rb/visitors/tree_node_visitors_spec.rb
|
165
|
-
- spec/tree_rb/tree_dsl_with_derived_class_spec.rb
|
162
|
+
- spec/tree_rb/tree_node_spec.rb
|
166
163
|
- spec/tree_rb/directory_walker_spec.rb
|
167
164
|
- spec/tree_rb/tree_dsl_spec.rb
|
168
|
-
- spec/tree_rb/tree_node_paths_spec.rb
|
169
165
|
- spec/tree_rb/tree_dsl_with_derived_class1_spec.rb
|
166
|
+
- spec/tree_rb/cli/cli_tree_spec.rb
|
167
|
+
- spec/tree_rb/visitors/depth_tree_node_visitor_spec.rb
|
168
|
+
- spec/tree_rb/visitors/tree_node_visitors_spec.rb
|
169
|
+
- spec/tree_rb/visitors/block_tree_node_visitor_spec.rb
|
170
|
+
- spec/tree_rb/visitors/callback_tree_node_visitor2_spec.rb
|
171
|
+
- spec/tree_rb/tree_dsl_with_derived_class_spec.rb
|
170
172
|
- spec/tree_rb/tree_node_visitor_delegate_spec.rb
|
171
|
-
- spec/tree_rb/tree_node_spec.rb
|
172
173
|
- spec/tree_rb/tree_node_visitor_dsl_spec.rb
|
173
|
-
- spec/
|
174
|
-
- spec/fixtures/test_dir_1/dir.1/file.1.1
|
174
|
+
- spec/spec_helper.rb
|
175
175
|
- spec/fixtures/test_dir_1/dir.2/file.2.1
|
176
|
+
- spec/fixtures/test_dir_1/dir.1/file.1.1
|
177
|
+
- spec/fixtures/test_dir_1/dir.1/dir.1.2/file.1.2.1
|
176
178
|
- spec/fixtures/test_dir_2/[Dsube]/sub/.gitkeep
|
177
179
|
- spec/fixtures/test_dir_1/.dir_with_dot/dummy.txt
|
178
180
|
- bin/tree.rb
|
@@ -188,12 +190,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
188
190
|
- - ! '>='
|
189
191
|
- !ruby/object:Gem::Version
|
190
192
|
version: '0'
|
193
|
+
segments:
|
194
|
+
- 0
|
195
|
+
hash: 3293516785273926334
|
191
196
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
192
197
|
none: false
|
193
198
|
requirements:
|
194
199
|
- - ! '>='
|
195
200
|
- !ruby/object:Gem::Version
|
196
201
|
version: '0'
|
202
|
+
segments:
|
203
|
+
- 0
|
204
|
+
hash: 3293516785273926334
|
197
205
|
requirements: []
|
198
206
|
rubyforge_project:
|
199
207
|
rubygems_version: 1.8.24
|
@@ -202,24 +210,24 @@ specification_version: 3
|
|
202
210
|
summary: tree.rb is a 'clone' of tree unix command. The gem implements a library to
|
203
211
|
mange tree structures.
|
204
212
|
test_files:
|
205
|
-
- spec/
|
206
|
-
- spec/tree_rb/cli/cli_tree_spec.rb
|
213
|
+
- spec/tree_rb/tree_node_paths_spec.rb
|
207
214
|
- spec/tree_rb/util/dir_processor_spec.rb
|
208
|
-
- spec/tree_rb/
|
209
|
-
- spec/tree_rb/visitors/callback_tree_node_visitor2_spec.rb
|
210
|
-
- spec/tree_rb/visitors/block_tree_node_visitor_spec.rb
|
211
|
-
- spec/tree_rb/visitors/tree_node_visitors_spec.rb
|
212
|
-
- spec/tree_rb/tree_dsl_with_derived_class_spec.rb
|
215
|
+
- spec/tree_rb/tree_node_spec.rb
|
213
216
|
- spec/tree_rb/directory_walker_spec.rb
|
214
217
|
- spec/tree_rb/tree_dsl_spec.rb
|
215
|
-
- spec/tree_rb/tree_node_paths_spec.rb
|
216
218
|
- spec/tree_rb/tree_dsl_with_derived_class1_spec.rb
|
219
|
+
- spec/tree_rb/cli/cli_tree_spec.rb
|
220
|
+
- spec/tree_rb/visitors/depth_tree_node_visitor_spec.rb
|
221
|
+
- spec/tree_rb/visitors/tree_node_visitors_spec.rb
|
222
|
+
- spec/tree_rb/visitors/block_tree_node_visitor_spec.rb
|
223
|
+
- spec/tree_rb/visitors/callback_tree_node_visitor2_spec.rb
|
224
|
+
- spec/tree_rb/tree_dsl_with_derived_class_spec.rb
|
217
225
|
- spec/tree_rb/tree_node_visitor_delegate_spec.rb
|
218
|
-
- spec/tree_rb/tree_node_spec.rb
|
219
226
|
- spec/tree_rb/tree_node_visitor_dsl_spec.rb
|
220
|
-
- spec/
|
221
|
-
- spec/fixtures/test_dir_1/dir.1/file.1.1
|
227
|
+
- spec/spec_helper.rb
|
222
228
|
- spec/fixtures/test_dir_1/dir.2/file.2.1
|
229
|
+
- spec/fixtures/test_dir_1/dir.1/file.1.1
|
230
|
+
- spec/fixtures/test_dir_1/dir.1/dir.1.2/file.1.2.1
|
223
231
|
- spec/fixtures/test_dir_2/[Dsube]/sub/.gitkeep
|
224
232
|
- spec/fixtures/test_dir_1/.dir_with_dot/dummy.txt
|
225
233
|
has_rdoc:
|