das-cli 1.1.0__tar.gz → 1.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. {das_cli-1.1.0/das_cli.egg-info → das_cli-1.2.0}/PKG-INFO +1 -1
  2. {das_cli-1.1.0 → das_cli-1.2.0}/das/cli.py +32 -0
  3. {das_cli-1.1.0 → das_cli-1.2.0}/das/common/api.py +20 -0
  4. {das_cli-1.1.0 → das_cli-1.2.0}/das/managers/download_manager.py +43 -1
  5. {das_cli-1.1.0 → das_cli-1.2.0}/das/services/downloads.py +19 -2
  6. {das_cli-1.1.0 → das_cli-1.2.0/das_cli.egg-info}/PKG-INFO +1 -1
  7. {das_cli-1.1.0 → das_cli-1.2.0}/pyproject.toml +1 -1
  8. {das_cli-1.1.0 → das_cli-1.2.0}/LICENSE +0 -0
  9. {das_cli-1.1.0 → das_cli-1.2.0}/MANIFEST.in +0 -0
  10. {das_cli-1.1.0 → das_cli-1.2.0}/README.md +0 -0
  11. {das_cli-1.1.0 → das_cli-1.2.0}/das/__init__.py +0 -0
  12. {das_cli-1.1.0 → das_cli-1.2.0}/das/ai/plugins/dasai.py +0 -0
  13. {das_cli-1.1.0 → das_cli-1.2.0}/das/ai/plugins/entries/entries_plugin.py +0 -0
  14. {das_cli-1.1.0 → das_cli-1.2.0}/das/app.py +0 -0
  15. {das_cli-1.1.0 → das_cli-1.2.0}/das/authentication/auth.py +0 -0
  16. {das_cli-1.1.0 → das_cli-1.2.0}/das/authentication/secure_input.py +0 -0
  17. {das_cli-1.1.0 → das_cli-1.2.0}/das/common/config.py +0 -0
  18. {das_cli-1.1.0 → das_cli-1.2.0}/das/common/entry_fields_constants.py +0 -0
  19. {das_cli-1.1.0 → das_cli-1.2.0}/das/common/enums.py +0 -0
  20. {das_cli-1.1.0 → das_cli-1.2.0}/das/common/file_utils.py +0 -0
  21. {das_cli-1.1.0 → das_cli-1.2.0}/das/managers/__init__.py +0 -0
  22. {das_cli-1.1.0 → das_cli-1.2.0}/das/managers/digital_objects_manager.py +0 -0
  23. {das_cli-1.1.0 → das_cli-1.2.0}/das/managers/entries_manager.py +0 -0
  24. {das_cli-1.1.0 → das_cli-1.2.0}/das/managers/search_manager.py +0 -0
  25. {das_cli-1.1.0 → das_cli-1.2.0}/das/services/attributes.py +0 -0
  26. {das_cli-1.1.0 → das_cli-1.2.0}/das/services/cache.py +0 -0
  27. {das_cli-1.1.0 → das_cli-1.2.0}/das/services/digital_objects.py +0 -0
  28. {das_cli-1.1.0 → das_cli-1.2.0}/das/services/entries.py +0 -0
  29. {das_cli-1.1.0 → das_cli-1.2.0}/das/services/entry_fields.py +0 -0
  30. {das_cli-1.1.0 → das_cli-1.2.0}/das/services/hangfire.py +0 -0
  31. {das_cli-1.1.0 → das_cli-1.2.0}/das/services/search.py +0 -0
  32. {das_cli-1.1.0 → das_cli-1.2.0}/das/services/users.py +0 -0
  33. {das_cli-1.1.0 → das_cli-1.2.0}/das_cli.egg-info/SOURCES.txt +0 -0
  34. {das_cli-1.1.0 → das_cli-1.2.0}/das_cli.egg-info/dependency_links.txt +0 -0
  35. {das_cli-1.1.0 → das_cli-1.2.0}/das_cli.egg-info/entry_points.txt +0 -0
  36. {das_cli-1.1.0 → das_cli-1.2.0}/das_cli.egg-info/requires.txt +0 -0
  37. {das_cli-1.1.0 → das_cli-1.2.0}/das_cli.egg-info/top_level.txt +0 -0
  38. {das_cli-1.1.0 → das_cli-1.2.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: das-cli
3
- Version: 1.1.0
3
+ Version: 1.2.0
4
4
  Summary: DAS api client.
5
5
  Author: Royal Netherlands Institute for Sea Research
6
6
  License-Expression: MIT
@@ -992,6 +992,38 @@ def create_download_request(das_ctx, name, entry, file, from_file, output_format
992
992
  except Exception as e:
993
993
  click.secho(f"Error: {e}", fg="red")
994
994
 
995
+ @download.command("files")
996
+ @click.argument('request_id', required=True)
997
+ @click.option('--out', 'output_path', required=False, default='.', help='Output file path or directory (defaults to current directory)')
998
+ @click.option('--force', is_flag=True, help='Overwrite existing file if present')
999
+ @pass_das_context
1000
+ def download_files(das_ctx, request_id, output_path, force):
1001
+ """
1002
+ Download the completed bundle for a download request and save it to disk.
1003
+
1004
+ Examples:
1005
+
1006
+ \b
1007
+ # Save into current directory with server-provided filename
1008
+ das download files 6b0e68e6-00cd-43a7-9c51-d56c9c091123
1009
+
1010
+ \b
1011
+ # Save to a specific folder
1012
+ das download files 6b0e68e6-00cd-43a7-9c51-d56c9c091123 --out C:\\Downloads
1013
+
1014
+ \b
1015
+ # Save to an explicit filename, overwriting if exists
1016
+ das download files 6b0e68e6-00cd-43a7-9c51-d56c9c091123 --out C:\\Downloads\\bundle.zip --force
1017
+ """
1018
+ try:
1019
+ das_ctx.get_client()
1020
+ saved_path = das_ctx.download_manager.save_download(request_id=request_id, output_path=output_path, overwrite=force)
1021
+ click.secho(f"✓ Download saved to: {saved_path}", fg="green")
1022
+ except FileExistsError as e:
1023
+ click.secho(str(e), fg="yellow")
1024
+ except Exception as e:
1025
+ click.secho(f"Error: {e}", fg="red")
1026
+
995
1027
  @download.command("delete-request")
996
1028
  @click.argument('request_id', required=True)
997
1029
  @pass_das_context
@@ -27,6 +27,26 @@ def get_data(url, headers=None, params=None):
27
27
  print(f"Error fetching API data: {e}")
28
28
  return {"error": str(e)}
29
29
 
30
+ def get_binary_response(url, headers=None, params=None, stream=True):
31
+ """
32
+ Perform a GET request expected to return binary content.
33
+
34
+ Returns the raw requests.Response so callers can inspect headers
35
+ and stream content to disk.
36
+ """
37
+ try:
38
+ response = requests.get(
39
+ url,
40
+ headers=headers,
41
+ params=params,
42
+ verify=load_verify_ssl(),
43
+ stream=stream,
44
+ )
45
+ response.raise_for_status()
46
+ return response
47
+ except requests.RequestException as e:
48
+ return {"error": str(e)}
49
+
30
50
  def post_data(url, headers=None, data=None):
31
51
  """
32
52
  Send data to a REST API endpoint.
@@ -90,4 +90,46 @@ class DownloadManager:
90
90
 
91
91
  def get_my_requests(self):
92
92
  """Get all download requests for the current user."""
93
- return self.download_request_service.get_my_requests()
93
+ return self.download_request_service.get_my_requests()
94
+
95
+ def download_files(self, request_id: str):
96
+ """Return streaming response for files of a download request."""
97
+ return self.download_request_service.download_files(request_id)
98
+
99
+ def save_download(self, request_id: str, output_path: str, overwrite: bool = False) -> str:
100
+ """
101
+ Download and save the request bundle to disk.
102
+
103
+ Returns the path to the saved file.
104
+ """
105
+ import os
106
+
107
+ resp = self.download_files(request_id)
108
+ # If an error structure was returned from lower layer
109
+ if isinstance(resp, dict) and resp.get('error'):
110
+ raise ValueError(resp['error'])
111
+
112
+ # Determine filename from headers if available
113
+ filename = f"download_{request_id}.zip"
114
+ try:
115
+ cd = resp.headers.get('Content-Disposition') if hasattr(resp, 'headers') else None
116
+ if cd and 'filename=' in cd:
117
+ filename = cd.split('filename=')[-1].strip('"')
118
+ except Exception:
119
+ pass
120
+
121
+ # If output_path is a directory, join with filename
122
+ target_path = output_path
123
+ if os.path.isdir(output_path) or output_path.endswith(os.path.sep):
124
+ target_path = os.path.join(output_path, filename)
125
+
126
+ if os.path.exists(target_path) and not overwrite:
127
+ raise FileExistsError(f"File already exists: {target_path}. Use overwrite to replace.")
128
+
129
+ # Stream to disk
130
+ with open(target_path, 'wb') as f:
131
+ for chunk in resp.iter_content(chunk_size=8192):
132
+ if chunk:
133
+ f.write(chunk)
134
+
135
+ return target_path
@@ -1,10 +1,11 @@
1
- from das.common.api import post_data, get_data
1
+ from das.common.api import post_data, get_data, get_binary_response
2
2
  from das.common.config import load_token
3
3
 
4
4
 
5
5
  class DownloadRequestService:
6
6
  def __init__(self, base_url):
7
7
  self.base_url = f"{base_url}/api/services/app/DownloadRequest"
8
+ self.download_files_url = f"{base_url}/File/DownloadRequestSet"
8
9
 
9
10
  def create(self, request_data: list[dict]):
10
11
  """Create a new download request."""
@@ -81,4 +82,20 @@ class DownloadRequestService:
81
82
  error_msg = None
82
83
  if isinstance(response, dict):
83
84
  error_msg = response.get('error') or response.get('message')
84
- raise ValueError(error_msg or 'Failed to fetch download requests')
85
+ raise ValueError(error_msg or 'Failed to fetch download requests')
86
+
87
+ def download_files(self, request_id: str):
88
+ """Return a streaming HTTP response for the download bundle of a request."""
89
+ token = load_token()
90
+
91
+ if (token is None or token == ""):
92
+ raise ValueError("Authorization token is required")
93
+
94
+ headers = {
95
+ "Authorization": f"Bearer {token}"
96
+ }
97
+
98
+ url = f"{self.download_files_url}?requestId={request_id}"
99
+
100
+ response = get_binary_response(url, headers=headers, params=None, stream=True)
101
+ return response
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: das-cli
3
- Version: 1.1.0
3
+ Version: 1.2.0
4
4
  Summary: DAS api client.
5
5
  Author: Royal Netherlands Institute for Sea Research
6
6
  License-Expression: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "das-cli"
7
- version = "1.1.0"
7
+ version = "1.2.0"
8
8
  authors = [
9
9
  { name="Royal Netherlands Institute for Sea Research" },
10
10
  ]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes