ats_utilities.factory_file_utils module

Module

factory_file_utils.py

Copyright

Copyright (C) 2017 - 2026 Vladimir Roncevic <elektron.ronca@gmail.com> ats_utilities is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. ats_utilities is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Info

Defines factory file utility functions.

ats_utilities.factory_file_utils.apply_path_replacements(rel_path: str, path_replacements: dict[str, str], vals: dict[str, str]) str[source]

Applies path replacements to a relative path using casing heuristics.

Parameters:
  • rel_path (<str>) – The original relative path.

  • path_replacements (<dict[str, str]>) – String replacements mapping.

  • vals (<dict[str, str]>) – Computed template values.

Returns:

The replaced relative path.

Return type:

<str>

Exceptions:
ATSTypeError: Expected str parameters, got <type>.
ats_utilities.factory_file_utils.check_file_exists(file_path: str) None[source]

Checks if a file exists.

Parameters:

file_path (<str>) – Path to the file.

Exceptions:
ATSTypeError: Expected str for ‘file_path’, got <type>.
ATSValueError: File at the provided path does not exist.
ats_utilities.factory_file_utils.format_casing_by_match(clean_str: str, default_val: str, upper_val: str, camel_val: str, dashed_val: str) str[source]

Formats a replacement value according to the casing style matched in clean_str.

Parameters:
  • clean_str (<str>) – Cleaned matched substring to analyze.

  • default_val (<str>) – Default replacement value.

  • upper_val (<str>) – Value in UPPER_CASE.

  • camel_val (<str>) – Value in CamelCase/PascalCase.

  • dashed_val (<str>) – Value in dashed-case.

Returns:

The replacement formatted in matching casing style.

Return type:

<str>

Exceptions:
ATSTypeError: Expected str parameters, got <type>.
ats_utilities.factory_file_utils.is_excluded_path(rel_path: str, exclude_patterns: list[str]) bool[source]

Checks if a relative path matches any exclusion patterns.

Parameters:
  • rel_path (<str>) – The relative path to inspect.

  • exclude_patterns (<list[str]>) – List of glob patterns to exclude.

Returns:

True if the path should be excluded, False otherwise.

Return type:

<bool>

Exceptions:
ATSTypeError: Expected str and list parameters, got <type>.
ats_utilities.factory_file_utils.normalize_path(path: str) str[source]

Normalizes file paths and strips leading directory prefixes.

Parameters:

path (<str>) – The original path to clean up.

Returns:

The cleaned up relative path.

Return type:

<str>

Exceptions:
ATSTypeError: Expected str for ‘path’, got <type>.
ats_utilities.factory_file_utils.resolve_relative_path(normalized_name: str, source_dir_clean: str) str | None[source]

Calculates relative path to the specified source directory.

Parameters:
  • normalized_name (<str>) – The cleaned name of the archive member.

  • source_dir_clean (<str>) – Cleaned source directory name.

Returns:

The relative path inside the source dir, or None if not matching.

Return type:

<str | None>

Exceptions:
ATSTypeError: Expected str for parameters, got <type>.
ats_utilities.factory_file_utils.write_content(file_path: str, content: str | bytes) None[source]

Writes string or bytes content to a file.

Parameters:
  • file_path (<str>) – Path to the target file.

  • content (<str | bytes>) – Text string or raw bytes to write.

Exceptions:
ATSTypeError: Expected str for ‘file_path’, or str/bytes for ‘content’.