Kathara.foundation.model.FilesystemMixin - KatharaFramework/Kathara GitHub Wiki
Abstraction to manage filesystems of devices and network scenarios.
Attributes:
-
fs
(FS): An object referencing a filesystem. Can be both real OS or a memory fs.
__init__()
copy_directory_from_path(src_path: str, dst_path: str) → None
Copy a directory from a src_path in the host filesystem into a dst_path in this fs.
Args:
-
src_path
(str): The source path of the directory to copy. -
dst_path
(str): The destination path where to copy the directory.
Returns: None
Raises:
-
InvocationError
: If the fs is None.
create_file_from_list(lines: List[str], dst_path: str) → None
Create a file in the fs object from a list of strings.
Args:
-
lines
(List[str]): The list of strings representing the content of the file to create. -
dst_path
(str): The absolute path of the fs where create the file.
Returns: None
Raises:
-
InvocationError
: If the fs is None. -
fs.errors.ResourceNotFound
: If the path is not found in the fs.
create_file_from_path(src_path: str, dst_path: str) → None
Create a file in the fs object from an existing file on the host filesystem.
Args:
-
src_path
(str): The path of the file on the host filesystem to copy in the fs object. -
dst_path
(str): The absolute path of the fs where create the file.
Returns: None
Raises:
-
InvocationError
: If the fs is None. -
fs.errors.ResourceNotFound
: If the path is not found in the fs.
create_file_from_stream(stream: Union[BinaryIO, TextIO], dst_path: str) → None
Create a file in the fs object from a stream.
Args:
-
stream
(Union[BinaryIO, TextIO]): The stream representing the content of the file to create. -
dst_path
(str): The absolute path of the fs where create the file.
Returns: None
Raises:
-
InvocationError
: If the fs is None. -
UnsupportedOperation
: If the stream is opened without read permissions. -
fs.errors.ResourceNotFound
: If the path is not found in the fs.
create_file_from_string(content: str, dst_path: str) → None
Create a file in the fs object from a string.
Args:
-
content
(str): The string representing the content of the file to create. -
dst_path
(str): The absolute path of the fs where create the file.
Returns: None
Raises:
-
InvocationError
: If the fs is None. -
fs.errors.ResourceNotFound
: If the path is not found in the fs.
delete_line(
file_path: str,
line_to_delete: str,
first_occurrence: bool = False
) → int
Delete a specified line in a file.
Args:
-
file_path
(str): The path of the file to delete the line. -
line_to_delete
(str): A string or a regex representing the line to delete. -
first_occurrence
(bool): Deletes only first occurrence. Default is False.
Returns:
-
int
: Number of times the line has been deleted.
Raises:
-
InvocationError
: If the fs is None. -
fs.errors.FileExpected
: If the path is not a file. -
fs.errors.ResourceNotFound
: If the path does not exist.
fs_path() → Optional[str]
Return the path of the filesystem, if fs has a path on the host. Else, return None
Returns:
-
Optional
(str): The path of the filesystem in the fs.
fs_type() → Optional[str]
Return the name of the class of the fs object, if present. Else, return None.
Returns:
-
Optional
(str): The name of the class of the fs object.
update_file_from_list(lines: List[str], dst_path: str) → None
Update a file in the fs object from a list of strings.
Args:
-
lines
(List[str]): The list of strings representing the content for updating the file. -
dst_path
(str): The absolute path on the fs of the file to upload.
Returns: None
Raises:
-
InvocationError
: If the fs is None. -
fs.errors.ResourceNotFound
: If the path is not found in the fs.
update_file_from_string(content: str, dst_path: str) → None
Update a file in the fs object from a string.
Args:
-
content
(str): The string representing the content for updating the file. -
dst_path
(str): The absolute path on the fs of the file to update.
Returns: None
Raises:
-
InvocationError
: If the fs is None. -
fs.errors.ResourceNotFound
: If the path is not found in the fs.
write_line_after(
file_path: str,
line_to_add: str,
searched_line: str,
first_occurrence: bool = False
) → int
Write a new line after a specific line in a file.
Args:
-
file_path
(str): The path of the file to add the new line. -
line_to_add
(str): The new line to add after the searched line. -
searched_line
(str): A string or a regex representing the searched line. -
first_occurrence
(bool): Inserts line only after the first occurrence. Default is False.
Returns:
-
int
: Number of times the line has been added.
Raises:
-
InvocationError
: If the fs is None. -
fs.errors.FileExpected
: If the path is not a file. -
fs.errors.ResourceNotFound
: If the path does not exist.
write_line_before(
file_path: str,
line_to_add: str,
searched_line: str,
first_occurrence: bool = False
) → int
Write a new line before a specific line in a file.
Args:
-
file_path
(str): The path of the file to add the new line. -
line_to_add
(str): The new line to add before the searched line. -
searched_line
(str): A string or a regex representing the searched line. -
first_occurrence
(bool): Inserts line only before the first occurrence. Default is False.
Returns:
-
int
: Number of times the line has been added.
Raises:
-
InvocationError
: If the fs is None. -
fs.errors.FileExpected
: If the path is not a file. -
fs.errors.ResourceNotFound
: If the path does not exist.
This file was automatically generated via lazydocs.