Skip to content
Merged
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
27 changes: 27 additions & 0 deletions cirro/cli/controller.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import logging
import importlib.metadata
import os
import requests
import sys

import pandas as pd
Expand Down Expand Up @@ -32,6 +34,7 @@
def run_list_datasets(input_params: ListArguments, interactive=False):
"""List the datasets available in a particular project."""
_check_configure()
_check_version()
cirro = CirroApi()
logger.info(f"Collecting data from {cirro.configuration.base_url}")
projects = cirro.projects.list()
Expand All @@ -56,6 +59,7 @@ def run_list_datasets(input_params: ListArguments, interactive=False):

def run_ingest(input_params: UploadArguments, interactive=False):
_check_configure()
_check_version()
cirro = CirroApi()
logger.info(f"Collecting data from {cirro.configuration.base_url}")
processes = cirro.processes.list(process_type=Executor.INGEST)
Expand Down Expand Up @@ -112,6 +116,7 @@ def run_ingest(input_params: UploadArguments, interactive=False):

def run_download(input_params: DownloadArguments, interactive=False):
_check_configure()
_check_version()
cirro = CirroApi()
logger.info(f"Collecting data from {cirro.configuration.base_url}")

Expand Down Expand Up @@ -171,6 +176,7 @@ def run_download(input_params: DownloadArguments, interactive=False):


def run_configure():
_check_version()
auth_method, base_url, auth_method_config, enable_additional_checksum = gather_auth_config()
save_user_config(UserConfig(auth_method=auth_method,
auth_method_config=auth_method_config,
Expand All @@ -193,6 +199,27 @@ def _check_configure():
run_configure()


def _check_version():
"""
Prompts the user to update their package version if needed
"""
yellow_color = '\033[93m'
reset_color = '\033[0m'

try:
current_version = importlib.metadata.version('cirro')
response = requests.get("https://pypi.org/pypi/cirro/json")
response.raise_for_status()
latest_version = response.json()["info"]["version"]

if current_version != latest_version:
print(f"{yellow_color}Warning:{reset_color} Cirro version {current_version} "
f"is out of date. Update to {latest_version} with 'pip install cirro --upgrade'.")

except Exception:
return


def handle_error(e: Exception):
logger.error(f"{e.__class__.__name__}: {e}")
sys.exit(1)
Loading