htmldu 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +32 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/htmldu +5 -0
- data/bin/setup +7 -0
- data/htmldu.gemspec +24 -0
- data/img/sample.png +0 -0
- data/lib/htmldu/commands.rb +59 -0
- data/lib/htmldu/dirtree.rb +48 -0
- data/lib/htmldu/js/show.js +52 -0
- data/lib/htmldu/version.rb +3 -0
- data/lib/htmldu.rb +3 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2c4eed3f2c953776ca1a31b0e93770556ec6490c
|
4
|
+
data.tar.gz: e57cb1decf308b923783f94ec2a5859925df96e4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3841e7f6ec78cb30005b023ccc11b256b86e85fffa03710620a4e26fa231c0520927bd6cc2fd99e72b8707a37b33e2b01718d786e4260222d2ede5c6de37711d
|
7
|
+
data.tar.gz: c48fb5f9daf0afe2d310fad208e98323854fdf2bf566f24ab1b3f4757ebc1db6a17b69b748363e197b7eb31d336f6819d81428a7075ccaa7ff4b77abcd8ff756
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Takeshi SASAKI
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Htmldu
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/htmldu`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```
|
12
|
+
$ gem install htmldu
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
```
|
18
|
+
$ htmldu /usr/local/Cellar
|
19
|
+
```
|
20
|
+
will open browser and show directory hierarchy:
|
21
|
+
|
22
|
+

|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
|
26
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/dagezi/htmldu.
|
27
|
+
|
28
|
+
|
29
|
+
## License
|
30
|
+
|
31
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
32
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "htmldu"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/htmldu
ADDED
data/bin/setup
ADDED
data/htmldu.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'htmldu/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "htmldu"
|
8
|
+
spec.version = Htmldu::VERSION
|
9
|
+
spec.authors = ["Takeshi SASAKI"]
|
10
|
+
spec.email = ["dagezi@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Generates HTML showing hierarchical disk usages.}
|
13
|
+
spec.description = %q{Generates HTML showing hierarchical disk usages.}
|
14
|
+
spec.homepage = ""
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
end
|
data/img/sample.png
ADDED
Binary file
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "tempfile"
|
2
|
+
|
3
|
+
module Htmldu
|
4
|
+
class Commands
|
5
|
+
def self.start(args, script_dir)
|
6
|
+
command = self.new(args[0], script_dir)
|
7
|
+
command.exec
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(dir, script_dir)
|
11
|
+
@dir = dir
|
12
|
+
@script_dir = script_dir
|
13
|
+
@dirtree = Htmldu::Dirtree.new(@dir)
|
14
|
+
end
|
15
|
+
|
16
|
+
def open_command
|
17
|
+
@open_command ||=
|
18
|
+
case RbConfig::CONFIG['host_os']
|
19
|
+
when /darwin/
|
20
|
+
'open'
|
21
|
+
when /linux|bsd/
|
22
|
+
'xdg-open'
|
23
|
+
when /mswin|mingw|cygwin/
|
24
|
+
'start'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def exec()
|
29
|
+
@dirtree.generate_tree
|
30
|
+
|
31
|
+
json_file = Tempfile.create("htmldu")
|
32
|
+
json_file.write "dirtree="
|
33
|
+
json_file.write @dirtree.to_json
|
34
|
+
json_file.close
|
35
|
+
json_path = json_file.path + ".js"
|
36
|
+
json_url = "file://#{json_path}"
|
37
|
+
File.rename(json_file.path, json_path)
|
38
|
+
|
39
|
+
script_url = "file://#{@script_dir}/lib/htmldu/js/show.js"
|
40
|
+
|
41
|
+
html_file = Tempfile.create("htmldu")
|
42
|
+
html_file.write <<"EOS"
|
43
|
+
<html>
|
44
|
+
<head>
|
45
|
+
<title> DU: #{@dir} </title>
|
46
|
+
<script src="#{json_url}"></script>
|
47
|
+
</head>
|
48
|
+
<body>
|
49
|
+
</body>
|
50
|
+
<script src="#{script_url}"></script>
|
51
|
+
</html>
|
52
|
+
EOS
|
53
|
+
html_file.close
|
54
|
+
html_path = html_file.path + ".html"
|
55
|
+
File.rename(html_file.path, html_path)
|
56
|
+
system "#{open_command} #{html_path}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Htmldu
|
4
|
+
class Dirtree
|
5
|
+
attr_reader :path, :name, :root, :blocks, :children
|
6
|
+
|
7
|
+
BLOCK_SIZE=512
|
8
|
+
|
9
|
+
def initialize(root, name = nil)
|
10
|
+
@root = root
|
11
|
+
@name = name
|
12
|
+
@path = name ? File.join(root, name) : root
|
13
|
+
end
|
14
|
+
|
15
|
+
def generate_tree()
|
16
|
+
blocks = 0
|
17
|
+
@children = []
|
18
|
+
Dir.foreach(@path) do |name|
|
19
|
+
next if name == '.' or name == '..'
|
20
|
+
path = File.join(@path, name)
|
21
|
+
stat = File.lstat(path)
|
22
|
+
blocks += stat.blocks
|
23
|
+
|
24
|
+
if stat.directory? and !stat.symlink?
|
25
|
+
child = Dirtree.new(@path, name)
|
26
|
+
child.generate_tree
|
27
|
+
@children << child
|
28
|
+
blocks += child.blocks
|
29
|
+
end
|
30
|
+
end
|
31
|
+
@blocks = blocks
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_json(json: '')
|
35
|
+
json << "{\"name\":\"#{@name}\","
|
36
|
+
json << "\"path\":\"#{@path}\","
|
37
|
+
json << "\"blocks\":#{@blocks},"
|
38
|
+
json << '"children":['
|
39
|
+
c = ''
|
40
|
+
@children.each { |dir|
|
41
|
+
json << c
|
42
|
+
dir.to_json(json: json)
|
43
|
+
c = ','
|
44
|
+
}
|
45
|
+
json << ']}'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
function formatBlocks(blocks) {
|
2
|
+
var unit = 'k'
|
3
|
+
var num = blocks / 2;
|
4
|
+
if (num > 512) {
|
5
|
+
num /= 1024;
|
6
|
+
unit = 'M'
|
7
|
+
}
|
8
|
+
if (num > 512) {
|
9
|
+
num /= 1024
|
10
|
+
unit = 'G'
|
11
|
+
}
|
12
|
+
return num.toFixed(1) + unit
|
13
|
+
}
|
14
|
+
|
15
|
+
function subdraw(ctx, dirtree, left, width, top, height) {
|
16
|
+
ctx.save()
|
17
|
+
ctx.strokeRect(left, top, width, height)
|
18
|
+
ctx.beginPath()
|
19
|
+
ctx.moveTo(left, top)
|
20
|
+
ctx.lineTo(left + width, top)
|
21
|
+
ctx.lineTo(left + width, top + height)
|
22
|
+
ctx.lineTo(left, top + height)
|
23
|
+
ctx.closePath()
|
24
|
+
ctx.clip()
|
25
|
+
|
26
|
+
ctx.font = '16px sans-serif'
|
27
|
+
ctx.fillText(formatBlocks(dirtree.blocks) + "(" + dirtree.name + ")", left + 1, top + 16, width)
|
28
|
+
|
29
|
+
|
30
|
+
ctx.restore()
|
31
|
+
var y = top
|
32
|
+
var children = dirtree.children.sort(function (a, b) {
|
33
|
+
return b.blocks - a.blocks
|
34
|
+
})
|
35
|
+
for (var i = 0; i < children.length; i++) {
|
36
|
+
var child = children[i]
|
37
|
+
var h = height * child.blocks / dirtree.blocks
|
38
|
+
subdraw(ctx, child, left + width, width, y, h)
|
39
|
+
y += h
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
function draw(canvas, dirtree) {
|
44
|
+
var ctx = canvas.getContext('2d')
|
45
|
+
subdraw(ctx, dirtree, 10, 200, 10, 800)
|
46
|
+
}
|
47
|
+
|
48
|
+
var canvas = document.createElement('canvas')
|
49
|
+
canvas.setAttribute('width', '800')
|
50
|
+
canvas.setAttribute('height', '800')
|
51
|
+
document.body.insertBefore(canvas, null)
|
52
|
+
draw(canvas, dirtree)
|
data/lib/htmldu.rb
ADDED
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: htmldu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Takeshi SASAKI
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Generates HTML showing hierarchical disk usages.
|
42
|
+
email:
|
43
|
+
- dagezi@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- bin/console
|
54
|
+
- bin/htmldu
|
55
|
+
- bin/setup
|
56
|
+
- htmldu.gemspec
|
57
|
+
- img/sample.png
|
58
|
+
- lib/htmldu.rb
|
59
|
+
- lib/htmldu/commands.rb
|
60
|
+
- lib/htmldu/dirtree.rb
|
61
|
+
- lib/htmldu/js/show.js
|
62
|
+
- lib/htmldu/version.rb
|
63
|
+
homepage: ''
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata: {}
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.4.5.1
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: Generates HTML showing hierarchical disk usages.
|
87
|
+
test_files: []
|