files
Methods for changing files.
Classes¶
ConfiguredFile
¶
ConfiguredFile(file_change: FileChange, version_config: VersionConfig, search: Optional[str] = None, replace: Optional[str] = None)
A file to modify in a configured way.
Methods:¶
get_file_contents
¶
get_file_contents() -> str
Return the contents of the file.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The contents of the file |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
if the file doesn’t exist |
make_file_change
¶
make_file_change(current_version: Version, new_version: Version, context: MutableMapping, dry_run: bool = False) -> None
Make the change to the file.
DataFileUpdater
¶
DataFileUpdater(file_change: FileChange, version_part_configs: Dict[str, VersionComponentSpec])
FileUpdater
¶
FileUpdater(file_change: FileChange, version_config: VersionConfig, search: Optional[str] = None, replace: Optional[str] = None)
Functions:¶
contains_pattern
¶
contains_pattern(search: Pattern, contents: str) -> bool
Does the search pattern match any part of the contents?
log_changes
¶
log_changes(file_path: str, file_content_before: str, file_content_after: str, dry_run: bool = False) -> None
Log the changes that would be made to the file.
| PARAMETER | DESCRIPTION |
|---|---|
file_path
|
The path to the file
TYPE:
|
file_content_before
|
The file contents before the change
TYPE:
|
file_content_after
|
The file contents after the change
TYPE:
|
dry_run
|
True if this is a report-only job
TYPE:
|
modify_files
¶
modify_files(files: List[ConfiguredFile], current_version: Version, new_version: Version, context: MutableMapping, dry_run: bool = False) -> None
Modify the files, searching and replacing values according to the FileConfig.
| PARAMETER | DESCRIPTION |
|---|---|
files
|
The list of configured files
TYPE:
|
current_version
|
The current version
TYPE:
|
new_version
|
The next version
TYPE:
|
context
|
The context used for rendering the version
TYPE:
|
dry_run
|
True if this should be a report-only job
TYPE:
|
resolve_file_config
¶
resolve_file_config(files: List[FileChange], version_config: VersionConfig, search: Optional[str] = None, replace: Optional[str] = None) -> List[ConfiguredFile]
Resolve the files, searching and replacing values according to the FileConfig.
| PARAMETER | DESCRIPTION |
|---|---|
files
|
A list of file configurations
TYPE:
|
version_config
|
How the version should be changed
TYPE:
|
search
|
The search pattern to use instead of any configured search pattern |
replace
|
The replace pattern to use instead of any configured replace pattern |
| RETURNS | DESCRIPTION |
|---|---|
List[ConfiguredFile]
|
A list of ConfiguredFiles |