shell_helpers: wget for release-download-latest

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-01-23 00:00:02 +00:00
parent de18cdb687
commit 1d3da0ea67
2 changed files with 16 additions and 6 deletions

View File

@@ -1,7 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import urllib.request
import common import common
from shell_helpers import LF 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): 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') _json = self.github_make_request(path='/releases')
asset = _json[0]['assets'][0] 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__': if __name__ == '__main__':
Main().cli() Main().cli()

View File

@@ -10,6 +10,7 @@ import stat
import subprocess import subprocess
import sys import sys
import threading import threading
import urllib.request
class LF: class LF:
''' '''
@@ -269,6 +270,20 @@ class ShellHelpers:
else: else:
os.unlink(path) 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'): def write_configs(self, config_path, configs, config_fragments=None, mode='a'):
''' '''
Append extra KEY=val configs into the given config file. Append extra KEY=val configs into the given config file.