diff options
author | Milan Verespej <m.verespej@partner.samsung.com> | 2019-05-07 14:50:20 +0200 |
---|---|---|
committer | Milan Verespej <m.verespej@partner.samsung.com> | 2019-05-24 11:28:25 +0200 |
commit | 9dfa7642e60a37d9822276441e1700173428e30d (patch) | |
tree | 3d4605b704be560b527cd8700e3ced86db544748 /build/download/base.py | |
parent | e0227c21f903bffe4a2a872d05102eca3770b483 (diff) |
Improve download of http files
Issue-ID: OOM-1803
Change-Id: If2aeb1aa4fab27641511a6300832ccd7be95e846
Signed-off-by: Milan Verespej <m.verespej@partner.samsung.com>
Diffstat (limited to 'build/download/base.py')
-rw-r--r-- | build/download/base.py | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/build/download/base.py b/build/download/base.py index e3081638..5bcd0ef6 100644 --- a/build/download/base.py +++ b/build/download/base.py @@ -20,8 +20,11 @@ # COPYRIGHT NOTICE ENDS HERE -import progressbar import concurrent.futures +import os +import progressbar +import prettytable +import requests from distutils.spawn import find_executable progressbar.streams.wrap_stdout() @@ -84,3 +87,28 @@ def finish_progress(progress, error_count, log): def check_tool(name): return find_executable(name) + +def save_to_file(dst, content): + """ + Save downloaded byte content to file + :param dst: path to file to save content to + :param content: byte content of file + """ + dst_dir = os.path.dirname(dst) + if not os.path.exists(dst_dir): + os.makedirs(dst_dir) + with open(dst, 'wb') as dst_file: + dst_file.write(content) + +def make_get_request(url): + req = requests.get(url) + req.raise_for_status() + return req + +def simple_check_table(target, missing): + table = prettytable.PrettyTable(['Name', 'Downloaded']) + table.align['Name'] = 'l' + for item in sorted(target): + table.add_row([item, item not in missing]) + return table + |