FileManager#

class ansys.sam.sysml2.diagrams.utils.file_manager.FileManager#

Handles file operations and path management.

Overview#

save_binary_content

Save binary content to a file.

save_response_content

Save streamed response content to a file.

resolve_file_path

Resolve a valid file path from the given path and default filename.

ensure_directory_exists

Ensure that a directory exists. Create it if needed.

Import detail#

from ansys.sam.sysml2.diagrams.utils.file_manager import FileManager

Method detail#

static FileManager.save_binary_content(content: bytes, path: str | pathlib.Path, filename: str, file_format: str) pathlib.Path#

Save binary content to a file.

Parameters:
contentbytes

Binary content to write.

pathstr or Path

Path to a file or directory.

filenamestr

Name of the file to save.

file_formatstr

Format requested.

Returns:
Path

Path where the file was saved.

static FileManager.save_response_content(response: requests.Response, path: str | pathlib.Path, filename: str) pathlib.Path#

Save streamed response content to a file.

Parameters:
responserequests.Response

Response object containing the streamed data.

pathstr or Path

Path to a file or directory.

filenamestr

Name of the file to save.

Returns:
Path

Path where the file was saved.

static FileManager.resolve_file_path(path: str | pathlib.Path, filename: str) pathlib.Path#

Resolve a valid file path from the given path and default filename.

If a file is specified, use its parent directory and concatenate with the filename.

Parameters:
pathstr or Path

Directory or file path.

filenamestr

Default filename if path is a directory or filename to use with parent directory if path is a file.

Returns:
Path

Resolved file path.

Raises:
ValueError

If the path cannot be resolved properly.

static FileManager.ensure_directory_exists(directory_path: pathlib.Path) None#

Ensure that a directory exists. Create it if needed.

Parameters:
directory_pathPath

Directory to check or create.