durb 0.2 → 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/durb +11 -4
- data/lib/directory_inspector.rb +22 -6
- data/lib/directory_node.rb +8 -1
- data/lib/durb.rb +1 -1
- data/lib/reducer.rb +1 -1
- data/lib/text_output.rb +9 -4
- metadata +2 -2
data/bin/durb
CHANGED
@@ -41,7 +41,8 @@ opts = GetoptLong.new(
|
|
41
41
|
["--parsable", "--parseable", "-p", GetoptLong::REQUIRED_ARGUMENT],
|
42
42
|
["--help", "-h", GetoptLong::NO_ARGUMENT],
|
43
43
|
["--version", GetoptLong::NO_ARGUMENT],
|
44
|
-
["--cross-filesystems", "-x", GetoptLong::NO_ARGUMENT]
|
44
|
+
["--cross-filesystems", "-x", GetoptLong::NO_ARGUMENT],
|
45
|
+
["--fatal-warnings", "-W", GetoptLong::NO_ARGUMENT])
|
45
46
|
|
46
47
|
$options = {}
|
47
48
|
opts.each do |opt, arg|
|
@@ -49,7 +50,7 @@ opts.each do |opt, arg|
|
|
49
50
|
end
|
50
51
|
if $options[:version]
|
51
52
|
puts <<END_VERSION
|
52
|
-
durb v0.
|
53
|
+
durb v0.3
|
53
54
|
Copyright (c) 2009 Matteo Sasso
|
54
55
|
|
55
56
|
END_VERSION
|
@@ -86,13 +87,16 @@ Options:
|
|
86
87
|
By default durb only shows aggregate size for each directory shown.
|
87
88
|
This option enables a more complex report of the disk space used.
|
88
89
|
|
90
|
+
-W, --fatal-warnings
|
91
|
+
This flag makes all warnings fatal.
|
92
|
+
|
89
93
|
END_HELP
|
90
94
|
end
|
91
95
|
|
92
96
|
exit if $options[:version] or $options[:help]
|
93
97
|
|
94
98
|
if $options[:parsable]
|
95
|
-
raise ArgumentError, "--parsable and --verbose make no
|
99
|
+
raise ArgumentError, "--parsable and --verbose make no sense toghether" if $options[:verbose]
|
96
100
|
$options[:output_fields] = $options[:parsable].split(',')
|
97
101
|
$options[:output_fields].each do |f|
|
98
102
|
raise ArgumentError, ("Unknown field: %s" % f) if not FIELD_NAMES.include?(f)
|
@@ -114,7 +118,10 @@ $paths = ["."] if $paths.empty?
|
|
114
118
|
$paths = $paths.map{|p| File.expand_path(p)}
|
115
119
|
|
116
120
|
$path = $paths.first
|
117
|
-
$options[:threshold]
|
121
|
+
if not $options[:threshold]
|
122
|
+
$stderr.puts "INFO: using default threshold of %s" % DEFAULT_THRESHOLD
|
123
|
+
$options[:threshold] = DEFAULT_THRESHOLD
|
124
|
+
end
|
118
125
|
|
119
126
|
reduced_trees = []
|
120
127
|
$paths.each do |p|
|
data/lib/directory_inspector.rb
CHANGED
@@ -27,9 +27,9 @@ class DirectoryInspector
|
|
27
27
|
|
28
28
|
protected
|
29
29
|
def make_node(path)
|
30
|
-
size, files, subdirectories = scan(path)
|
30
|
+
size, files, subdirectories, flags = scan(path)
|
31
31
|
|
32
|
-
dir = DirectoryNode.new(path, size, files)
|
32
|
+
dir = DirectoryNode.new(path, size, files, flags)
|
33
33
|
subdirectories.map{|p| make_node(p)}.select{|n| not n.nil?}.each do |n|
|
34
34
|
dir.add_subdirectory(n)
|
35
35
|
end
|
@@ -45,7 +45,15 @@ protected
|
|
45
45
|
begin
|
46
46
|
dir = Dir.new(path_string)
|
47
47
|
rescue Errno::EACCES
|
48
|
-
|
48
|
+
$stderr.puts("%s: access denied to %s. %s" % [
|
49
|
+
$options[:fatal_warnings] ? "ERROR" : "WARNING",
|
50
|
+
path_string,
|
51
|
+
$options[:fatal_warnings] ? nil : "Skipped."])
|
52
|
+
if $options[:fatal_warnings]
|
53
|
+
exit
|
54
|
+
else
|
55
|
+
return 0, 0, [], [:imprecise]
|
56
|
+
end
|
49
57
|
rescue Errno::ENOENT
|
50
58
|
raise $!
|
51
59
|
end
|
@@ -55,12 +63,20 @@ protected
|
|
55
63
|
begin
|
56
64
|
st = File.lstat(fname)
|
57
65
|
rescue Errno::EACCES
|
58
|
-
|
66
|
+
$stderr.puts("%s: access denied to %s/*. %s" % [
|
67
|
+
$options[:fatal_warnings] ? "ERROR" : "WARNING",
|
68
|
+
path_string,
|
69
|
+
$options[:fatal_warnings] ? nil : "Skipped."])
|
70
|
+
if $options[:fatal_warnings]
|
71
|
+
exit
|
72
|
+
else
|
73
|
+
return 0, 0, [], [:imprecise]
|
74
|
+
end
|
59
75
|
rescue Errno::ENOENT, Errno::ELOOP
|
60
76
|
next
|
61
77
|
end
|
62
78
|
if @filesystem and st.dev != @filesystem
|
63
|
-
$stderr.puts("
|
79
|
+
$stderr.puts("INFO: different filesystem for %s. Skipped." % fname)
|
64
80
|
next
|
65
81
|
end
|
66
82
|
if st.file? or st.symlink?
|
@@ -73,6 +89,6 @@ protected
|
|
73
89
|
end
|
74
90
|
end
|
75
91
|
|
76
|
-
return size, files, subdirectories
|
92
|
+
return size, files, subdirectories, []
|
77
93
|
end
|
78
94
|
end
|
data/lib/directory_node.rb
CHANGED
@@ -20,8 +20,9 @@ class DirectoryNode
|
|
20
20
|
attr_accessor :size, :files, :big, :show
|
21
21
|
attr_accessor :s_subsize, :s_subfiles, :s_dirs
|
22
22
|
attr_accessor :i_subsize, :i_subfiles, :i_dirs, :i_rec_dirs
|
23
|
+
attr_accessor :flags
|
23
24
|
|
24
|
-
def initialize(path, size, files)
|
25
|
+
def initialize(path, size, files, flags)
|
25
26
|
@path = path
|
26
27
|
@size = size
|
27
28
|
@files = files
|
@@ -30,6 +31,11 @@ class DirectoryNode
|
|
30
31
|
@big = true
|
31
32
|
@show = false
|
32
33
|
@subdirectories = []
|
34
|
+
@flags = flags
|
35
|
+
end
|
36
|
+
|
37
|
+
def precise?
|
38
|
+
@flags.include?(:imprecise) ? false : true
|
33
39
|
end
|
34
40
|
|
35
41
|
def add_subdirectory(d)
|
@@ -37,6 +43,7 @@ class DirectoryNode
|
|
37
43
|
@s_subsize += d.s_subsize
|
38
44
|
@s_subfiles += d.s_subfiles
|
39
45
|
@s_dirs += d.s_dirs
|
46
|
+
@flags << :imprecise if not d.precise? and precise?
|
40
47
|
if d.big
|
41
48
|
@s_subsize += d.size + d.i_subsize
|
42
49
|
@s_subfiles += d.files + d.i_subfiles
|
data/lib/durb.rb
CHANGED
data/lib/reducer.rb
CHANGED
@@ -17,7 +17,7 @@
|
|
17
17
|
|
18
18
|
module Reducer
|
19
19
|
def self.run(tree, threshold)
|
20
|
-
rtree = DirectoryNode.new(tree.path, tree.size, tree.files)
|
20
|
+
rtree = DirectoryNode.new(tree.path, tree.size, tree.files, tree.flags)
|
21
21
|
|
22
22
|
tree.subdirectories.each{|n| rtree.add_subdirectory(run(n, threshold))}
|
23
23
|
rtree.big = ((rtree.size + rtree.i_subsize) >= threshold)
|
data/lib/text_output.rb
CHANGED
@@ -20,7 +20,7 @@ class TextOutput
|
|
20
20
|
|
21
21
|
def initialize(trees, output)
|
22
22
|
trees_width = trees.map{|t| calc_width(t)}.max
|
23
|
-
@width = trees_width + ($options[:verbose] ? 47 :
|
23
|
+
@width = trees_width + ($options[:verbose] ? 47 : 11)
|
24
24
|
@output = output
|
25
25
|
if output.tty?
|
26
26
|
begin
|
@@ -81,7 +81,7 @@ class TextOutput
|
|
81
81
|
if $options[:verbose]
|
82
82
|
size_and_isize = (node.size > 0 and node.i_subsize > 0)
|
83
83
|
tsize_and_ssize = (node.size + node.i_subsize > 0 and node.s_subsize > 0)
|
84
|
-
size_text = "%4s %1s %9s %1s %4s %1s %9s %1s %4s" % \
|
84
|
+
size_text = "%4s %1s %9s %1s %4s %1s %9s %1s %4s %1s" % \
|
85
85
|
[
|
86
86
|
(node.size > 0) ? size_to_text(node.size) : nil,
|
87
87
|
size_and_isize ? "+" : nil,
|
@@ -94,11 +94,16 @@ class TextOutput
|
|
94
94
|
[size_to_text(node.s_subsize), size_to_text(node.s_dirs)] : nil,
|
95
95
|
tsize_and_ssize ? "=" : nil,
|
96
96
|
(node.size + node.i_subsize + node.s_subsize > 0) ?
|
97
|
-
|
97
|
+
size_to_text(node.size + node.i_subsize + node.s_subsize) : nil,
|
98
|
+
node.precise? ? nil : "*",
|
98
99
|
]
|
99
100
|
else
|
100
101
|
total_size = node.size + node.i_subsize
|
101
|
-
size_text =
|
102
|
+
size_text = "%4s %1s" % \
|
103
|
+
[
|
104
|
+
total_size < size ? nil : size_to_text(total_size),
|
105
|
+
node.precise? ? nil : "*",
|
106
|
+
]
|
102
107
|
end
|
103
108
|
align((' ' * indentation) + (indentation == 0 ? node.path_string : node.name), size_text)
|
104
109
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: durb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.3"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matteo Sasso
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-05-03 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|