This repository was archived by the owner on Jun 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 114
Add --print-progress flag to show puller progress #66
Open
scele
wants to merge
1
commit into
google:master
Choose a base branch
from
scele:verbose_print
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
import io | ||
import json | ||
import os | ||
import sys | ||
import tarfile | ||
|
||
import concurrent.futures | ||
|
@@ -144,7 +145,8 @@ def tarball(name, image, | |
def fast(image, | ||
directory, | ||
threads = 1, | ||
cache_directory = None): | ||
cache_directory = None, | ||
print_progress = False): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. update Args section below. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
"""Produce a FromDisk compatible file layout under the provided directory. | ||
|
||
After calling this, the following filesystem will exist: | ||
|
@@ -166,6 +168,7 @@ def fast(image, | |
directory: an existing empty directory under which to save the layout. | ||
threads: the number of threads to use when performing the upload. | ||
cache_directory: directory that stores file cache. | ||
print_progress: whether to print pull status messages to stderr. | ||
|
||
Returns: | ||
A tuple whose first element is the path to the config file, and whose second | ||
|
@@ -174,13 +177,15 @@ def fast(image, | |
""" | ||
|
||
def write_file(name, accessor, | ||
arg): | ||
arg, message = None): | ||
if print_progress and message is not None: | ||
sys.stderr.write(message + "\n") | ||
with io.open(name, u'wb') as f: | ||
f.write(accessor(arg)) | ||
|
||
def write_file_and_store(name, accessor, | ||
arg, cached_layer): | ||
write_file(cached_layer, accessor, arg) | ||
arg, cached_layer, message = None): | ||
write_file(cached_layer, accessor, arg, message) | ||
link(cached_layer, name) | ||
|
||
def link(source, dest): | ||
|
@@ -225,11 +230,13 @@ def valid(cached_layer, digest): | |
'unused') | ||
|
||
idx = 0 | ||
num_layers = len(image.fs_layers()) | ||
layers = [] | ||
for blob in reversed(image.fs_layers()): | ||
# Create a local copy | ||
layer_name = os.path.join(directory, '%03d.tar.gz' % idx) | ||
digest_name = os.path.join(directory, '%03d.sha256' % idx) | ||
message = 'Downloading from {} (layer {}/{})'.format(image.name(), idx+1, num_layers) | ||
# Strip the sha256: prefix | ||
digest = blob[7:].encode('utf8') | ||
f = executor.submit( | ||
|
@@ -247,10 +254,10 @@ def valid(cached_layer, digest): | |
future_to_params[f] = layer_name | ||
else: | ||
f = executor.submit(write_file_and_store, layer_name, image.blob, | ||
blob, cached_layer) | ||
blob, cached_layer, message) | ||
future_to_params[f] = layer_name | ||
else: | ||
f = executor.submit(write_file, layer_name, image.blob, blob) | ||
f = executor.submit(write_file, layer_name, image.blob, blob, message) | ||
future_to_params[f] = layer_name | ||
|
||
layers.append((digest_name, layer_name)) | ||
|
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use logging instead, you can check fast_flatten or fast_pusher for reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my commit message for explanation why I don't want to use
logging
.Also, I would like the print to go to stderr, not stdout, because other bazel build status messages also go to stderr:
I think the pull status progresses should appear together with these messages in stderr like so:
If the output goes to stdout, then these status messages would clutter run_log.txt in the following invocation: