-
Notifications
You must be signed in to change notification settings - Fork 12
Better progress logger for stor #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jtratner
wants to merge
1
commit into
counsyl:master
Choose a base branch
from
jtratner:better-progress-bars
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,4 @@ boto3>=1.4.0 | |
| python-keystoneclient>=1.8.1 | ||
| python-swiftclient | ||
| six | ||
| tqdm | ||
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 |
|---|---|---|
|
|
@@ -14,7 +14,6 @@ | |
| from six import PY3 | ||
|
|
||
| from stor import utils | ||
| import six | ||
|
|
||
|
|
||
| class TreeWalkWarning(Warning): | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -113,63 +113,19 @@ def _get_s3_transfer(config=None): | |
|
|
||
|
|
||
| class S3DownloadLogger(utils.BaseProgressLogger): | ||
| def __init__(self, total_download_objects): | ||
| super(S3DownloadLogger, self).__init__(progress_logger) | ||
| self.total_download_objects = total_download_objects | ||
| self.downloaded_bytes = 0 | ||
|
|
||
| def update_progress(self, result): | ||
| """Tracks number of bytes downloaded.""" | ||
| self.downloaded_bytes += (os.path.getsize(result['dest']) | ||
| if not utils.has_trailing_slash(result['source']) else 0) | ||
|
|
||
| def get_start_message(self): | ||
| return 'starting download of %s objects' % self.total_download_objects | ||
|
|
||
| def get_finish_message(self): | ||
| return 'download complete - %s' % self.get_progress_message() | ||
|
|
||
| def get_progress_message(self): | ||
| elapsed_time = self.get_elapsed_time() | ||
| formatted_elapsed_time = self.format_time(elapsed_time) | ||
| mb = self.downloaded_bytes / (1024 * 1024.0) | ||
| mb_s = mb / elapsed_time.total_seconds() if elapsed_time else 0.0 | ||
| return ( | ||
| '%s/%s\t' | ||
| '%s\t' | ||
| '%0.2f MB\t' | ||
| '%0.2f MB/s' | ||
| ) % (self.num_results, self.total_download_objects, formatted_elapsed_time, mb, mb_s) | ||
| logger = progress_logger | ||
|
|
||
| def add_result(self, result): | ||
| self.update_progress(num_objects=1, addl_bytes=os.path.getszie(result['dest'])) | ||
|
Contributor
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. Is this a typo?
Contributor
Author
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. hmmm... maybe I didn't let the s3 version bubble up long enough.. |
||
|
|
||
|
|
||
| class S3UploadLogger(utils.BaseProgressLogger): | ||
| def __init__(self, total_upload_objects): | ||
| super(S3UploadLogger, self).__init__(progress_logger) | ||
| self.total_upload_objects = total_upload_objects | ||
| self.uploaded_bytes = 0 | ||
| logger = progress_logger | ||
|
|
||
| def update_progress(self, result): | ||
| def add_result(self, result): | ||
| """Keep track of total uploaded bytes by referencing the object sizes""" | ||
| self.uploaded_bytes += (os.path.getsize(result['source']) | ||
| if not utils.has_trailing_slash(result['dest']) else 0) | ||
|
|
||
| def get_start_message(self): | ||
| return 'starting upload of %s objects' % self.total_upload_objects | ||
|
|
||
| def get_finish_message(self): | ||
| return 'upload complete - %s' % self.get_progress_message() | ||
|
|
||
| def get_progress_message(self): | ||
| elapsed_time = self.get_elapsed_time() | ||
| formatted_elapsed_time = self.format_time(elapsed_time) | ||
| mb = self.uploaded_bytes / (1024 * 1024.0) | ||
| mb_s = mb / elapsed_time.total_seconds() if elapsed_time else 0.0 | ||
| return ( | ||
| '%s/%s\t' | ||
| '%s\t' | ||
| '%0.2f MB\t' | ||
| '%0.2f MB/s' | ||
| ) % (self.num_results, self.total_upload_objects, formatted_elapsed_time, mb, mb_s) | ||
| self.update_progress(1, (os.path.getsize(result['source']) | ||
| if not utils.has_trailing_slash(result['dest']) else 0)) | ||
|
|
||
|
|
||
| class S3Path(OBSPath): | ||
|
|
@@ -627,7 +583,16 @@ def download(self, dest, condition=None, use_manifest=False, **kwargs): | |
| return downloaded | ||
|
|
||
| def _upload_object(self, upload_obj, config=None): | ||
| """Upload a single object given an OBSUploadObject.""" | ||
| """Upload a single object given an OBSUploadObject. | ||
|
|
||
| Returns: | ||
| dict: source, dest (str), success (bool), and optionally an error key""" | ||
| result = { | ||
| 'source': upload_obj.source, | ||
| 'dest': str(upload_obj.object_name), | ||
| 'success': True | ||
| } | ||
|
|
||
| if utils.has_trailing_slash(upload_obj.object_name): | ||
| # Handle empty directories separately | ||
| ul_kwargs = { | ||
|
|
||
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
Oops, something went wrong.
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.
AFAIK this import is unused