Skip to content

Commit

Permalink
Allow checkurl() to return True in case file is present but neither s…
Browse files Browse the repository at this point in the history
…ize nor filename are known

From https://git-annex.branchable.com/design/external_special_remote_protocol/
The Size is the size in bytes, or use UNKNOWN if the size could not be determined.
The Filename can be empty (in which case a default is used), or can specify a filename that is suggested to be used for this url.
  • Loading branch information
Lykos153 committed Apr 2, 2020
1 parent 05b5908 commit 78a79cf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
11 changes: 3 additions & 8 deletions annexremote/annexremote.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,18 +275,13 @@ def checkurl(self, url):
False if it can't currently be downloaded.
In order to provide additional information, a list of dictionaries can be returned.
The dictionaries can have 3 keys: {'url': str, 'size': int, 'filename': str}
The dictionaries can have 3 keys: {'url': str, 'size': int, 'filename': str}. All of them are optional.
If there is only one file to be downloaded, we could return:
[{'size': 512, 'filename':'example_file.txt'}]
Both `size` and `filename` can be ommited.
If there are multiple files to be downloaded from this url
The dictionaries are of the form:
Other examples:
{'url':"https://example.com", 'size':512, 'filename':"example_file.txt"}
[{'url':"Url1", 'size':512, 'filename':"Filename1"}, {'url':"Url2", 'filename':"Filename2"}]
Expand Down
13 changes: 6 additions & 7 deletions docs/annexremote/annexremote.html
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,12 @@ <h2 id="returns">Returns</h2>
<p>True if the url's content can currently be downloaded and no additional information can be provided.
False if it can't currently be downloaded.</p>
<p>In order to provide additional information, a list of dictionaries can be returned.
The dictionaries can have 3 keys: {'url': str, 'size': int, 'filename': str}
If there is only one file to be downloaded, we could return:
[{'size': 512, 'filename':'example_file.txt'}]
Both <code>size</code> and <code>filename</code> can be ommited.</p>
<p>If there are multiple files to be downloaded from this url</p>
<p _filename_:_example_file.txt_="'filename':&quot;example_file.txt&quot;" _size_:512_="'size':512," _url_:_https:_example.com_="'url':&quot;https://example.com&quot;,">The dictionaries are of the form:</p>
<p>[{'url':"Url1", 'size':512, 'filename':"Filename1"}, {'url':"Url2", 'filename':"Filename2"}]</p>
The dictionaries can have 3 keys: {'url': str, 'size': int, 'filename': str}. All of them are optional.</p>
<p>If there is only one file to be downloaded, we could return:
[{'size': 512, 'filename':'example_file.txt'}]</p>
<p>Other examples:
{'url':"https://example.com", 'size':512, 'filename':"example_file.txt"}
[{'url':"Url1", 'size':512, 'filename':"Filename1"}, {'url':"Url2", 'filename':"Filename2"}]</p>
</dd>
</dl></section>
</dd>
Expand Down
6 changes: 6 additions & 0 deletions tests/test_GitAnnexRequestMessages.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ def TestClaimurlFailure(self):
self.annex.Listen(io.StringIO("CLAIMURL Url"))
self.assertEqual(utils.second_buffer_line(self.output), "CLAIMURL-FAILURE")

def TestCheckurlContentsTrue(self):
self.remote.checkurl.return_value = True
self.annex.Listen(io.StringIO("CHECKURL Url"))
self.remote.checkurl.assert_called_once_with("Url")
self.assertEqual(utils.second_buffer_line(self.output), "CHECKURL-CONTENTS UNKNOWN")

def TestCheckurlContents(self):
self.remote.checkurl.return_value = [{'size':512,'filename':"Filename"}]
self.annex.Listen(io.StringIO("CHECKURL Url"))
Expand Down

0 comments on commit 78a79cf

Please sign in to comment.