Skip to content

Commit

Permalink
add warning that tidy up is in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
jnussbaum committed Apr 26, 2024
1 parent 8f8aec0 commit 464a08f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/dsp_tools/commands/xmlupload/xmlupload.py
Expand Up @@ -2,6 +2,7 @@

import pickle
import sys
import warnings
from datetime import datetime
from pathlib import Path
from typing import Any
Expand Down Expand Up @@ -32,6 +33,7 @@
from dsp_tools.commands.xmlupload.stash.upload_stashed_xml_texts import upload_stashed_xml_texts
from dsp_tools.commands.xmlupload.upload_config import UploadConfig
from dsp_tools.commands.xmlupload.write_diagnostic_info import write_id2iri_mapping
from dsp_tools.models.custom_warnings import GeneralDspToolsWarning
from dsp_tools.models.exceptions import BaseError
from dsp_tools.models.exceptions import PermanentTimeOutError
from dsp_tools.models.exceptions import UserError
Expand Down Expand Up @@ -353,6 +355,7 @@ def _upload_one_resource(
try:
iri, label = _create_resource(resource, media_info, resource_create_client)
except (PermanentTimeOutError, KeyboardInterrupt) as err:
warnings.warn(GeneralDspToolsWarning(f"{type(err).__name__}: Tidying up, then exit..."))
msg = (
f"There was a {type(err).__name__} while trying to create resource '{resource.res_id}'.\n"
f"It is unclear if the resource '{resource.res_id}' was created successfully or not.\n"
Expand All @@ -367,6 +370,7 @@ def _upload_one_resource(
try:
_tidy_up_resource_creation_idempotent(upload_state, iri, label, resource, current_res, total_res)
except KeyboardInterrupt:
warnings.warn(GeneralDspToolsWarning("KeyboardInterrupt: Tidying up, then exit..."))
_tidy_up_resource_creation_idempotent(upload_state, iri, label, resource, current_res, total_res)


Expand Down
9 changes: 9 additions & 0 deletions src/dsp_tools/models/custom_warnings.py
Expand Up @@ -13,6 +13,15 @@ def showwarning(cls, message: str) -> None:
"""Functionality that should be executed when a warning of this class is emitted"""


class GeneralDspToolsWarning(Warning):
"""Class for user-facing deprecation warnings"""

@classmethod
def showwarning(cls, message: str) -> None:
"""Print the warning, without context"""
cprint(message, color="red", attrs=["bold"])


class DspToolsFutureWarning(FutureWarning):
"""Class for user-facing deprecation warnings"""

Expand Down

0 comments on commit 464a08f

Please sign in to comment.