diff --git a/disdrodb/data_transfer/scripts/download_disdrodb_archive.py b/disdrodb/data_transfer/scripts/download_disdrodb_archive.py
index 055382bd..ca1f60b1 100644
--- a/disdrodb/data_transfer/scripts/download_disdrodb_archive.py
+++ b/disdrodb/data_transfer/scripts/download_disdrodb_archive.py
@@ -14,13 +14,16 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
# -----------------------------------------------------------------------------.
-####################################################################
-## Wrapper to download disdrodb archives by command lines ##
-####################################################################
+"""Wrapper to download stations from the DISDRODB Decentralized Data Archive."""
+
+import sys
+
import click
from disdrodb.data_transfer.download_data import click_download_option
+sys.tracebacklimit = 0 # avoid full traceback error if occur
+
@click.command()
@click_download_option
diff --git a/disdrodb/metadata/check_metadata.py b/disdrodb/metadata/check_metadata.py
index f920fb46..d642f845 100644
--- a/disdrodb/metadata/check_metadata.py
+++ b/disdrodb/metadata/check_metadata.py
@@ -489,7 +489,7 @@ def check_archive_metadata_reader(base_dir: str = None) -> bool:
return is_valid
-def check_archive_metadata_compliance(base_dir: str = None):
+def check_archive_metadata_compliance(base_dir: str = None, raise_error=False):
"""Check the archive metadata compliance.
Parameters
@@ -497,6 +497,9 @@ def check_archive_metadata_compliance(base_dir: str = None):
base_dir : str (optional)
Base directory of DISDRODB. Format: <...>/DISDRODB
If None (the default), the disdrodb config variable 'dir' is used.
+ raise_error: bool (optional)
+ Whether to raise an error and interrupt the archive check if a
+ metadata is not compliant. The default is False.
Returns
-------
@@ -512,6 +515,7 @@ def check_archive_metadata_compliance(base_dir: str = None):
data_source = _infer_data_source_from_path(fpath)
campaign_name = _infer_campaign_name_from_path(fpath)
station_name = os.path.basename(fpath).replace(".yml", "")
+ # Check compliance
try:
check_metadata_compliance(
base_dir=base_dir,
@@ -521,8 +525,13 @@ def check_archive_metadata_compliance(base_dir: str = None):
)
except Exception as e:
is_valid = False
- print(f"Error for {data_source} {campaign_name} {station_name}.")
- print(f"The error is: {e}.")
+ msg = f"Error for {data_source} {campaign_name} {station_name}."
+ msg = msg + f"The error is: {e}."
+ if raise_error:
+ raise ValueError(msg)
+ else:
+ print(msg)
+
return is_valid
diff --git a/disdrodb/metadata/scripts/check_metadata_archive.py b/disdrodb/metadata/scripts/check_metadata_archive.py
index e852be1b..6cbdb52c 100644
--- a/disdrodb/metadata/scripts/check_metadata_archive.py
+++ b/disdrodb/metadata/scripts/check_metadata_archive.py
@@ -15,12 +15,16 @@
# along with this program. If not, see .
# -----------------------------------------------------------------------------.
"""Wrapper to check DISDRODB Metadata Archive Compliance from terminal."""
+import sys
+
import click
+sys.tracebacklimit = 0 # avoid full traceback error if occur
+
@click.command()
@click.option("--base_dir", type=str, show_default=True, default=None, help="DISDRODB root directory")
-def disdrodb_check_metadata_archive(base_dir=None):
+def check_metadata_archive(base_dir=None):
from disdrodb.metadata.check_metadata import check_archive_metadata_compliance
- check_archive_metadata_compliance(base_dir=base_dir)
+ check_archive_metadata_compliance(base_dir=base_dir, raise_error=True)
diff --git a/disdrodb/tests/test_metadata/test_check_metadata.py b/disdrodb/tests/test_metadata/test_check_metadata.py
index 41dde581..712185c4 100644
--- a/disdrodb/tests/test_metadata/test_check_metadata.py
+++ b/disdrodb/tests/test_metadata/test_check_metadata.py
@@ -275,6 +275,9 @@ def test_check_archive_metadata_reader(tmp_path):
def test_check_archive_metadata_compliance(tmp_path):
+ # from pathlib import Path
+ # tmp_path = Path("/tmp/")
+
base_dir = os.path.join(tmp_path, "DISDRODB")
# We check only the failure, the success are tested in the above tests.
@@ -283,9 +286,14 @@ def test_check_archive_metadata_compliance(tmp_path):
campaign_name = "campaign_name"
yaml_dict = {"reader": ""}
create_fake_metadata_file(tmp_path, yaml_file_name, yaml_dict, data_source, campaign_name)
- result = check_archive_metadata_compliance(base_dir)
+ # Test does not raise error !
+ result = check_archive_metadata_compliance(base_dir, raise_error=False)
assert result is False
+ # Test it raise error
+ with pytest.raises(ValueError):
+ result = check_archive_metadata_compliance(base_dir, raise_error=True)
+
def test_check_archive_metadata_geolocation(tmp_path):
# We check only the failure, the success are tested in the above test.