Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 34 additions & 7 deletions metis/bin/metis_client
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def config_exists?
end

def progress_bar(completion, bar_size=20)
progress = "+"*(bar_size * completion) + " "*(bar_size*(1-completion)).ceil
progress = "+"*(bar_size * completion) + " "*(bar_size*(1-completion)).ceil + "|"
end

def byte_format(bytes)
Expand All @@ -44,8 +44,16 @@ def byte_format(bytes)
return bytes
end

def progress(completion, rate, path)
"\r#{progress_bar(completion)} #{path} - #{byte_format(rate)}B/s"
def print_progress(completion, rate, path)
if STDOUT.isatty
# Use verbose completion progress when the user is actively looking at,
# and waiting for a command to finish.
print "\r#{progress_bar(completion)} #{path} - #{byte_format(rate)}B/s"
elsif completion == 1.0
# When the user pipes results to a file, only print on completion. This
# will drastically reduce the file size.
print "#{path} - #{byte_format(rate)}B/s"
end
end

def metis_path(path)
Expand Down Expand Up @@ -980,7 +988,7 @@ EOT
io.write chunk

completed += chunk.size
print progress(
print_progress(
size == 0 ? 1 : completed / size,
(completed / (Time.now - start)).round(2),
file[:file_path]
Expand Down Expand Up @@ -1110,7 +1118,8 @@ EOT
current_byte_position: upload.current_byte_position
)

puts progress(1, 0, new_file_path)
print_progress(1, 0, new_file_path)
puts
return
end

Expand All @@ -1129,7 +1138,7 @@ EOT
current_byte_position: current_byte_position
)

print progress(
print_progress(
upload.current_byte_position.to_f / upload.file_size,
(upload.current_byte_position / (Time.now - start).to_f).round(2),
new_file_path
Expand Down Expand Up @@ -1194,7 +1203,11 @@ EOT
unless files.empty?
# compute md5sums
file_md5s = files.map.with_index do |file,i|
print "Computing md5s - #{progress_bar(i.to_f / files.length)} - #{i} of #{files.length}\r"
if STDOUT.isatty
print "Computing md5s - #{progress_bar(i.to_f / files.length)} - #{i} of #{files.length}\r"
else
puts "Computing md5s - #{progress_bar(i.to_f / files.length)} - #{i} of #{files.length}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this be spammy?

Copy link
Author

@arkal arkal Jan 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely, but like I said above, Nuke is a destructive operation so verbosity is good, no? This is just an md5 check though so it may be OK to only print completion

end
[ file, %x{ md5sum #{file} }.split(' ')[0] ]
end.to_h
puts "Computing md5s - #{progress_bar(1)} - #{files.length} of #{files.length}\n"
Expand Down Expand Up @@ -1389,6 +1402,13 @@ EOT
return
end

if Readline.get_screen_size[1] == 0
# In a non-interactive script, the screen size in [rows, characters] is [0, 0]
# This will truncate long input lines (Say the user wants to download a file 10
# folders deep) when piped to a file.
# Update columns to an arbitrarily high value.
Readline.set_screen_size(0, 1000)
end
Readline.completion_proc = proc do |string|
complete(string)
end
Expand Down Expand Up @@ -1489,6 +1509,11 @@ EOT
MetisShell.log_error(e)
exit(1) if errexit?
end
unless STDOUT.isatty
# This will sync the input command and the output result. Making
# a logfile more readable/parsable.
STDOUT.flush
end
end

VALID_INPUT=/^(?<command>\w+)(?:\s+(?<args>.*))?$/
Expand Down Expand Up @@ -1578,7 +1603,9 @@ def start
MetisSetup.new.run

MetisConfig.instance.config(config)

MetisShell.new(ARGV[0], *ARGV[1..-1]).run

puts
end

Expand Down