fitzzftw.patch.patcher.PatchStatistics

        ---
config:
  height: 300px
  width: 300px

title: PatchStatistics
---
classDiagram
  TerminalColorMixin <|-- PatchStatistics
    

Inheritage diagramm for PatchStatistics

class PatchStatistics[source]

Bases: TerminalColorMixin

Collector for patch execution metrics and file operation statistics.

Tracks modified, created, and deleted files during a patch process and aggregates line-level changes (additions/removals). It supports colorized terminal output based on the configured verbosity level.

Variables:
  • _color_map – Mapping of operation types to terminal colors.

  • _verbosity – Controls the detail level of the statistical output.

  • _modified – List of DiffCodeFile objects identifying modified files.

  • _created – List of DiffCodeFile objects identifying new files.

  • _deleted – List of DiffCodeFile objects identifying removed files.

Public Data Attributes:

verbosity

Returns the current verbosity level.

total_files

Returns the total number of files affected by the patch.

lines_added

Returns the cumulative count of lines added across all files.

lines_removed

Returns the cumulative count of lines removed across all files.

files_modified

Returns the count of existing files that were changed.

files_created

Returns the count of files newly created by the patch.

files_deleted

Returns the count of files removed by the patch.

start_time

Inherited from TerminalColorMixin

use_colors

Global toggle to enable or disable colorized output.

Public Methods:

__init__([verbosity])

Initializes the statistics collector.

add_file(file)

Categorizes a processed file and updates aggregate line counters.

print()

Prints a colorized summary of the collected statistics to the terminal.

__repr__()

Returns a developer-friendly string representation of the instance.

Inherited from TerminalColorMixin

colorize(text, color_key[, bold])

Colorizes the text using ANSI escape sequences.

print(**kwargs)

Prints the line with color mapping based on its prefix.

Private Data Attributes:

_color_map

_start_time

_modified

_created

_deleted

_lines_added

_lines_removed

Inherited from TerminalColorMixin

_ANSI

Internal mapping of semantic names to ANSI escape sequences.


_ANSI: Color = <fitzzftw.patch.static.Color object>

Internal mapping of semantic names to ANSI escape sequences. Can be overridden for testing purposes.

__init__(verbosity=0)[source]

Initializes the statistics collector.

Parameters:

verbosity (int) – Output detail level. 0 for minimal, 1 for extended info.

add_file(file)[source]

Categorizes a processed file and updates aggregate line counters.

Analyzes the original and new headers to determine if the file was created, deleted, or modified.

Parameters:

file (DiffCodeFile) – The processed file object containing diff data.

Raises:

FtwPatchError – If the file object lacks a valid new header.

colorize(text, color_key, bold=False, **kwargs)

Colorizes the text using ANSI escape sequences.

Parameters:
  • text (str) – The string to colorize.

  • color_key ('red' | 'green' | 'yellow' | 'cyan' | 'terminal') – The color to use (‘red’, ‘green’, ‘cyan’).

  • bold (bool) – Whether to make the output bold.

  • kwargs – Arbitrary keyword arguments forwarded to the built-in print() function. This allows for fine-grained control over the output, such as specifying a custom ‘file’ stream or changing the line termination via ‘end’ (e.g., end=”|”).

Returns:

Colorized string or plain text if colors are disabled.

Return type:

None

property files_created: int

Returns the count of files newly created by the patch.

Returns:

Count of created files.

property files_deleted: int

Returns the count of files removed by the patch.

Returns:

Count of deleted files.

property files_modified: int

Returns the count of existing files that were changed.

Returns:

Count of modified files.

property lines_added: int

Returns the cumulative count of lines added across all files.

Returns:

Total lines added.

property lines_removed: int

Returns the cumulative count of lines removed across all files.

Returns:

Total lines removed.

print()[source]

Prints a colorized summary of the collected statistics to the terminal.

Output detail varies by ‘verbosity’ level: - Level 0: Total files processed. - Level 1: Total files and sum of added/removed lines.

property total_files: int

Returns the total number of files affected by the patch.

Returns:

Count of all processed files.

use_colors: ClassVar[bool] = True

Global toggle to enable or disable colorized output. Defaults to True; should be set explicitly based on CLI flags.

property verbosity: int

Returns the current verbosity level.

Returns:

Verbosity level.