xtmjoin: Progressbar & new naming pattern.
* Added progressbar display using ANSI sequences ; * Handle a new naming pattern (.xtm.*) .
This commit is contained in:
parent
485b4f41ec
commit
be090694e2
1 changed files with 25 additions and 7 deletions
32
bin/xtmjoin
32
bin/xtmjoin
|
@ -13,6 +13,7 @@ class XtmJoin
|
||||||
|
|
||||||
attr_reader :opts
|
attr_reader :opts
|
||||||
|
|
||||||
|
BUFFER_MAX_SIZE = 4096 * 4096
|
||||||
|
|
||||||
def initialize args
|
def initialize args
|
||||||
@args = []
|
@args = []
|
||||||
|
@ -74,6 +75,7 @@ class XtmJoin
|
||||||
cur_xtm = @input_filename
|
cur_xtm = @input_filename
|
||||||
is_first = true
|
is_first = true
|
||||||
cur_size = header.filesize
|
cur_size = header.filesize
|
||||||
|
print "\x1b[s"
|
||||||
while cur_size > 0 do
|
while cur_size > 0 do
|
||||||
unless is_first then
|
unless is_first then
|
||||||
cur_xtm = _nextfile cur_xtm
|
cur_xtm = _nextfile cur_xtm
|
||||||
|
@ -81,8 +83,15 @@ class XtmJoin
|
||||||
in_xtm = File.open cur_xtm, "rb"
|
in_xtm = File.open cur_xtm, "rb"
|
||||||
end
|
end
|
||||||
while cur_size > 0 and (not in_xtm.eof?) do
|
while cur_size > 0 and (not in_xtm.eof?) do
|
||||||
puts "Remaining : %s bytes" % cur_size
|
pcent = ((header.filesize - cur_size) * 100 / header.filesize)
|
||||||
buffer = in_xtm.read cur_size
|
|
||||||
|
STDOUT.print "\x1b[uProgress : %s %" % pcent
|
||||||
|
STDOUT.flush
|
||||||
|
|
||||||
|
read_size = if cur_size > BUFFER_MAX_SIZE then BUFFER_MAX_SIZE
|
||||||
|
else cur_size
|
||||||
|
end
|
||||||
|
buffer = in_xtm.read read_size
|
||||||
cur_size = cur_size - buffer.length
|
cur_size = cur_size - buffer.length
|
||||||
out_xtm.write buffer.slice(0, buffer.length)
|
out_xtm.write buffer.slice(0, buffer.length)
|
||||||
end
|
end
|
||||||
|
@ -90,21 +99,30 @@ class XtmJoin
|
||||||
in_xtm.close
|
in_xtm.close
|
||||||
end
|
end
|
||||||
out_xtm.close
|
out_xtm.close
|
||||||
|
STDOUT.puts ""
|
||||||
|
|
||||||
# remaining files
|
# remaining files
|
||||||
end
|
end
|
||||||
|
|
||||||
def _nextfile curfile
|
def _nextfile curfile
|
||||||
|
result = nil
|
||||||
cur_idx = 0
|
cur_idx = 0
|
||||||
cur_len = 0
|
cur_len = 0
|
||||||
if curfile =~ /\.([0-9]+)\.xtm$/ then
|
case curfile
|
||||||
|
when /\.([0-9]+)\.xtm$/ then
|
||||||
cur_idx = $1.to_i
|
cur_idx = $1.to_i
|
||||||
cur_len = $1.length
|
cur_len = $1.length
|
||||||
|
next_idx = cur_idx + 1
|
||||||
|
result = curfile.gsub(/\.([0-9]+)\.xtm$/, ".%0#{cur_len}d.xtm" % next_idx)
|
||||||
|
when /\.xtm\.([0-9]+)$/ then
|
||||||
|
cur_idx = $1.to_i
|
||||||
|
cur_len = $1.length
|
||||||
|
next_idx = cur_idx + 1
|
||||||
|
result = curfile.gsub(/\.xtm\.([0-9]+)$/, ".xtm.%0#{cur_len}d" % next_idx)
|
||||||
|
else
|
||||||
|
raise "Unable to detect a naming patterng for file sequence!"
|
||||||
end
|
end
|
||||||
next_idx = cur_idx + 1
|
return result
|
||||||
|
|
||||||
nf = curfile.gsub(/\.([0-9]+)\.xtm$/, ".%0#{cur_len}d.xtm" % next_idx)
|
|
||||||
return nf
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.main args
|
def self.main args
|
||||||
|
|
Loading…
Reference in a new issue