gigl.common.utils.local_fs#
Attributes#
Classes#
Class representing the entities in a file system. |
Functions#
|
Append a line to a file if it doesn't already exist in the file. |
|
Copy files from source paths to destination paths. |
|
Count the number of files with a given URI prefix. |
|
Create an empty file if it doesn't already exist. |
|
Create symlinks between source paths and link paths. |
|
Deletes the existing local directory at the given path and creates a new one. |
|
Deletes a local directory. |
|
Check if a file exists. |
|
List all files and directories in the given local path. |
|
Remove file with os if file exists. |
|
Remove a file or folder if it exists. |
|
Remove a folder if it exists. |
|
Remove a line from a file if it exists in the file. |
Module Contents#
- class gigl.common.utils.local_fs.FileSystemEntity[source]#
Bases:
enum.Enum
Class representing the entities in a file system.
- gigl.common.utils.local_fs.append_line_to_file(file_path, line)[source]#
Append a line to a file if it doesn’t already exist in the file.
- Parameters:
file_path (LocalUri) – The path of the file to append the line to.
line (str) – The line to append.
- Returns:
None
- Return type:
None
- gigl.common.utils.local_fs.copy_files(local_source_to_local_dst_path_map, should_overwrite=False)[source]#
Copy files from source paths to destination paths.
- gigl.common.utils.local_fs.count_files_with_uri_prefix(uri_prefix, suffix=None)[source]#
Count the number of files with a given URI prefix.
- Parameters:
uri_prefix (LocalUri) – The URI prefix to match.
suffix (Optional[str]) – The suffix to match. Defaults to None.
- Returns:
The number of files with the given URI prefix.
- Return type:
int
- gigl.common.utils.local_fs.create_empty_file_if_none_exists(local_path)[source]#
Create an empty file if it doesn’t already exist.
- Parameters:
local_path (LocalUri) – The local path of the file to be created.
- Returns:
None
- Return type:
None
- gigl.common.utils.local_fs.create_file_symlinks(local_source_to_link_path_map, should_overwrite=False)[source]#
Create symlinks between source paths and link paths.
- gigl.common.utils.local_fs.delete_and_create_local_path(local_path)[source]#
Deletes the existing local directory at the given path and creates a new one.
- Parameters:
local_path (LocalUri) – The path of the local directory to delete and create.
- Returns:
None
- Return type:
None
- gigl.common.utils.local_fs.delete_local_directory(local_path)[source]#
Deletes a local directory.
- Parameters:
local_path (LocalUri) – The path of the local directory to be deleted.
- Returns:
None
- Return type:
None
- gigl.common.utils.local_fs.does_path_exist(local_path)[source]#
Check if a file exists.
- Parameters:
local_path (LocalUri) – The local path to check.
- Returns:
True if the file exists, False otherwise.
- Return type:
bool
- gigl.common.utils.local_fs.list_at_path(local_path, *, regex=None, file_system_entity=None, names_only=False)[source]#
List all files and directories in the given local path.
- Parameters:
local_path (LocalUri) – The local path to search for files and directories.
regex (Optional[str]) – Optional regex to match. If not provided then all children will be returned.
entity (Optional[FileSystemEntity]) – Optional entity type to filter by. If not provided then all children will be returned.
names_only (bool) – If True, return only the base names of the files and directories. Defaults to False. e.g /path/to/file.txt -> file.txt
file_system_entity (Optional[FileSystemEntity])
- Returns:
A list of local URIs for the files and directories in the given path.
- Return type:
List[LocalUri]
- gigl.common.utils.local_fs.remove_file_if_exist(local_path)[source]#
Remove file with os if file exists.
- Parameters:
local_path (LocalUri) – The local path of the file to be removed.
- Returns:
None
- Return type:
None
- gigl.common.utils.local_fs.remove_file_or_folder_if_exist(local_path)[source]#
Remove a file or folder if it exists.
- Parameters:
local_path (LocalUri) – The local path of the file or folder to be removed.
- Returns:
None
- Return type:
None
- gigl.common.utils.local_fs.remove_folder_if_exist(local_path, ignore_errors=True)[source]#
Remove a folder if it exists.
- Parameters:
local_path (LocalUri) – The local path of the folder to be removed.
ignore_errors (bool) – If True, ignore errors during removal. Defaults to True.
- Returns:
None
- Return type:
None