From e6a578e60e124d3a70d867db845ab15a940ae8cd Mon Sep 17 00:00:00 2001 From: Patrick Robertson Date: Tue, 4 Mar 2025 16:44:15 +0000 Subject: [PATCH] Check for auto-archiver updates and present warning if there's a newer version available --- src/auto_archiver/core/orchestrator.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/auto_archiver/core/orchestrator.py b/src/auto_archiver/core/orchestrator.py index 274fa9e..cb1220f 100644 --- a/src/auto_archiver/core/orchestrator.py +++ b/src/auto_archiver/core/orchestrator.py @@ -15,6 +15,7 @@ from copy import copy from rich_argparse import RichHelpFormatter from loguru import logger +import requests from .metadata import Metadata, Media from auto_archiver.version import __version__ @@ -348,7 +349,23 @@ class ArchivingOrchestrator: yaml_config = self.load_config(basic_config.config_file) return self.setup_complete_parser(basic_config, yaml_config, unused_args) + + def check_for_updates(self): + response = requests.get("https://pypi.org/pypi/auto-archiver/json").json() + latest_version = response['info']['version'] + # check version compared to current version + if latest_version != __version__: + if os.environ.get('RUNNING_IN_DOCKER'): + update_cmd = "`docker pull bellingcat/auto-archiver:latest`" + else: + update_cmd = "`pip install --upgrade auto-archiver`" + logger.warning("") + logger.warning(f"********* IMPORTANT: UPDATE AVAILABLE ********") + logger.warning(f"A new version of auto-archiver is available (v{latest_version}, you have {__version__})") + logger.warning("Make sure to update to the latest version using: {update_cmd}") + logger.warning("") + def setup(self, args: list): """ Function to configure all setup of the orchestrator: setup configs and load modules. @@ -356,6 +373,8 @@ class ArchivingOrchestrator: This method should only ever be called once """ + self.check_for_updates() + if self.setup_finished: logger.warning("The `setup_config()` function should only ever be run once. \ If you need to re-run the setup, please re-instantiate a new instance of the orchestrator. \