File¶
file
¶
Filesystem helpers for path manipulation, file I/O, symlink management, and addon discovery.
Sections
- Path utilities: path predicates, canonical path computation, prefix checks
- File I/O: plain-text file reading/writing and directory copy
- Symlinks: listing, mapping, rewriting, and materialising symlinks
- Addons: locating and collecting Odoo addon directories
Functions:
| Name | Description |
|---|---|
check_prefix |
Check whether a path is equal to or descends from a prefix directory. |
collect_addon_paths |
Collect (addon_path, unported) pairs from an addons directory. |
copytree |
Copy a directory tree from src to dst, preserving symlinks. |
desired_path |
Build the desired local path for a git repository URL. |
ensure_parent |
Ensure the parent directory of a path exists, creating it if needed. |
find_addon_dirs |
Return all addon directories found under a root path. |
find_addons |
Yield AddonInfo for every Odoo addon found under a root directory. |
find_modified_addons |
Return the names of addons containing any of the given file paths. |
get_addons_diff |
Classify addon changes between base_ref and HEAD into new, updated, and removed. |
get_symlink_complete_map |
Return a mapping of symlink parent dirs to all their target names. |
get_symlink_map |
Build a mapping of symlink parent directories to their single target name. |
is_dir_empty |
Check whether a directory exists and contains no entries. |
is_pull_request_path |
Detect whether a submodule path looks like a pull request path. |
list_symlinks |
Collect symlink targets found recursively under a directory. |
make_migration_command |
Build the content of a migration shell script from addon change lists. |
materialize_symlink |
Replace a symlink pointing to a directory with a physical copy of its target. |
parse_odoo_version |
Read and return the Odoo version string from the project version file. |
parse_packages |
Read and return the sorted list of packages from the project packages file. |
parse_requirements |
Read and return the sorted list of entries from the project requirements file. |
parse_text_file |
Parse a text file's content into a set of non-empty, stripped lines. |
read_and_parse |
Read a text file and return its non-empty, sorted lines. |
relpath |
Compute a relative path from one location to another. |
rewrite_symlink |
Rewrite a symlink's target by replacing a path prefix. |
update_gitignore |
Ensure given folder names are present in .gitignore under a header section. |
write_migration_script |
Write a migration script to the configured file path and mark it executable. |
write_text_file |
Write a list of lines to a text file. |
check_prefix
¶
Check whether a path is equal to or descends from a prefix directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Path to test. |
required |
|
str
|
Ancestor path to check against. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if path equals prefix or is nested inside it, False otherwise. |
Source code in oops/io/file.py
collect_addon_paths
¶
collect_addon_paths(addons_dir: Path) -> list
Collect (addon_path, unported) pairs from an addons directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Path
|
Root addons directory to inspect. |
required |
Returns:
| Type | Description |
|---|---|
list
|
Sorted list of (Path, bool) pairs where the bool indicates |
list
|
whether the addon lives under the unported subdirectory. |
Source code in oops/io/file.py
copytree
¶
Copy a directory tree from src to dst, preserving symlinks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Path
|
Source directory to copy. |
required |
|
Path
|
Destination path, must not already exist. |
required |
|
bool
|
If True, skip .git directories. Defaults to True. |
True
|
Source code in oops/io/file.py
desired_path
¶
desired_path(url: str, pull_request: bool = False, prefix: Optional[str] = None, suffix: Optional[str] = None) -> str
Build the desired local path for a git repository URL.
Produces <prefix>/<owner>/<repo>/<suffix>, inserting a pull-request
segment after the prefix when pull_request is True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
GitHub repository URL (HTTPS or SSH). |
required |
|
bool
|
If True, insert the pull-request directory segment. Defaults to False. |
False
|
|
Optional[str]
|
Optional path prefix prepended before the owner segment. |
None
|
|
Optional[str]
|
Optional path segment appended after the repo name. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Relative filesystem path derived from the repository URL components. |
Source code in oops/io/file.py
ensure_parent
¶
find_addon_dirs
¶
Return all addon directories found under a root path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Path
|
Directory to search recursively. |
required |
|
bool
|
If True, descend into pull-request subdirectories. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
list
|
List of Path objects for each directory containing a manifest file. |
Source code in oops/io/file.py
find_addons
¶
Yield AddonInfo for every Odoo addon found under a root directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Path
|
Directory to search recursively (symlinked first-level dirs are followed). |
required |
|
bool
|
If True, do not recurse deeper than one level into subdirectories. Defaults to False. |
False
|
Yields:
| Type | Description |
|---|---|
AddonInfo
|
AddonInfo for each addon directory containing a manifest file. |
Source code in oops/io/file.py
find_modified_addons
¶
Return the names of addons containing any of the given file paths.
Walks up each file path until a directory with an Odoo manifest is found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
list
|
List of file paths to inspect. |
required |
Returns:
| Type | Description |
|---|---|
list
|
Sorted list of addon directory names that contain at least one of the files. |
Source code in oops/io/file.py
get_addons_diff
¶
Classify addon changes between base_ref and HEAD into new, updated, and removed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Repo
|
GitPython Repo object for the local repository. |
required |
|
str
|
Git ref (tag, branch, or commit-ish) to compare against HEAD. |
required |
Returns:
| Type | Description |
|---|---|
list
|
Tuple of (new_addons, updated_addons, removed_addons), each a sorted list |
list
|
of addon names. |
Source code in oops/io/file.py
get_symlink_complete_map
¶
Return a mapping of symlink parent dirs to all their target names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Root directory to scan for symlinks. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dict mapping each parent directory path to a list of target names |
dict
|
found under it. |
Source code in oops/io/file.py
get_symlink_map
¶
Build a mapping of symlink parent directories to their single target name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Root directory to scan for symlinks. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dict mapping each parent directory path to one target name. |
dict
|
Assumes at most one symlink per parent directory. |
Source code in oops/io/file.py
is_dir_empty
¶
is_pull_request_path
¶
Detect whether a submodule path looks like a pull request path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Optional[str]
|
Submodule path string to inspect. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the path matches pull-request naming conventions, False otherwise. |
Source code in oops/io/file.py
list_symlinks
¶
Collect symlink targets found recursively under a directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
PathLike
|
Root directory to walk. |
required |
|
bool
|
If True, only return targets of broken symlinks. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of symlink target strings found under path. |
Source code in oops/io/file.py
make_migration_command
¶
make_migration_command(new_addons: Optional[list] = None, updated_addons: Optional[list] = None, removed_addons: Optional[list] = None, release: Optional[str] = None) -> str
Build the content of a migration shell script from addon change lists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Optional[list]
|
Addons to install with |
None
|
|
Optional[list]
|
Addons to update with |
None
|
|
Optional[list]
|
Addons that were removed; included as a comment only. |
None
|
|
Optional[str]
|
Release label used in the script header. Defaults to "Unreleased". |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Full migration script content as a string, including the shebang line. |
Source code in oops/io/file.py
materialize_symlink
¶
materialize_symlink(symlink_path: Path, dry_run: bool) -> None
Replace a symlink pointing to a directory with a physical copy of its target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Path
|
Path to the symlink to materialize. |
required |
|
bool
|
If True, validate inputs but make no filesystem changes. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the path does not exist, is not a symlink, its target is not a directory, or materialization fails. |
Source code in oops/io/file.py
parse_odoo_version
¶
Read and return the Odoo version string from the project version file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Path
|
Project root directory containing the Odoo version file. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Odoo version string (first non-empty line of the version file). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the version file is empty or missing. |
Source code in oops/io/file.py
parse_packages
¶
parse_requirements
¶
Read and return the sorted list of entries from the project requirements file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Path
|
Project root directory containing the requirements file. |
required |
Returns:
| Type | Description |
|---|---|
list
|
Sorted list of requirement strings. |
Source code in oops/io/file.py
parse_text_file
¶
read_and_parse
¶
relpath
¶
Compute a relative path from one location to another.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Path
|
The starting directory. |
required |
|
Path
|
The target path to reach. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Relative path string from from_path to to_path. |
Source code in oops/io/file.py
rewrite_symlink
¶
rewrite_symlink(link: Path, old_prefix: str, new_prefix: str) -> bool
Rewrite a symlink's target by replacing a path prefix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Path
|
Path to the symlink to rewrite. |
required |
|
str
|
Prefix to replace in the symlink target. |
required |
|
str
|
Replacement prefix. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the symlink was rewritten, False if the target did not match. |
Source code in oops/io/file.py
update_gitignore
¶
update_gitignore(file_path: Union[str, Path], folders: list, header: str = '# Ignored addons (auto)') -> bool
Ensure given folder names are present in .gitignore under a header section.
Adds missing entries only (idempotent). Normalizes folder patterns to 'name/'. Appends a header at EOF if absent, then the new folders under it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Union[str, Path]
|
Path to .gitignore file |
required |
|
list
|
List of folder names to add |
required |
|
str
|
Header comment to use for the section |
'# Ignored addons (auto)'
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the file was modified, False otherwise |
Source code in oops/io/file.py
write_migration_script
¶
Write a migration script to the configured file path and mark it executable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Full script content to write. |
required |
|
bool
|
If True, print to stdout instead of writing to disk. Defaults to False. |
False
|
Source code in oops/io/file.py
write_text_file
¶
Write a list of lines to a text file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Path
|
Destination file path. |
required |
|
list
|
Lines to write, joined by new_line. |
required |
|
str
|
Line separator. Defaults to "\n". |
'\n'
|
|
bool
|
If True, append a trailing newline. Defaults to True. |
True
|