From 1d3da0ea67104f0992705b9ff838fd2e3c1997b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?UTF-8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F?= Date: Wed, 23 Jan 2019 00:00:02 +0000 Subject: [PATCH] shell_helpers: wget for release-download-latest --- release-download-latest | 7 +------ shell_helpers.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/release-download-latest b/release-download-latest index f06a94f..81fa163 100755 --- a/release-download-latest +++ b/release-download-latest @@ -1,7 +1,5 @@ #!/usr/bin/env python3 -import urllib.request - import common from shell_helpers import LF @@ -17,12 +15,9 @@ https://stackoverflow.com/questions/24987542/is-there-a-link-to-github-for-downl ) def timed_main(self): - # This would be better, but impossible: - # https://stackoverflow.com/questions/51212/how-to-write-a-download-progress-indicator-in-python - self.log_info('Downloading the release, this may take several seconds / a few minutes.') _json = self.github_make_request(path='/releases') asset = _json[0]['assets'][0] - urllib.request.urlretrieve(asset['browser_download_url'], asset['name']) + self.sh.wget(asset['browser_download_url'], asset['name']) if __name__ == '__main__': Main().cli() diff --git a/shell_helpers.py b/shell_helpers.py index 709441c..a60d495 100644 --- a/shell_helpers.py +++ b/shell_helpers.py @@ -10,6 +10,7 @@ import stat import subprocess import sys import threading +import urllib.request class LF: ''' @@ -269,6 +270,20 @@ class ShellHelpers: else: os.unlink(path) + def wget(self, url, download_path): + ''' + Append extra KEY=val configs into the given config file. + + I wissh we could have a progress indicator, but impossible: + https://stackoverflow.com/questions/51212/how-to-write-a-download-progress-indicator-in-python + ''' + self.print_cmd([ + 'wget', LF, + '-O', download_path, LF, + url, LF, + ]) + urllib.request.urlretrieve(url, download_path) + def write_configs(self, config_path, configs, config_fragments=None, mode='a'): ''' Append extra KEY=val configs into the given config file.