cdsetool 0.2.11__tar.gz → 0.2.12__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.
@@ -1,10 +1,10 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cdsetool
3
- Version: 0.2.11
3
+ Version: 0.2.12
4
4
  Summary: Tools & CLI for interacting with CDSE product APIs
5
5
  Author-email: Jacob Vejby <javej@sdfi.dk>
6
- Project-URL: Homepage, https://github.com/SDFIdk/CDSETool
7
- Project-URL: Bug Tracker, https://github.com/SDFIdk/CDSETool/issues
6
+ Project-URL: Homepage, https://github.com/CDSETool/CDSETool
7
+ Project-URL: Bug Tracker, https://github.com/CDSETool/CDSETool/issues
8
8
  Classifier: Programming Language :: Python :: 3
9
9
  Classifier: Operating System :: OS Independent
10
10
  Requires-Python: >=3.8
@@ -17,8 +17,8 @@ Requires-Dist: pyjwt[crypto]~=2.8.0
17
17
  Requires-Dist: geopandas>=0.13.2
18
18
  Provides-Extra: test
19
19
  Requires-Dist: black==24.4.2; extra == "test"
20
- Requires-Dist: pylint==3.2.2; extra == "test"
21
- Requires-Dist: pytest==8.2.1; extra == "test"
20
+ Requires-Dist: pylint==3.2.6; extra == "test"
21
+ Requires-Dist: pytest==8.3.2; extra == "test"
22
22
  Requires-Dist: pytest-cov==5.0.0; extra == "test"
23
23
  Requires-Dist: requests-mock==1.12.1; extra == "test"
24
24
  Requires-Dist: pytest-mock==3.14.0; extra == "test"
@@ -96,7 +96,7 @@ cdsetool download Sentinel2 PATH/TO/DIR --concurrency 4 --search-term startDate=
96
96
  Install `cdsetool` using pip:
97
97
 
98
98
  ```bash
99
- pip install cdsetool==0.2.11
99
+ pip install cdsetool==0.2.12
100
100
  ```
101
101
 
102
102
  ## Usage
@@ -71,7 +71,7 @@ cdsetool download Sentinel2 PATH/TO/DIR --concurrency 4 --search-term startDate=
71
71
  Install `cdsetool` using pip:
72
72
 
73
73
  ```bash
74
- pip install cdsetool==0.2.11
74
+ pip install cdsetool==0.2.12
75
75
  ```
76
76
 
77
77
  ## Usage
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "cdsetool"
7
- version = "0.2.11"
7
+ version = "0.2.12"
8
8
  authors = [
9
9
  { name="Jacob Vejby", email="javej@sdfi.dk" },
10
10
  ]
@@ -25,16 +25,16 @@ dependencies = [
25
25
  [project.optional-dependencies]
26
26
  test = [
27
27
  "black==24.4.2",
28
- "pylint==3.2.2",
29
- "pytest==8.2.1",
28
+ "pylint==3.2.6",
29
+ "pytest==8.3.2",
30
30
  "pytest-cov==5.0.0",
31
31
  "requests-mock==1.12.1",
32
32
  "pytest-mock==3.14.0",
33
33
  ]
34
34
 
35
35
  [project.urls]
36
- "Homepage" = "https://github.com/SDFIdk/CDSETool"
37
- "Bug Tracker" = "https://github.com/SDFIdk/CDSETool/issues"
36
+ "Homepage" = "https://github.com/CDSETool/CDSETool"
37
+ "Bug Tracker" = "https://github.com/CDSETool/CDSETool/issues"
38
38
 
39
39
  [project.scripts]
40
40
  cdsetool = "cdsetool:cli.main"
@@ -12,9 +12,9 @@ from cdsetool.query import describe_collection, query_features
12
12
  from cdsetool.monitor import StatusMonitor
13
13
  from cdsetool.download import download_features
14
14
 
15
- app = typer.Typer()
15
+ app = typer.Typer(no_args_is_help=True)
16
16
 
17
- query_app = typer.Typer()
17
+ query_app = typer.Typer(no_args_is_help=True)
18
18
  app.add_typer(query_app, name="query")
19
19
 
20
20
 
@@ -120,3 +120,7 @@ def _to_dict(term_list: List[str]) -> Dict[str, str]:
120
120
  key, value = item.split("=")
121
121
  search_terms[key] = value
122
122
  return search_terms
123
+
124
+
125
+ if __name__ == "__main__":
126
+ main()
@@ -147,7 +147,7 @@ class Credentials: # pylint: disable=too-few-public-methods disable=too-many-in
147
147
  caller=self,
148
148
  authorization=False,
149
149
  max_retries=Retry(
150
- total=2,
150
+ total=15,
151
151
  backoff_factor=0.5,
152
152
  allowed_methods=None,
153
153
  raise_on_status=False,
@@ -38,6 +38,7 @@ def download_feature(
38
38
  log = _get_logger(options)
39
39
  url = _get_feature_url(feature)
40
40
  title = feature.get("properties").get("title")
41
+ temp_dir_usr = _get_temp_dir(options)
41
42
 
42
43
  if not url or not title:
43
44
  log.debug(f"Bad URL ('{url}') or title ('{title}')")
@@ -58,19 +59,25 @@ def download_feature(
58
59
  # Always get a new session, credentials might have expired.
59
60
  try:
60
61
  session = _get_credentials(options).get_session()
61
- except (TokenClientConnectionError, TokenExpiredSignatureError) as e:
62
- log.warning(e)
62
+ except TokenClientConnectionError:
63
+ log.warning("Token client connection failed, retrying..")
64
+ continue
65
+ except TokenExpiredSignatureError:
66
+ log.warning("Token signature expired, retrying..")
63
67
  continue
64
68
  url = _follow_redirect(url, session)
65
- with session.get(url, stream=True) as response:
69
+ name_dir_prefix = filename.replace(".zip", "____")
70
+ with session.get(url, stream=True) as response, tempfile.TemporaryDirectory(
71
+ prefix=name_dir_prefix, dir=temp_dir_usr
72
+ ) as temp_dir:
66
73
  if response.status_code != 200:
67
74
  log.warning(f"Status code {response.status_code}, retrying..")
68
75
  time.sleep(60 * (1 + (random.random() / 4)))
69
76
  continue
70
77
 
71
78
  status.set_filesize(int(response.headers["Content-Length"]))
72
-
73
- with tempfile.NamedTemporaryFile() as file:
79
+ tmp_file = os.path.join(temp_dir, "download.zip")
80
+ with open(tmp_file, "wb") as file:
74
81
  # Server might not send all bytes specified by the
75
82
  # Content-Length header before closing connection.
76
83
  # Log as a warning and try again.
@@ -85,8 +92,8 @@ def download_feature(
85
92
  ) as e:
86
93
  log.warning(e)
87
94
  continue
88
- shutil.copy(file.name, result_path)
89
-
95
+ # Close file before copy so all buffers are flushed.
96
+ shutil.copy(tmp_file, result_path)
90
97
  return filename
91
98
  log.error(f"Failed to download {filename}")
92
99
  return None
@@ -143,3 +150,7 @@ def _get_credentials(options: Dict) -> Credentials:
143
150
  return options.get("credentials") or Credentials(
144
151
  proxies=options.get("proxies", None)
145
152
  )
153
+
154
+
155
+ def _get_temp_dir(options: Dict) -> Union[str, None]:
156
+ return options.get("tmpdir") or None
@@ -156,7 +156,7 @@ def describe_collection(
156
156
  )
157
157
 
158
158
  parameters = {}
159
- if not parameter_node_parent:
159
+ if parameter_node_parent is None:
160
160
  return parameters
161
161
  for parameter_node in parameter_node_parent:
162
162
  name = parameter_node.attrib.get("name")
@@ -1,10 +1,10 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cdsetool
3
- Version: 0.2.11
3
+ Version: 0.2.12
4
4
  Summary: Tools & CLI for interacting with CDSE product APIs
5
5
  Author-email: Jacob Vejby <javej@sdfi.dk>
6
- Project-URL: Homepage, https://github.com/SDFIdk/CDSETool
7
- Project-URL: Bug Tracker, https://github.com/SDFIdk/CDSETool/issues
6
+ Project-URL: Homepage, https://github.com/CDSETool/CDSETool
7
+ Project-URL: Bug Tracker, https://github.com/CDSETool/CDSETool/issues
8
8
  Classifier: Programming Language :: Python :: 3
9
9
  Classifier: Operating System :: OS Independent
10
10
  Requires-Python: >=3.8
@@ -17,8 +17,8 @@ Requires-Dist: pyjwt[crypto]~=2.8.0
17
17
  Requires-Dist: geopandas>=0.13.2
18
18
  Provides-Extra: test
19
19
  Requires-Dist: black==24.4.2; extra == "test"
20
- Requires-Dist: pylint==3.2.2; extra == "test"
21
- Requires-Dist: pytest==8.2.1; extra == "test"
20
+ Requires-Dist: pylint==3.2.6; extra == "test"
21
+ Requires-Dist: pytest==8.3.2; extra == "test"
22
22
  Requires-Dist: pytest-cov==5.0.0; extra == "test"
23
23
  Requires-Dist: requests-mock==1.12.1; extra == "test"
24
24
  Requires-Dist: pytest-mock==3.14.0; extra == "test"
@@ -96,7 +96,7 @@ cdsetool download Sentinel2 PATH/TO/DIR --concurrency 4 --search-term startDate=
96
96
  Install `cdsetool` using pip:
97
97
 
98
98
  ```bash
99
- pip install cdsetool==0.2.11
99
+ pip install cdsetool==0.2.12
100
100
  ```
101
101
 
102
102
  ## Usage
@@ -6,8 +6,8 @@ geopandas>=0.13.2
6
6
 
7
7
  [test]
8
8
  black==24.4.2
9
- pylint==3.2.2
10
- pytest==8.2.1
9
+ pylint==3.2.6
10
+ pytest==8.3.2
11
11
  pytest-cov==5.0.0
12
12
  requests-mock==1.12.1
13
13
  pytest-mock==3.14.0
File without changes
File without changes