Skip to content

Commit

Permalink
fixup! Add functionality for setting custom names
Browse files Browse the repository at this point in the history
  • Loading branch information
marcellevstek committed Oct 14, 2024
1 parent 85fd813 commit 8c27660
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
8 changes: 2 additions & 6 deletions src/resdk/resolwe.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,20 +466,16 @@ def _download_files(
files: List[Union[str, Path]],
download_dir=None,
show_progress=True,
custom_file_names: Union[List[str], None] = None,
custom_file_names: Optional[List[str]] = None,
):
"""Download files.
Download files from the Resolwe server to the download
directory (defaults to the current working directory).
:param files: files to download
:type files: list of file URI
:param download_dir: download directory
:type download_dir: string
:param custom_file_names: list of file names to save the downloaded files as
:type custom_file_names: list of strings or None
:rtype: None
"""
if not download_dir:
Expand Down Expand Up @@ -565,7 +561,7 @@ def _download_files(
)
if expected_md5 != computed_md5:
raise ValueError(
f"Checksum of downloaded file {actual_file_name} does not match the expected value."
f"Checksum ({computed_md5}) of downloaded file {actual_file_name} does not match the expected value of {expected_md5}."
)

def data_usage(self, **query_params):
Expand Down
19 changes: 8 additions & 11 deletions src/resdk/resources/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,30 +325,27 @@ def files(self, file_name=None, field_name=None):
return file_list

def download(
self, file_name=None, field_name=None, download_dir=None, custom_file_name=None
self,
file_name: Optional[str] = None,
field_name: Optional[str] = None,
download_dir: Optional[str] = None,
custom_file_name: Optional[str] = None,
):
"""Download Data object's files and directories.
Download files and directories from the Resolwe server to the
download directory (defaults to the current working directory).
:param file_name: name of file or directory
:type file_name: string
:param field_name: file or directory field name
:type field_name: string
:param download_dir: download path
:type download_dir: string
:param custom_file_name: custom file name
:type custom_file_name: string
:rtype: None
Data objects can contain multiple files and directories. All are
downloaded by default, but may be filtered by name or output
field:
* re.data.get(42).download(file_name='alignment7.bam')
* re.data.get(42).download(field_name='bam')
If custom_file_name is provided, the file will be saved with that name,
provided that either field_name or file_name is also specified.
"""
if file_name and field_name:
raise ValueError("Only one of file_name or field_name may be given.")
Expand Down

0 comments on commit 8c27660

Please sign in to comment.