Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hdp-tree for printing a tree view of an hdfs directory
- Loading branch information
Jacob Perkins
committed
Mar 9, 2011
1 parent
c06a47a
commit 818d86e
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env jruby | ||
|
||
require 'swineherd' | ||
|
||
# | ||
# Creates a 'tree' view of an hdfs path. It's not as pretty as the | ||
# unix tree command but that's only because I'm not smart enough to | ||
# print the hierarchy properly. | ||
# | ||
|
||
FS = Swineherd::FileSystem.get(:hdfs) | ||
path = ARGV[0] | ||
|
||
# Recursively list paths | ||
def lr path | ||
paths = FS.entries(path) | ||
if (paths && !paths.empty?) | ||
paths.map{|e| {File.basename(path) => lr(e)}}.flatten | ||
else | ||
File.basename(path) | ||
end | ||
end | ||
|
||
|
||
tree = {path => lr(path)}.to_yaml | ||
puts tree |