-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Create `curl_plugin_shared.download_file` to get rid of some duplication between curl fetch and reup. Add progress printing to this function, so that curl now plays nicely with the fancy terminal. Test Plan: New tests included for the shared logic. Reviewers: sean Differential Revision: https://phabricator.buildinspace.com/D95
- Loading branch information
1 parent
09bb6ab
commit f294542
Showing
5 changed files
with
101 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,24 @@ | ||
#! /usr/bin/env python3 | ||
|
||
import hashlib | ||
import os | ||
import sys | ||
import urllib.request | ||
|
||
from curl_plugin_shared import get_request_filename | ||
import curl_plugin_shared | ||
|
||
|
||
url = os.environ['PERU_MODULE_URL'] | ||
sha1 = os.environ['PERU_MODULE_SHA1'] | ||
filename = os.environ['PERU_MODULE_FILENAME'] | ||
|
||
digest = hashlib.sha1() | ||
with urllib.request.urlopen(url) as request: | ||
if not filename: | ||
filename = get_request_filename(request) | ||
filename = curl_plugin_shared.get_request_filename(request) | ||
full_filepath = os.path.join(os.environ['PERU_FETCH_DEST'], filename) | ||
with open(full_filepath, 'wb') as outfile: | ||
while True: | ||
buf = request.read(4096) | ||
if not buf: | ||
break | ||
outfile.write(buf) | ||
digest.update(buf) | ||
with open(full_filepath, 'wb') as output_file: | ||
digest = curl_plugin_shared.download_file(request, output_file) | ||
|
||
if sha1 and digest.hexdigest() != sha1: | ||
if sha1 and digest != sha1: | ||
print('Bad checksum!\n url: {}\nexpected: {}\n actual: {}' | ||
.format(url, sha1, digest.hexdigest()), file=sys.stderr) | ||
.format(url, sha1, digest), file=sys.stderr) | ||
sys.exit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,17 @@ | ||
#! /usr/bin/env python3 | ||
|
||
import hashlib | ||
import os | ||
import urllib.request | ||
|
||
import curl_plugin_shared | ||
|
||
reup_output = os.environ['PERU_REUP_OUTPUT'] | ||
|
||
url = os.environ['PERU_MODULE_URL'] | ||
sha1 = os.environ['PERU_MODULE_SHA1'] | ||
|
||
digest = hashlib.sha1() | ||
with urllib.request.urlopen(url) as request: | ||
while True: | ||
buf = request.read(4096) | ||
if not buf: | ||
break | ||
digest.update(buf) | ||
digest = curl_plugin_shared.download_file(request, None) | ||
|
||
with open(reup_output, 'w') as output_file: | ||
print('sha1:', digest.hexdigest(), file=output_file) | ||
print('sha1:', digest, file=output_file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters