From c51e49061ae9a25c8957f84260b73aef89ec3da0 Mon Sep 17 00:00:00 2001 From: z4yx Date: Mon, 27 Apr 2020 18:01:45 +0800 Subject: [PATCH] calc the size of github-release --- github-release.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/github-release.py b/github-release.py index 35e960f..8222f21 100755 --- a/github-release.py +++ b/github-release.py @@ -38,6 +38,12 @@ REPOS = [ # connect and read timeout value TIMEOUT_OPTION = (7, 10) +def sizeof_fmt(num, suffix='iB'): + for unit in ['','K','M','G','T','P','E','Z']: + if abs(num) < 1024.0: + return "%3.2f%s%s" % (num, unit, suffix) + num /= 1024.0 + return "%.2f%s%s" % (num, 'Y', suffix) # wrap around requests.get to use token if available def github_get(*args, **kwargs): @@ -117,6 +123,7 @@ def main(): task_queue = create_workers(args.workers) remote_filelist = [] cleaning = False + total_size = 0 def download(release, release_dir, tarball = False): @@ -139,6 +146,7 @@ def main(): asset['updated_at'], '%Y-%m-%dT%H:%M:%SZ').timestamp() dst_file = release_dir / ensure_safe_name(asset['name']) remote_filelist.append(dst_file.relative_to(working_dir)) + total_size += asset['size'] if dst_file.is_file(): if args.fast_skip: @@ -245,6 +253,8 @@ def main(): except: pass + print("Total size is", sizeof_fmt(total_size, suffix="")) + if __name__ == "__main__": main()