forked from lvanhaaren/DataladExtensionCDS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
339 additions
and
257 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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 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 |
---|---|---|
@@ -1,6 +1,10 @@ | ||
name: docs | ||
|
||
on: [push, pull_request] | ||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
|
||
jobs: | ||
build: | ||
|
This file contains 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 |
---|---|---|
@@ -1,13 +1,14 @@ | ||
.pybuild/ | ||
.coverage | ||
/.tox | ||
*.egg-info | ||
*.grib | ||
*.py[coe] | ||
.#* | ||
.*.swp | ||
pip-wheel-metadata | ||
docs/build | ||
docs/source/generated | ||
.coverage | ||
.hypothesis | ||
.pybuild/ | ||
/.tox | ||
build/ | ||
dist/ | ||
*.grib | ||
docs/build | ||
docs/source/generated | ||
pip-wheel-metadata |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Command line reference | ||
====================== | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
|
||
generated/man/datalad-download-cds |
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
High-level API commands | ||
======================= | ||
|
||
.. currentmodule:: datalad.api | ||
.. autosummary:: | ||
:toctree: generated | ||
|
||
download_cds |
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import inspect | ||
import logging | ||
|
||
import cdsapi | ||
from annexremote import Master, RemoteError, SpecialRemote | ||
|
||
import datalad_cds.spec | ||
|
||
logger = logging.getLogger("datalad.cds.cds_remote") | ||
|
||
CDS_REMOTE_UUID = "923e2755-e747-42f4-890a-9c921068fb82" | ||
|
||
|
||
class HandleUrlError(Exception): | ||
pass | ||
|
||
|
||
class CDSRemote(SpecialRemote): | ||
transfer_store = None | ||
remove = None | ||
|
||
def initremote(self) -> None: | ||
pass | ||
|
||
def prepare(self) -> None: | ||
pass | ||
|
||
def _retrieve_cds(self, spec: datalad_cds.spec.Spec, filename: str) -> None: | ||
logger.debug( | ||
"%s called with spec %s and filename %s", | ||
inspect.stack()[0][3], | ||
spec, | ||
filename, | ||
) | ||
c = cdsapi.Client() | ||
c.retrieve(spec.name, spec.request, filename) | ||
|
||
def transfer_retrieve(self, key: str, filename: str) -> None: | ||
logger.debug( | ||
"%s called with key %s and filename %s", | ||
inspect.stack()[0][3], | ||
key, | ||
filename, | ||
) | ||
urls = self.annex.geturls(key, "datalad-cds:") | ||
logger.debug("urls for this key: %s", urls) | ||
for url in urls: | ||
try: | ||
self._retrieve_cds(datalad_cds.spec.Spec.from_url(url), filename) | ||
break | ||
except: # noqa: E722 | ||
pass | ||
else: | ||
raise RemoteError("Failed to handle key {}".format(key)) | ||
|
||
def checkpresent(self, key: str) -> bool: | ||
# We just assume that we can always handle the key | ||
return True | ||
|
||
def claimurl(self, url: str) -> bool: | ||
return url.startswith("datalad-cds:") | ||
|
||
def checkurl(self, url: str) -> bool: | ||
return url.startswith("datalad-cds:") | ||
|
||
|
||
def main() -> None: | ||
master = Master() | ||
remote = CDSRemote(master) | ||
master.LinkRemote(remote) | ||
logger.addHandler(master.LoggingHandler()) | ||
master.Listen() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import sys | ||
|
||
|
||
def removeprefix(s: str, prefix: str) -> str: | ||
if sys.version_info >= (3, 9): # pragma: py-lt-39 | ||
return s.removeprefix(prefix) | ||
else: # pragma: py-gte-39 | ||
if s.startswith(prefix): | ||
return s[len(prefix) :] | ||
return s |
Oops, something went wrong.