This repository was archived by the owner on Jan 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 360
Support pull directories #8
Open
tgalal
wants to merge
2
commits into
google:master
Choose a base branch
from
tgalal:recursive_pull
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 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |
| import cStringIO | ||
| import os | ||
| import socket | ||
| import stat | ||
|
|
||
| from M2Crypto import RSA | ||
|
|
||
|
|
@@ -171,19 +172,41 @@ def Pull(self, device_filename, dest_file=None, timeout_ms=None): | |
| Returns: | ||
| The file data if dest_file is not set. | ||
| """ | ||
| if isinstance(dest_file, basestring): | ||
| dest_file = open(dest_file, 'w') | ||
| elif not dest_file: | ||
| dest_file = cStringIO.StringIO() | ||
| connection = self.protocol_handler.Open( | ||
| self.handle, destination='sync:', | ||
| timeout_ms=timeout_ms) | ||
| self.filesync_handler.Pull(connection, device_filename, dest_file) | ||
| connection.Close() | ||
| # An empty call to cStringIO.StringIO returns an instance of | ||
| # cStringIO.OutputType. | ||
| if isinstance(dest_file, cStringIO.OutputType): | ||
| return dest_file.getvalue() | ||
|
|
||
| if dest_file: | ||
| print("pull: %s -> %s" % (device_filename, dest_file)) | ||
|
|
||
| filemode, _, _= self.Stat(device_filename) | ||
|
|
||
| if stat.S_ISDIR(filemode): | ||
| assert dest_file, "Must specify out dir when pulling a directory" | ||
| file_list = self.List(device_filename) | ||
| if not os.path.exists(dest_file): | ||
| os.makedirs(dest_file) | ||
|
|
||
| for device_file in file_list: | ||
| if device_file.filename not in (".", ".."): | ||
| self.Pull( | ||
| os.path.join(device_filename, device_file.filename), | ||
| os.path.join(dest_file, device_file.filename) if dest_file else None | ||
|
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. dest_file can't be None, so are you expecting it to be an empty string? If so, os.path.join('', filename) == filename, so it shouldn't matter. The only other case is if dest_file is False or something falsey but not a string, which should be caught in the check above (by it failing or os.path.exists failing) 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. So from where I'm sitting, this really only means that the conditional at L189 should be removed. Is that correct? |
||
| ) | ||
|
|
||
| else: | ||
| if stat.S_ISLNK(filemode) or stat.S_ISSOCK(filemode): | ||
| return | ||
| if isinstance(dest_file, basestring): | ||
| dest_file = open(dest_file, 'w') | ||
| elif not dest_file: | ||
| dest_file = cStringIO.StringIO() | ||
| connection = self.protocol_handler.Open( | ||
| self.handle, destination='sync:', | ||
| timeout_ms=timeout_ms) | ||
| self.filesync_handler.Pull(connection, device_filename, dest_file) | ||
| connection.Close() | ||
| # An empty call to cStringIO.StringIO returns an instance of | ||
| # cStringIO.OutputType. | ||
| if isinstance(dest_file, cStringIO.OutputType): | ||
| return dest_file.getvalue() | ||
|
|
||
| def Stat(self, device_filename): | ||
| """Get a file's stat() information.""" | ||
|
|
||
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.
No printing, please. Also, instead of an assert on 182, raise a custom error or something like ValueError that can be caught more specifically than the generic AssertionError.