diff --git a/README.md b/README.md index 26c2fda2..ebda3baf 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ Usage: cirro download [OPTIONS] Options: --project TEXT Name or ID of the project --dataset TEXT ID of the dataset + --file... TEXT Name and relative path of the file (optional) --data-directory TEXT Directory to store the files -i, --interactive Gather arguments interactively --help Show this message and exit. @@ -91,7 +92,7 @@ $ cirro upload --interactive See the following set of Jupyter notebooks that contain examples on the following topics: | Jupyter Notebook | Topic | -|--------------------------------------------------------------------|--------------------------------------| +| ------------------------------------------------------------------ | ------------------------------------ | | [Introduction](samples/Getting_started.ipynb) | Installing and authenticating | | [Uploading a dataset](samples/Uploading_a_dataset.ipynb) | Uploading data | | [Downloading a dataset](samples/Downloading_a_dataset.ipynb) | Downloading data | @@ -103,7 +104,7 @@ See the following set of Jupyter notebooks that contain examples on the followin ## R Usage | Jupyter Notebook | Topic | -|-----------------------------------------------------|---------------------| +| --------------------------------------------------- | ------------------- | | [Downloading a dataset in R](samples/Using-R.ipynb) | Reading data with R | ## Advanced Usage @@ -113,7 +114,7 @@ View the API documentation for this library [here](https://cirrobio.github.io/Ci ### Supported environment variables | Name | Description | Default | -|----------------|-------------------------------|----------| +| -------------- | ----------------------------- | -------- | | CIRRO_HOME | Local configuration directory | ~/.cirro | | CIRRO_BASE_URL | Base URL of the data portal | | diff --git a/cirro/cli/cli.py b/cirro/cli/cli.py index db1ea475..5c719db7 100644 --- a/cirro/cli/cli.py +++ b/cirro/cli/cli.py @@ -36,6 +36,10 @@ def list_datasets(**kwargs): help='Name or ID of the project') @click.option('--dataset', help='ID of the dataset') +@click.option('--file', + help='Name and relative path of the file (optional)', + default=[], + multiple=True) @click.option('--data-directory', help='Directory to store the files') @click.option('-i', '--interactive', diff --git a/cirro/cli/controller.py b/cirro/cli/controller.py index cf8be4ba..f6efbd0b 100644 --- a/cirro/cli/controller.py +++ b/cirro/cli/controller.py @@ -1,4 +1,5 @@ import logging +import os import sys import pandas as pd @@ -142,6 +143,19 @@ def run_download(input_params: DownloadArguments, interactive=False): datasets = cirro.datasets.list(project_id) dataset_id = get_id_from_name(datasets, input_params['dataset']) + if input_params['file']: + all_files = cirro.datasets.get_file_listing(project_id, dataset_id) + files_to_download = [] + + for filepath in input_params['file']: + if not filepath.startswith('data/'): + filepath = os.path.join('data/', filepath) + file = next((f for f in all_files if f.relative_path == filepath), None) + if not file: + logger.warning(f"Could not find file {filepath}. Skipping.") + continue + files_to_download.append(file) + logger.info("Downloading files") if cirro.configuration.enable_additional_checksum: checksum_method = "SHA256" diff --git a/pyproject.toml b/pyproject.toml index 5124f06f..29c18137 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "cirro" -version = "1.2.8" +version = "1.2.9" description = "CLI tool and SDK for interacting with the Cirro platform" authors = ["Cirro Bio "] license = "MIT"