2010-11-08 13:07:12 +00:00
|
|
|
#!/usr/bin/ruby
|
|
|
|
|
|
|
|
require 'optparse'
|
|
|
|
|
|
|
|
require 'rubygems'
|
|
|
|
require 'bindata'
|
|
|
|
|
2010-11-15 20:47:31 +00:00
|
|
|
require 'xtmfile/header'
|
|
|
|
require 'xtmfile/joiner'
|
|
|
|
require 'xtmfile/splitter'
|
2010-11-08 13:07:12 +00:00
|
|
|
|
|
|
|
class XtmJoin
|
|
|
|
class XtmJoinArgumentError < ArgumentError ; end
|
|
|
|
|
|
|
|
attr_reader :opts
|
|
|
|
|
2010-11-09 10:13:45 +00:00
|
|
|
BUFFER_MAX_SIZE = 4096 * 4096
|
2010-11-08 13:07:12 +00:00
|
|
|
|
|
|
|
def initialize args
|
|
|
|
@args = []
|
2010-11-08 16:42:12 +00:00
|
|
|
@input_filename = nil
|
2010-11-08 13:07:12 +00:00
|
|
|
parse_command_line args
|
|
|
|
end
|
|
|
|
|
|
|
|
def parse_command_line args
|
|
|
|
@args = args.clone
|
|
|
|
@opts = OptionParser.new do |opts|
|
|
|
|
opts.banner = "Usage: #{File.basename $0} [options]\n"
|
|
|
|
|
|
|
|
opts.separator ""
|
2010-11-15 20:47:31 +00:00
|
|
|
opts.separator "Options"
|
2010-11-08 13:07:12 +00:00
|
|
|
|
2010-11-15 20:47:31 +00:00
|
|
|
opts.on("-i", "--input FILE", "Input XTM file (mandatory)") do |r|
|
2010-11-08 16:42:12 +00:00
|
|
|
@input_filename = r
|
2010-11-08 13:07:12 +00:00
|
|
|
end
|
|
|
|
|
2010-11-15 20:47:31 +00:00
|
|
|
opts.on("-o", "--output FILE", "Output file (optional)") do |o|
|
|
|
|
@output_filename = o
|
|
|
|
end
|
|
|
|
|
|
|
|
opts.on("-m", "--md5", "Verify MD5 sums") do |m|
|
|
|
|
@verify_md5 = m
|
|
|
|
end
|
2010-11-08 13:07:12 +00:00
|
|
|
|
|
|
|
opts.on("-h", "--help", "Show this help") do |h|
|
|
|
|
@help = h
|
|
|
|
end
|
2010-11-15 20:47:31 +00:00
|
|
|
|
2010-11-08 13:07:12 +00:00
|
|
|
opts.on("-v", "--verbose", "Show warnings too") do |v|
|
|
|
|
@verbose = v
|
|
|
|
end
|
|
|
|
opts.separator ""
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def validate!
|
|
|
|
@opts.parse!
|
|
|
|
|
2010-11-08 16:42:12 +00:00
|
|
|
raise XtmJoinArgumentError, "No input XTM file specified!" if @input_filename.nil?
|
|
|
|
|
|
|
|
raise RuntimeError, "Current input XTM does not exist!" unless File.exist? @input_filename
|
|
|
|
raise RuntimeError, "Current input XTML is not a file!" unless File.file? @input_filename
|
|
|
|
@input_filename = File.expand_path @input_filename
|
2010-11-08 13:07:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
|
|
|
validate!
|
2010-11-15 20:47:31 +00:00
|
|
|
|
2010-11-08 13:07:12 +00:00
|
|
|
# FIXME: prevent overwriting
|
2010-11-15 20:47:31 +00:00
|
|
|
|
|
|
|
xtmj = XtmFile::Joiner.new @input_filename, @output_filename
|
|
|
|
puts "Writing data to %s" % xtmj.output_filename
|
|
|
|
|
|
|
|
xtmj.start do |event, info|
|
|
|
|
case event
|
|
|
|
when XtmFile::Joiner::EVENT_OPENFILE then
|
|
|
|
puts "Opening %s" % info
|
|
|
|
when XtmFile::Joiner::EVENT_PROGRESS then
|
|
|
|
print "\x1b[uProgress : %s %" % info
|
2010-11-09 10:13:45 +00:00
|
|
|
STDOUT.flush
|
2010-11-08 16:42:12 +00:00
|
|
|
end
|
2010-11-08 13:07:12 +00:00
|
|
|
end
|
|
|
|
|
2010-11-15 20:47:31 +00:00
|
|
|
STDOUT.puts ""
|
2010-11-08 16:42:12 +00:00
|
|
|
end
|
|
|
|
|
2010-11-08 13:07:12 +00:00
|
|
|
def self.main args
|
|
|
|
xj = nil
|
|
|
|
begin
|
|
|
|
xj = XtmJoin.new args
|
|
|
|
xj.run
|
|
|
|
exit 0
|
|
|
|
rescue XtmJoinArgumentError => e
|
|
|
|
STDERR.puts "%s" % xj.opts
|
|
|
|
STDERR.puts "error: %s" % e.message
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
rescue SystemExit => e
|
|
|
|
raise e
|
|
|
|
rescue Exception => e
|
|
|
|
STDERR.puts "error: %s" % e.message
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
XtmJoin.main ARGV
|