-
Notifications
You must be signed in to change notification settings - Fork 199
Allow specifying destination directory and filename in get() #158
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
Closed
lordcirth
wants to merge
6
commits into
ipfs-shipyard:py-ipfs-http-client
from
lordcirth:http-get-filename
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9633653
add filepath arg to get()
lordcirth bcb4c3e
Don't use a list as a default argument
lordcirth 298131a
add 'filename' arg to get()
lordcirth c8e25fd
docstrings for get() changes
lordcirth dfceeb3
add test for get() with filepath
lordcirth 59ac2c4
add test for get() with filename
lordcirth 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 |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
import functools | ||
import re | ||
import tarfile | ||
import shutil | ||
from six.moves import http_client | ||
|
||
import requests | ||
|
@@ -247,7 +248,7 @@ def request(self, path, | |
files, headers, data) | ||
|
||
@pass_defaults | ||
def download(self, path, args=[], filepath=None, opts={}, | ||
def download(self, path, args=None, filepath=None, filename=None, opts={}, | ||
compress=True, **kwargs): | ||
"""Makes a request to the IPFS daemon to download a file. | ||
|
||
|
@@ -267,9 +268,12 @@ def download(self, path, args=[], filepath=None, opts={}, | |
path : str | ||
The REST command path to send | ||
filepath : str | ||
The local path where IPFS will store downloaded files | ||
The local directory where IPFS will store downloaded files | ||
|
||
Defaults to the current working directory. | ||
If the directory does not exist, it will be created. | ||
filename : str | ||
The filename to store the file as. | ||
args : list | ||
Positional parameters to be sent along with the HTTP request | ||
opts : dict | ||
|
@@ -280,6 +284,8 @@ def download(self, path, args=[], filepath=None, opts={}, | |
kwargs : dict | ||
Additional arguments to pass to :mod:`requests` | ||
""" | ||
if not args: | ||
args = [] | ||
url = self.base + path | ||
wd = filepath or '.' | ||
|
||
|
@@ -307,6 +313,11 @@ def download(self, path, args=[], filepath=None, opts={}, | |
with tarfile.open(fileobj=res.raw, mode=mode) as tf: | ||
tf.extractall(path=wd) | ||
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. Please iterate over the fsnodes of the received tar file using |
||
|
||
if type(filename) is str: | ||
# Assume that arg 0 is multihash. Not great. | ||
old_name = args[0] | ||
shutil.move((wd + '/' + old_name), (wd + '/' + filename)) | ||
|
||
@contextlib.contextmanager | ||
def session(self): | ||
"""A context manager for this client's session. | ||
|
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.
Why do we need two parameters here? Why not just have a path relative to the current working directory whose basename will be the filename of the object to download (meaning that the file at the path will be either a file or a directory depending on its actual type)?