Browse Source

Reduce number of "download progress" messages. (#1482)

pull/1484/head
josetr 5 years ago committed by GitHub
parent
commit
73f334c90e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      build/scripts/Utils.lua

20
build/scripts/Utils.lua

@ -81,17 +81,25 @@ function git.rev_parse(dir, rev)
return outputof(cmd) return outputof(cmd)
end end
function http.progress (total, curr) function percentage(total, curr)
local ratio = curr / total; return math.floor(math.min(math.max(curr / total, 0), 1) * 100)
ratio = math.min(math.max(ratio, 0), 1); end
local percent = math.floor(ratio * 100); function http.progress (total, prev, curr)
io.write("Download progress (" .. percent .. "%/100%)\r") local prevPercent = percentage(total, prev)
local percent = percentage(total, curr)
if percent % 5 == 0 and prevPercent ~= percent then
io.write("Download progress (" .. percent .. "%/100%)\r")
end
end end
function download(url, file) function download(url, file)
print("Downloading: " .. url) print("Downloading: " .. url)
local res = http.download(url, file, http.progress) local prev = 0
local res = http.download(url, file, function(total, curr)
http.progress(total, prev, curr)
prev = curr
end)
if res ~= "OK" then if res ~= "OK" then
os.remove(file) os.remove(file)

Loading…
Cancel
Save