Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a check for whether the CSV exists to assist UX #568

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions apps/dc_tools/odc/apps/dc_tools/add_update_products.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
systematically maintain a CSV of products and synchronise it with
a database"""

from collections import Counter, namedtuple

import click
import fsspec
import logging
import sys
import yaml
from collections import Counter, namedtuple
from csv import DictReader
from typing import Any, Dict, List, Optional, Generator, Tuple
from pathlib import Path
from typing import Any, Dict, Generator, List, Optional, Tuple

import click
import datacube
import fsspec
import yaml
from datacube import Datacube
from odc.apps.dc_tools.utils import (
update_if_exists_flag,
statsd_gauge_reporting,
statsd_setting,
update_if_exists_flag,
)

Product = namedtuple("Product", ["name", "doc"])
Expand Down Expand Up @@ -134,7 +134,12 @@ def cli(csv_path: str, update_if_exists: bool, statsd_setting: str):
update_if_exists,
)

# TODO: Add in some QA/QC checks
# Check if the CSV file exists
in_file = Path(csv_path)
if not in_file.exists():
logging.error("Could not find input CSV at %s", csv_path)
sys.exit(1)

added, updated, failed = add_update_products(dc, csv_path, update_if_exists)

print(f"Added: {added}, Updated: {updated} and Failed: {failed}")
Expand Down
11 changes: 11 additions & 0 deletions apps/dc_tools/tests/test_add_update_products.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@
)


def test_non_existing_csv():
runner = CliRunner()
result = runner.invoke(
add_update_products_cli,
[
"some_non_existing_file.csv",
],
)
assert result.exit_code == 1


def test_parse_local_csv(local_csv):
local_contents = [x for x in _parse_csv(local_csv)]

Expand Down