Skip to content

json_formatter

appimage_updater.ui.output.json_formatter

JSON output formatter implementation.

JSONOutputFormatter(**kwargs)

JSON output formatter for programmatic consumption.

This formatter collects all output data and produces a structured JSON document at the end, suitable for automation and scripting.

Parameters:

Name Type Description Default
**kwargs Any

Additional arguments (ignored for compatibility)

{}
Source code in src/appimage_updater/ui/output/json_formatter.py
def __init__(self, **kwargs: Any):
    """Initialize the JSON formatter.

    Args:
        **kwargs: Additional arguments (ignored for compatibility)
    """
    self.data: dict[str, Any] = {
        "messages": [],
        "tables": [],
        "check_results": [],
        "application_list": [],
        "config_settings": [],
        "errors": [],
        "warnings": [],
        "info": [],
        "success": [],
        "sections": [],
    }
    self._current_section: str | None = None

data = {'messages': [], 'tables': [], 'check_results': [], 'application_list': [], 'config_settings': [], 'errors': [], 'warnings': [], 'info': [], 'success': [], 'sections': []} instance-attribute

end_section()

End the current output section for JSON output.

Source code in src/appimage_updater/ui/output/json_formatter.py
def end_section(self) -> None:
    """End the current output section for JSON output."""
    if self._current_section:
        self.data["sections"].append({"title": self._current_section, "end": True})
        self._current_section = None

finalize()

Finalize JSON output and print the complete JSON document.

Returns:

Type Description
str | None

None (output goes directly to stdout)

Source code in src/appimage_updater/ui/output/json_formatter.py
def finalize(self) -> str | None:
    """Finalize JSON output and print the complete JSON document.

    Returns:
        None (output goes directly to stdout)
    """
    output = json.dumps(self.data, indent=2, ensure_ascii=False)
    print(output)  # noqa: T201
    return None

print(message, **kwargs)

Print a message (store for JSON output).

Parameters:

Name Type Description Default
message str

The message to store

required
**kwargs Any

Additional options (ignored for JSON)

{}
Source code in src/appimage_updater/ui/output/json_formatter.py
def print(self, message: str, **kwargs: Any) -> None:
    """Print a message (store for JSON output).

    Args:
        message: The message to store
        **kwargs: Additional options (ignored for JSON)
    """
    self.data["messages"].append({"message": message, "kwargs": kwargs})

print_application_list(applications)

Store application list for JSON output.

Parameters:

Name Type Description Default
applications list[dict[str, Any]]

List of application dictionaries

required
Source code in src/appimage_updater/ui/output/json_formatter.py
def print_application_list(self, applications: list[dict[str, Any]]) -> None:
    """Store application list for JSON output.

    Args:
        applications: List of application dictionaries
    """
    self.data["application_list"] = applications

print_check_results(results)

Store check results for JSON output.

Parameters:

Name Type Description Default
results list[dict[str, Any]]

List of check result dictionaries

required
Source code in src/appimage_updater/ui/output/json_formatter.py
def print_check_results(self, results: list[dict[str, Any]]) -> None:
    """Store check results for JSON output.

    Args:
        results: List of check result dictionaries
    """
    self.data["check_results"] = results

print_config_settings(settings)

Store configuration settings for JSON output.

Parameters:

Name Type Description Default
settings dict[str, Any]

Dictionary of configuration settings

required
Source code in src/appimage_updater/ui/output/json_formatter.py
def print_config_settings(self, settings: dict[str, Any]) -> None:
    """Store configuration settings for JSON output.

    Args:
        settings: Dictionary of configuration settings
    """
    self.data["config_settings"] = settings

print_error(message)

Store error message for JSON output.

Parameters:

Name Type Description Default
message str

Error message to store

required
Source code in src/appimage_updater/ui/output/json_formatter.py
def print_error(self, message: str) -> None:
    """Store error message for JSON output.

    Args:
        message: Error message to store
    """
    self.data["errors"].append(message)

print_info(message)

Store info message for JSON output.

Parameters:

Name Type Description Default
message str

Info message to store

required
Source code in src/appimage_updater/ui/output/json_formatter.py
def print_info(self, message: str) -> None:
    """Store info message for JSON output.

    Args:
        message: Info message to store
    """
    self.data["info"].append(message)

print_progress(current, total, description='')

Store progress information for JSON output.

Parameters:

Name Type Description Default
current int

Current progress value

required
total int

Total progress value

required
description str

Optional progress description

''
Source code in src/appimage_updater/ui/output/json_formatter.py
def print_progress(self, current: int, total: int, description: str = "") -> None:
    """Store progress information for JSON output.

    Args:
        current: Current progress value
        total: Total progress value
        description: Optional progress description
    """
    progress_data = {
        "current": current,
        "total": total,
        "percentage": (current / total * 100) if total > 0 else 0,
        "description": description,
    }
    self.data["messages"].append({"type": "progress", "data": progress_data})

print_success(message)

Store success message for JSON output.

Parameters:

Name Type Description Default
message str

Success message to store

required
Source code in src/appimage_updater/ui/output/json_formatter.py
def print_success(self, message: str) -> None:
    """Store success message for JSON output.

    Args:
        message: Success message to store
    """
    self.data["success"].append(message)

print_table(data, title='', headers=None)

Store tabular data for JSON output.

Parameters:

Name Type Description Default
data list[dict[str, Any]]

List of dictionaries representing table rows

required
title str

Optional table title

''
headers list[str] | None

Optional custom headers

None
Source code in src/appimage_updater/ui/output/json_formatter.py
def print_table(self, data: list[dict[str, Any]], title: str = "", headers: list[str] | None = None) -> None:
    """Store tabular data for JSON output.

    Args:
        data: List of dictionaries representing table rows
        title: Optional table title
        headers: Optional custom headers
    """
    table_data = {"title": title, "headers": headers or (list(data[0].keys()) if data else []), "data": data}
    self.data["tables"].append(table_data)

print_warning(message)

Store warning message for JSON output.

Parameters:

Name Type Description Default
message str

Warning message to store

required
Source code in src/appimage_updater/ui/output/json_formatter.py
def print_warning(self, message: str) -> None:
    """Store warning message for JSON output.

    Args:
        message: Warning message to store
    """
    self.data["warnings"].append(message)

start_section(title)

Start a new output section for JSON output.

Parameters:

Name Type Description Default
title str

Section title

required
Source code in src/appimage_updater/ui/output/json_formatter.py
def start_section(self, title: str) -> None:
    """Start a new output section for JSON output.

    Args:
        title: Section title
    """
    self._current_section = title
    self.data["sections"].append({"title": title, "start": True})