fitzzftw.patch.patcher.FtwPatch¶
- class FtwPatch[source]¶
Bases:
objectMain class for the
ftwpatchprogram.Implements the PIMPLE idiom by storing the parsed
argparse.Namespaceobject and providing command-line arguments via read-only properties (getters).Public Data Attributes:
The path to the patch or diff file (ro).
The number of leading path components to strip from file names (ro).
The directory containing the files to be patched (ro).
Indicates if non-leading whitespace should be normalized (ro).
Indicates if pure blank lines should be ignored or normalized (ro).
Indicates if all whitespace differences should be completely ignored (ro).
Indicates whether the patch should only be simulated without writing to the file system (ro).
Get the verbosity level for console output (ro).
Get the normalized backup file extension (ro).
Get the base directory for backup files (ro).
Get the global reference timestamp for this session (ro).
Return the list of code files extracted from the patch (ro).
Public Methods:
__init__(args)Initializes the FtwPatch instance by storing the parsed command-line arguments.
__repr__()Return a machine-readable representation of the instance.
run()Execute the patching process and handle high-level errors.
apply(options)Orchestrate the staging of changes by applying hunks to temporary files.
Private Methods:
_get_patch_stream()Open the patch file and return a stream.
_parse()Initialize the parser and load patch data.
_create_backups(file_paths[, extension, ...])Create mandatory backups of all files before any modification.
_commit_changes(results, options)Move patched files to their final destination and clean up.
- __init__(args)[source]¶
Initializes the FtwPatch instance by storing the parsed command-line arguments.
- Parameters:
args (ArgParsOptions) – The argparse.Namespace object containing command-line arguments. Expected attributes: patch_file, strip_count, target_directory, normalize_whitespace, ignore_blank_lines, ignore_all_whitespace.
- Raises:
FileNotFoundError – If the patch file does not exist.
FtwPatchError – If any internal error occurs during setup.
- apply(options)[source]¶
Orchestrate the staging of changes by applying hunks to temporary files.
Orchestrates the patching process: 1. Calculate changes (Logical) 2. Stage changes (IO - Temporary) 3. Commit changes (IO - Final)
- Parameters:
options (FtwPatchApplyOptions) – Command line options for patch application.
- Raises:
PatchParseError – If the patch content is invalid (Indirect).
OSError – If reading or writing files fails (Indirect).
- property backup_ext: str¶
Get the normalized backup file extension (ro).
This property returns the extension including the dot and the optional timestamp if a keyword was used during initialization.
- Returns:
The backup extension string.
- property backup_path: Path¶
Get the base directory for backup files (ro).
This path is resolved and contains the processed timestamp if any keywords were present in the initial configuration.
- Returns:
The Path object for the backup directory.
- property dry_run: bool¶
Indicates whether the patch should only be simulated without writing to the file system (ro).
- Returns:
The dry run status.
- property ignore_all_whitespace: bool¶
Indicates if all whitespace differences should be completely ignored (ro).
- Returns:
The ignore status.
- property ignore_blank_lines: bool¶
Indicates if pure blank lines should be ignored or normalized (ro).
- Returns:
The ignore status.
- property normalize_whitespace: bool¶
Indicates if non-leading whitespace should be normalized (ro).
- Returns:
The normalization status.
- property parsed_files: list[DiffCodeFile]¶
Return the list of code files extracted from the patch (ro).
- Raises:
PatchParseError – If the patch format is invalid (Indirect).
FileNotFoundError – If the patch file does not exist (Indirect).
PermissionError – If the patch file cannot be accessed (Indirect).
OSError – If file access fails during parsing (Indirect).
- Returns:
List of DiffCodeFile objects.
- property patch_file_path: Path¶
The path to the patch or diff file (ro).
- Returns:
The path object for the patch file.
- run()[source]¶
Execute the patching process and handle high-level errors.
- Returns:
Exit code (0 for success, 1 or 2 for errors).
- Return type:
int | None
- property start_time: datetime¶
Get the global reference timestamp for this session (ro).
This timestamp is fixed at program start to ensure consistency between directory names and file extensions.
- Returns:
The reference datetime.datetime object.
- property strip_count: int¶
The number of leading path components to strip from file names (ro).
- Returns:
The strip count value.