adding a 'p' option, to see the parent tree format

This commit is contained in:
Vincent Batts 2012-08-06 17:40:57 -04:00
parent 34514563b0
commit 9ca686aa6f
2 changed files with 40 additions and 6 deletions

View file

@ -12,7 +12,12 @@ content sets, output them to newline delimited output
`$> ruby ./thing.rb d this-cert.pem` `$> ruby ./thing.rb d this-cert.pem`
This would produce a file named 'this-cert.txt' This would produce a file named 'this-cert.txt'
Process this output to generate the compiled output
To see this txt list, in the tree format, do:
`$> ruby ./thing.rb p this-cert.txt | less`
Process this output to generate the compiled dictionary output
`$> ruby ./thing.rb c this-cert.txt` `$> ruby ./thing.rb c this-cert.txt`
@ -20,6 +25,8 @@ This would produce a file named 'this-cert.bin'
Then, the unpack the binary with: Then, the unpack the binary with:
`$> ./unpack this-cert.bin` `$> ./unpack this-cert.bin`
or
`$> ruby ./unpack.rb this-cert.bin`
The 'thing.rb' supports a "-v" verbose flag. The 'thing.rb' supports a "-v" verbose flag.

View file

@ -1,6 +1,6 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
=begin =begin
usage: ruby ./thing.rb [cd] 5286016419950084643.pem usage: ruby ./thing.rb <dpc> 5286016419950084643.{pem,txt}
=end =end
# stdlib # stdlib
@ -8,6 +8,7 @@ require 'openssl'
require 'zlib' require 'zlib'
require 'stringio' require 'stringio'
require 'logger' require 'logger'
require 'pp'
# gems # gems
require 'rubygems' require 'rubygems'
@ -228,6 +229,23 @@ def binary_write(file, parent, string_huff, node_huff)
end end
end end
def list_from_file(path)
paths = File.read(path)
paths.split("\n")
end
def tree_from_list(sets)
parent = Node.new("")
sets.each do |set|
line = set.start_with?("/") ? set[1..-1] : set
# => ["content", "beta", "rhel", "server", "6", "$releasever", "$basearch", "scalablefilesystem", "debug"]
chunks = line.split("/")
parent = mk_hash(chunks, parent)
end
parent
end
def write_strings(file, strings) def write_strings(file, strings)
string_io = StringIO.new() string_io = StringIO.new()
strings.each_key do |string| strings.each_key do |string|
@ -283,11 +301,13 @@ if $0 == __FILE__
puts "usage: thing.rb <d|c> <file>" puts "usage: thing.rb <d|c> <file>"
puts "please specify one of d or c" puts "please specify one of d or c"
puts "d - dump an x509 cert into a newline delimited output" puts "d - dump an x509 cert into a newline delimited output"
puts "p - pretty print the newline delimited list, as a tree"
puts "c - compress the newline delimited input list of paths" puts "c - compress the newline delimited input list of paths"
exit() exit()
end end
if ARGV[0] == 'd' case ARGV[0]
when 'd'
cert_data = File.read(ARGV[1]) cert_data = File.read(ARGV[1])
cert = OpenSSL::X509::Certificate.new(cert_data) cert = OpenSSL::X509::Certificate.new(cert_data)
@ -301,8 +321,13 @@ if $0 == __FILE__
file.write("\n") file.write("\n")
end end
exit() when 'p'
end sets = list_from_file(ARGV[1])
parent = tree_from_list(sets)
de_dupe_driver(parent)
pp parent.to_h
when 'c'
paths = File.read(ARGV[1]) paths = File.read(ARGV[1])
sets = paths.split("\n") sets = paths.split("\n")
@ -335,5 +360,7 @@ if $0 == __FILE__
bit_file = BitWriter.new file bit_file = BitWriter.new file
binary_write(bit_file, parent, string_huff, node_huff) binary_write(bit_file, parent, string_huff, node_huff)
bit_file.pad bit_file.pad
end end
end # esac
end end