gigl.common.utils.local_fs#

Attributes#

Classes#

FileSystemEntity

Class representing the entities in a file system.

Functions#

append_line_to_file(file_path, line)

Append a line to a file if it doesn't already exist in the file.

copy_files(local_source_to_local_dst_path_map[, ...])

Copy files from source paths to destination paths.

count_files_with_uri_prefix(uri_prefix[, suffix])

Count the number of files with a given URI prefix.

create_empty_file_if_none_exists(local_path)

Create an empty file if it doesn't already exist.

create_file_symlinks(local_source_to_link_path_map[, ...])

Create symlinks between source paths and link paths.

delete_and_create_local_path(local_path)

Deletes the existing local directory at the given path and creates a new one.

delete_local_directory(local_path)

Deletes a local directory.

does_path_exist(local_path)

Check if a file exists.

list_at_path(local_path, *[, regex, ...])

List all files and directories in the given local path.

remove_file_if_exist(local_path)

Remove file with os if file exists.

remove_file_or_folder_if_exist(local_path)

Remove a file or folder if it exists.

remove_folder_if_exist(local_path[, ignore_errors])

Remove a folder if it exists.

remove_line_from_file(file_path, line)

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.

DIRECTORY[source]#
FILE[source]#
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.

Parameters:
  • local_source_to_local_dst_path_map (Dict[LocalUri, LocalUri]) – A dictionary mapping source paths to destination paths.

  • should_overwrite (Optional[bool]) – If True, overwrite existing files at the destination paths. Defaults to False.

Returns:

None

Return type:

None

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

Create symlinks between source paths and link paths.

Parameters:
  • local_source_to_link_path_map (Dict[LocalUri, LocalUri]) – A dictionary mapping source paths to link paths.

  • should_overwrite (Optional[bool]) – If True, overwrite existing links at the link paths. Defaults to False.

Returns:

None

Return type:

None

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

gigl.common.utils.local_fs.remove_line_from_file(file_path, line)[source]#

Remove a line from a file if it exists in the file.

Parameters:
  • file_path (LocalUri) – The path of the file to remove the line from.

  • line (str) – The line to remove.

Returns:

None

Return type:

None

gigl.common.utils.local_fs.logger[source]#