durb 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +9 -0
- data/README.txt +2 -1
- data/bin/durb +103 -18
- data/lib/directory_inspector.rb +31 -11
- data/lib/directory_node.rb +52 -14
- data/lib/durb.rb +1 -1
- data/lib/human_readable.rb +20 -4
- data/lib/reducer.rb +19 -5
- data/lib/text_output.rb +84 -25
- metadata +4 -4
data/History.txt
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
=== 0.2 / 2009-02-13
|
2
|
+
|
3
|
+
* Added help message.
|
4
|
+
* Added machine readable output.
|
5
|
+
* Added support for multiple paths.
|
6
|
+
* Modified human-readable sizes to be shorter and easier on the eye.
|
7
|
+
* Added more details and sanity to verbose mode.
|
8
|
+
* Small fixes and cleanups.
|
9
|
+
|
1
10
|
=== 0.1 / 2009-02-11
|
2
11
|
|
3
12
|
* First release
|
data/README.txt
CHANGED
@@ -4,7 +4,8 @@
|
|
4
4
|
|
5
5
|
== DESCRIPTION:
|
6
6
|
|
7
|
-
durb is a smarter du.
|
7
|
+
durb is a smarter du(1).
|
8
|
+
It's a CLI ruby utility which intelligently displays disk usage under a directory or filesystem. durb hides unimportant directories to make it easier to find out where all your disk-space has gone.
|
8
9
|
|
9
10
|
== FEATURES/PROBLEMS:
|
10
11
|
|
data/bin/durb
CHANGED
@@ -1,7 +1,25 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Copyright (c) 2009 Matteo Sasso
|
4
|
+
#
|
5
|
+
# This file is part of durb.
|
6
|
+
#
|
7
|
+
# durb is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# durb is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with durb. If not, see <http://www.gnu.org/licenses/>.
|
2
19
|
|
3
20
|
require 'getoptlong'
|
4
21
|
|
22
|
+
$:.unshift(File.dirname(__FILE__) + "/../lib")
|
5
23
|
require 'human_readable'
|
6
24
|
require 'text_output'
|
7
25
|
require 'directory_node'
|
@@ -10,30 +28,97 @@ require 'reducer'
|
|
10
28
|
|
11
29
|
include HumanReadable
|
12
30
|
|
13
|
-
|
31
|
+
DEFAULT_THRESHOLD = "100m"
|
32
|
+
FIELD_NAMES = %w(path self-size small-dirs_size aggregate-size big_dirs-size total-size)
|
33
|
+
|
34
|
+
def string_to_sym(s)
|
35
|
+
s.sub('--', '').tr('-', '_').to_sym
|
36
|
+
end
|
14
37
|
|
15
38
|
opts = GetoptLong.new(
|
16
|
-
["--
|
17
|
-
["--width", "-w", GetoptLong::REQUIRED_ARGUMENT],
|
39
|
+
["--threshold", "-t", GetoptLong::REQUIRED_ARGUMENT],
|
18
40
|
["--verbose", "-v", GetoptLong::NO_ARGUMENT],
|
19
|
-
["--
|
41
|
+
["--parsable", "--parseable", "-p", GetoptLong::REQUIRED_ARGUMENT],
|
42
|
+
["--help", "-h", GetoptLong::NO_ARGUMENT],
|
43
|
+
["--version", GetoptLong::NO_ARGUMENT],
|
44
|
+
["--cross-filesystems", "-x", GetoptLong::NO_ARGUMENT])
|
20
45
|
|
46
|
+
$options = {}
|
21
47
|
opts.each do |opt, arg|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
48
|
+
$options[string_to_sym(opt)] = arg.empty? ? true : arg
|
49
|
+
end
|
50
|
+
if $options[:version]
|
51
|
+
puts <<END_VERSION
|
52
|
+
durb v0.2
|
53
|
+
Copyright (c) 2009 Matteo Sasso
|
54
|
+
|
55
|
+
END_VERSION
|
56
|
+
end
|
57
|
+
if $options[:help]
|
58
|
+
puts <<END_HELP
|
59
|
+
Synopsis:
|
60
|
+
durb shows where disk space is used. If no path is given, the current
|
61
|
+
directory is used. Disk usage of each path and its subdirectories is
|
62
|
+
calculated and displayed.
|
63
|
+
|
64
|
+
Usage:
|
65
|
+
durb [OPTION]... [PATH]...
|
66
|
+
|
67
|
+
Options:
|
68
|
+
-h, --help
|
69
|
+
Displays this text and exits.
|
70
|
+
|
71
|
+
-p, --parsable, --parseable=FIELDS
|
72
|
+
The output is optimized for usage in a script. FIELDS is a
|
73
|
+
comma-separated list of output fields to display. Available fields:
|
74
|
+
#{FIELD_NAMES.join(", ")}
|
75
|
+
|
76
|
+
-t, --threshold=SIZE
|
77
|
+
Sets the discrimination threshold. Directories above the size
|
78
|
+
specified are displayed, the others are aggregated.
|
79
|
+
SIZE can use one of the suffixes: k, m, g.
|
80
|
+
By default the threshold is #{DEFAULT_THRESHOLD}.
|
81
|
+
|
82
|
+
-x, --cross-filesystems
|
83
|
+
Descend directories even when they are on different filesystems.
|
84
|
+
|
85
|
+
-v, --verbose
|
86
|
+
By default durb only shows aggregate size for each directory shown.
|
87
|
+
This option enables a more complex report of the disk space used.
|
88
|
+
|
89
|
+
END_HELP
|
90
|
+
end
|
91
|
+
|
92
|
+
exit if $options[:version] or $options[:help]
|
93
|
+
|
94
|
+
if $options[:parsable]
|
95
|
+
raise ArgumentError, "--parsable and --verbose make no sens toghether" if $options[:verbose]
|
96
|
+
$options[:output_fields] = $options[:parsable].split(',')
|
97
|
+
$options[:output_fields].each do |f|
|
98
|
+
raise ArgumentError, ("Unknown field: %s" % f) if not FIELD_NAMES.include?(f)
|
31
99
|
end
|
100
|
+
$options[:output_fields] = $options[:output_fields].map{|f| string_to_sym(f)}
|
101
|
+
$options[:no_header] = true
|
102
|
+
$options[:exact] = true
|
103
|
+
$options[:parsable] = true
|
32
104
|
end
|
33
105
|
|
34
|
-
$
|
35
|
-
|
106
|
+
$paths = []
|
107
|
+
ARGV.each do |p|
|
108
|
+
while File.symlink?(p)
|
109
|
+
p = File.readlink(p)
|
110
|
+
end
|
111
|
+
$paths << p
|
112
|
+
end
|
113
|
+
$paths = ["."] if $paths.empty?
|
114
|
+
$paths = $paths.map{|p| File.expand_path(p)}
|
36
115
|
|
37
|
-
|
38
|
-
|
39
|
-
|
116
|
+
$path = $paths.first
|
117
|
+
$options[:threshold] ||= DEFAULT_THRESHOLD
|
118
|
+
|
119
|
+
reduced_trees = []
|
120
|
+
$paths.each do |p|
|
121
|
+
tree = DirectoryInspector.new(p).run
|
122
|
+
reduced_trees << Reducer.run(tree, text_to_size($options[:threshold]))
|
123
|
+
end
|
124
|
+
TextOutput.new(reduced_trees, $stdout).print_all(text_to_size($options[:threshold]))
|
data/lib/directory_inspector.rb
CHANGED
@@ -1,7 +1,24 @@
|
|
1
|
+
# Copyright (c) 2009 Matteo Sasso
|
2
|
+
#
|
3
|
+
# This file is part of durb.
|
4
|
+
#
|
5
|
+
# durb is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# durb is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with durb. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
1
18
|
class DirectoryInspector
|
2
|
-
def initialize(path
|
19
|
+
def initialize(path)
|
3
20
|
@path = DirectoryNode.string_to_path(path)
|
4
|
-
@filesystem = options[:
|
21
|
+
@filesystem = $options[:cross_filesystems] ? nil : File.stat(path).dev
|
5
22
|
end
|
6
23
|
|
7
24
|
def run
|
@@ -10,7 +27,7 @@ class DirectoryInspector
|
|
10
27
|
|
11
28
|
protected
|
12
29
|
def make_node(path)
|
13
|
-
size, files, subdirectories =
|
30
|
+
size, files, subdirectories = scan(path)
|
14
31
|
|
15
32
|
dir = DirectoryNode.new(path, size, files)
|
16
33
|
subdirectories.map{|p| make_node(p)}.select{|n| not n.nil?}.each do |n|
|
@@ -20,7 +37,7 @@ protected
|
|
20
37
|
return dir
|
21
38
|
end
|
22
39
|
|
23
|
-
def
|
40
|
+
def scan(path)
|
24
41
|
path_string = DirectoryNode.path_to_string(path)
|
25
42
|
size = files = 0
|
26
43
|
subdirectories = []
|
@@ -30,11 +47,11 @@ protected
|
|
30
47
|
rescue Errno::EACCES
|
31
48
|
raise $!
|
32
49
|
rescue Errno::ENOENT
|
33
|
-
|
50
|
+
raise $!
|
34
51
|
end
|
35
52
|
dir.each do |f|
|
36
|
-
next if
|
37
|
-
fname = path_string + f
|
53
|
+
next if f == ".."
|
54
|
+
fname = path_string + '/' + f
|
38
55
|
begin
|
39
56
|
st = File.lstat(fname)
|
40
57
|
rescue Errno::EACCES
|
@@ -42,13 +59,16 @@ protected
|
|
42
59
|
rescue Errno::ENOENT, Errno::ELOOP
|
43
60
|
next
|
44
61
|
end
|
45
|
-
|
46
|
-
|
47
|
-
|
62
|
+
if @filesystem and st.dev != @filesystem
|
63
|
+
$stderr.puts("SKIPPED: different filesystem for %s" % fname)
|
64
|
+
next
|
65
|
+
end
|
66
|
+
if st.file? or st.symlink?
|
48
67
|
size += (512 * st.blocks)
|
49
68
|
files += 1
|
69
|
+
elsif f == "."
|
70
|
+
size += (512 * st.blocks)
|
50
71
|
elsif st.directory?
|
51
|
-
# Need to add directory size?
|
52
72
|
subdirectories << path + [f]
|
53
73
|
end
|
54
74
|
end
|
data/lib/directory_node.rb
CHANGED
@@ -1,41 +1,79 @@
|
|
1
|
+
# Copyright (c) 2009 Matteo Sasso
|
2
|
+
#
|
3
|
+
# This file is part of durb.
|
4
|
+
#
|
5
|
+
# durb is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# durb is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with durb. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
1
18
|
class DirectoryNode
|
2
19
|
attr_reader :path, :subdirectories
|
3
|
-
attr_accessor :size, :files, :
|
20
|
+
attr_accessor :size, :files, :big, :show
|
21
|
+
attr_accessor :s_subsize, :s_subfiles, :s_dirs
|
22
|
+
attr_accessor :i_subsize, :i_subfiles, :i_dirs, :i_rec_dirs
|
4
23
|
|
5
|
-
def initialize(path, size, files
|
24
|
+
def initialize(path, size, files)
|
6
25
|
@path = path
|
7
26
|
@size = size
|
8
27
|
@files = files
|
9
|
-
@
|
10
|
-
@
|
28
|
+
@s_subsize = @s_subfiles = @s_dirs = 0
|
29
|
+
@i_subsize = @i_subfiles = @i_dirs = @i_rec_dirs = 0
|
30
|
+
@big = true
|
31
|
+
@show = false
|
11
32
|
@subdirectories = []
|
12
33
|
end
|
13
34
|
|
14
35
|
def add_subdirectory(d)
|
15
36
|
@subdirectories << d
|
16
|
-
|
17
|
-
|
18
|
-
|
37
|
+
@s_subsize += d.s_subsize
|
38
|
+
@s_subfiles += d.s_subfiles
|
39
|
+
@s_dirs += d.s_dirs
|
40
|
+
if d.big
|
41
|
+
@s_subsize += d.size + d.i_subsize
|
42
|
+
@s_subfiles += d.files + d.i_subfiles
|
43
|
+
@s_dirs += 1 + d.i_dirs
|
44
|
+
else
|
45
|
+
@i_subsize += d.size + d.i_subsize
|
46
|
+
@i_subfiles += d.files + d.i_subfiles
|
47
|
+
@i_rec_dirs += 1 + d.i_dirs
|
48
|
+
@i_dirs += 1
|
19
49
|
end
|
20
50
|
end
|
21
51
|
|
22
|
-
def
|
23
|
-
@subdirectories.select{|n| n.
|
24
|
-
end
|
25
|
-
|
26
|
-
def insignificant_subdirectories
|
27
|
-
@subdirectories.select{|n| not n.significant}
|
52
|
+
def shown_subdirs
|
53
|
+
@subdirectories.select{|n| n.show}
|
28
54
|
end
|
29
55
|
|
30
56
|
def path_string
|
31
57
|
self.class.path_to_string(@path)
|
32
58
|
end
|
33
59
|
|
60
|
+
def name
|
61
|
+
@path[-1]
|
62
|
+
end
|
63
|
+
|
34
64
|
def self.path_to_string(path)
|
35
|
-
path.length == 0 ? '/' : ('/' + path.join('/')
|
65
|
+
path.length == 0 ? '/' : ('/' + path.join('/'))
|
36
66
|
end
|
37
67
|
|
38
68
|
def self.string_to_path(path_string)
|
39
69
|
path_string == '/' ? [] : path_string.split('/').reject{|component| component.empty?}
|
40
70
|
end
|
71
|
+
|
72
|
+
def inspect(indentation = 0)
|
73
|
+
' ' * indentation +
|
74
|
+
"#<DirectoryNode:#{path_string} size=#{@size} " +
|
75
|
+
(@big ? "big " : "small ") + (@show ? "shown" : "hidden") +
|
76
|
+
(@subdirectories.empty? ? "" : ("\n" + @subdirectories.map{|d| d.inspect(indentation+2)}.join("\n"))) +
|
77
|
+
">"
|
78
|
+
end
|
41
79
|
end
|
data/lib/durb.rb
CHANGED
data/lib/human_readable.rb
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
# Copyright (c) 2009 Matteo Sasso
|
2
|
+
#
|
3
|
+
# This file is part of durb.
|
4
|
+
#
|
5
|
+
# durb is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# durb is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with durb. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
1
18
|
module HumanReadable
|
2
19
|
SUFFIXES = [' ', 'k', 'm', 'g', 't', 'p']
|
3
20
|
|
@@ -11,17 +28,16 @@ module HumanReadable
|
|
11
28
|
|
12
29
|
def size_to_text(size)
|
13
30
|
exp = 0
|
31
|
+
return size.to_s if size < 10000
|
14
32
|
while size > 999
|
15
33
|
size /= 1024.0
|
16
34
|
exp += 1
|
17
35
|
end
|
18
36
|
|
19
|
-
if size
|
20
|
-
"%d%s" % [size.round, SUFFIXES[exp]]
|
21
|
-
elsif size >= 10
|
37
|
+
if size < 10
|
22
38
|
"%.1f%s" % [size, SUFFIXES[exp]]
|
23
39
|
else
|
24
|
-
"
|
40
|
+
"%d%s" % [size.round, SUFFIXES[exp]]
|
25
41
|
end
|
26
42
|
end
|
27
43
|
end
|
data/lib/reducer.rb
CHANGED
@@ -1,13 +1,27 @@
|
|
1
|
+
# Copyright (c) 2009 Matteo Sasso
|
2
|
+
#
|
3
|
+
# This file is part of durb.
|
4
|
+
#
|
5
|
+
# durb is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# durb is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with durb. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
1
18
|
module Reducer
|
2
19
|
def self.run(tree, threshold)
|
3
20
|
rtree = DirectoryNode.new(tree.path, tree.size, tree.files)
|
4
21
|
|
5
22
|
tree.subdirectories.each{|n| rtree.add_subdirectory(run(n, threshold))}
|
6
|
-
rtree.
|
7
|
-
|
8
|
-
rtree.files += n.files
|
9
|
-
end
|
10
|
-
rtree.significant = (rtree.size >= threshold or not rtree.significant_subdirectories.empty?)
|
23
|
+
rtree.big = ((rtree.size + rtree.i_subsize) >= threshold)
|
24
|
+
rtree.show = (rtree.big or not rtree.shown_subdirs.empty?)
|
11
25
|
|
12
26
|
return rtree
|
13
27
|
end
|
data/lib/text_output.rb
CHANGED
@@ -1,57 +1,112 @@
|
|
1
|
+
# Copyright (c) 2009 Matteo Sasso
|
2
|
+
#
|
3
|
+
# This file is part of durb.
|
4
|
+
#
|
5
|
+
# durb is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# durb is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with durb. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
1
18
|
class TextOutput
|
2
|
-
|
3
|
-
|
19
|
+
DEFAULT_WIDTH = 78
|
20
|
+
|
21
|
+
def initialize(trees, output)
|
22
|
+
trees_width = trees.map{|t| calc_width(t)}.max
|
23
|
+
@width = trees_width + ($options[:verbose] ? 47 : 9)
|
4
24
|
@output = output
|
5
25
|
if output.tty?
|
6
26
|
begin
|
7
27
|
tput = open("|tput cols")
|
8
28
|
max_width = tput.gets.to_i
|
9
29
|
rescue
|
10
|
-
max_width =
|
30
|
+
max_width = ENV["COLUMNS"]
|
31
|
+
max_width = max_width ? max_width.to_i : DEFAULT_WIDTH
|
11
32
|
end
|
12
33
|
@width = [max_width, @width].min
|
13
34
|
end
|
14
|
-
@
|
15
|
-
@options = options
|
35
|
+
@trees = trees
|
16
36
|
end
|
17
37
|
|
18
38
|
def print_all(size)
|
19
|
-
if
|
20
|
-
|
21
|
-
|
39
|
+
if $options[:verbose] # and not $options[:no_header]
|
40
|
+
# The commented-out code is unneeded right now but may be necessary in the future
|
41
|
+
heading1 = " SMALL DIRS AGGREG BIG DIRS "
|
42
|
+
heading2 = "SIZE SIZE/# SIZE SIZE/# TOTAL"
|
43
|
+
puts((" " * (@width - heading1.size - 2)) + heading1)
|
44
|
+
puts((" " * (@width - heading2.size - 2)) + heading2)
|
45
|
+
end
|
46
|
+
@trees.each do |t|
|
47
|
+
print_tree(t, size)
|
22
48
|
end
|
23
|
-
print_tree(@tree, size)
|
24
49
|
end
|
25
50
|
|
26
51
|
def print_tree(tree, size, indentation = 0)
|
27
52
|
print_node(tree, size, indentation)
|
28
|
-
tree.
|
53
|
+
tree.shown_subdirs.each do |n|
|
29
54
|
print_tree(n, size, indentation + 2)
|
30
55
|
end
|
31
56
|
end
|
32
57
|
|
33
58
|
def print_node(node, size, indentation)
|
34
|
-
if $
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
59
|
+
if $options[:parsable]
|
60
|
+
@output.puts($options[:output_fields].map do |f|
|
61
|
+
case f
|
62
|
+
when :path
|
63
|
+
if $options[:output_fields].size == 1
|
64
|
+
node.path_string
|
65
|
+
else
|
66
|
+
node.path_string.gsub(":", "\\:")
|
67
|
+
end
|
68
|
+
when :self_size
|
69
|
+
node.size
|
70
|
+
when :small_dirs_size
|
71
|
+
node.i_subsize
|
72
|
+
when :aggregate_size
|
73
|
+
node.i_subsize + node.size
|
74
|
+
when :big_dirs_size
|
75
|
+
node.s_subsize
|
76
|
+
when :total_size
|
77
|
+
node.s_subsize + node.i_subsize + node.size
|
78
|
+
end
|
79
|
+
end.join(':'))
|
80
|
+
else
|
81
|
+
if $options[:verbose]
|
82
|
+
size_and_isize = (node.size > 0 and node.i_subsize > 0)
|
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" % \
|
85
|
+
[
|
86
|
+
(node.size > 0) ? size_to_text(node.size) : nil,
|
87
|
+
size_and_isize ? "+" : nil,
|
88
|
+
(node.i_subsize > 0) ? "%4s/%-4s" % \
|
89
|
+
[size_to_text(node.i_subsize), size_to_text(node.i_dirs)] : nil,
|
90
|
+
size_and_isize ? "=" : nil,
|
91
|
+
(node.size + node.i_subsize > 0) ? size_to_text(node.size + node.i_subsize) : nil,
|
92
|
+
tsize_and_ssize ? "+" : nil,
|
93
|
+
(node.s_subsize > 0) ? "%4s/%-4s" % \
|
94
|
+
[size_to_text(node.s_subsize), size_to_text(node.s_dirs)] : nil,
|
95
|
+
tsize_and_ssize ? "=" : nil,
|
96
|
+
(node.size + node.i_subsize + node.s_subsize > 0) ?
|
97
|
+
size_to_text(node.size + node.i_subsize + node.s_subsize) : nil,
|
98
|
+
]
|
42
99
|
else
|
43
|
-
|
100
|
+
total_size = node.size + node.i_subsize
|
101
|
+
size_text = total_size < size ? nil : size_to_text(total_size)
|
44
102
|
end
|
45
|
-
|
46
|
-
total_size = node.size #+ node.subsize
|
47
|
-
size_text = total_size < size ? nil : size_to_text(total_size)
|
103
|
+
align((' ' * indentation) + (indentation == 0 ? node.path_string : node.name), size_text)
|
48
104
|
end
|
49
|
-
align((' ' * indentation) + node.path_string, size_text)
|
50
105
|
end
|
51
106
|
|
52
107
|
def calc_width(tree, indentation = 0)
|
53
|
-
(tree.
|
54
|
-
[tree.path_string.size +
|
108
|
+
(tree.shown_subdirs.map{|n| calc_width(n, indentation + 2)} +
|
109
|
+
[(indentation == 0) ? tree.path_string.size : indentation + tree.name.size]).max
|
55
110
|
end
|
56
111
|
|
57
112
|
def align(left, right)
|
@@ -62,6 +117,10 @@ class TextOutput
|
|
62
117
|
size = 0
|
63
118
|
end
|
64
119
|
@output.print left, ' '
|
120
|
+
if size < 4
|
121
|
+
@output.print " " * size
|
122
|
+
size = 0
|
123
|
+
end
|
65
124
|
if not right.empty?
|
66
125
|
y = 0
|
67
126
|
while size > 0
|
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.2"
|
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-02-
|
12
|
+
date: 2009-02-22 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -22,7 +22,7 @@ dependencies:
|
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: 1.8.3
|
24
24
|
version:
|
25
|
-
description: durb is a smarter du. It's a CLI ruby utility which intelligently displays disk usage under a directory or filesystem. durb hides unimportant directories to make it easier to find out where all your disk-space has gone.
|
25
|
+
description: durb is a smarter du(1). It's a CLI ruby utility which intelligently displays disk usage under a directory or filesystem. durb hides unimportant directories to make it easier to find out where all your disk-space has gone.
|
26
26
|
email:
|
27
27
|
- matteo.sasso@gmail.com
|
28
28
|
executables:
|
@@ -71,6 +71,6 @@ rubyforge_project: durb
|
|
71
71
|
rubygems_version: 1.3.1
|
72
72
|
signing_key:
|
73
73
|
specification_version: 2
|
74
|
-
summary: durb is a smarter du
|
74
|
+
summary: durb is a smarter du(1)
|
75
75
|
test_files:
|
76
76
|
- test/test_durb.rb
|