class documentation

class ProgramsFileManager(object):

Constructor: ProgramsFileManager(programs_dir, extension)

View In Hierarchy

A manager for handling program files.

This class provides methods to create, read, update, and delete program files.

Parameters
programs_dirThe directory where program files are stored.
extensionThe file extension for program files.
Method __init__ Initialize the ProgramsFileManager.
Method exists Check if a file with a certain name exists.
Method get_all_names Get a list of all file names available in the storage.
Method get_file_path Undocumented
Method read Read the content of the specified file.
Method remove Remove the specified file.
Method temporary_file Undocumented
Method write Write the content of code inside a file named name
Method _path_from_name Get the full file path from the given file name.
Instance Variable __extension Undocumented
Instance Variable __programs_dir Undocumented
def __init__(self, programs_dir: str, extension: str):

Initialize the ProgramsFileManager.

Parameters
programs_dir:strThe directory where program files are stored.
extension:strThe file extension for program files.
def exists(self, name: str) -> bool:

Check if a file with a certain name exists.

Parameters
name:strThe name of the file to check.
Returns
boolTrue if the file exists, else False.
def get_all_names(self, with_suffix: bool = False) -> List[str]:

Get a list of all file names available in the storage.

Parameters
with_suffix:boolIf True, include file extensions in the names.
Returns
list[str]A list of file names.
Raises
Unknown exceptionProgramFileException: If the list of files cannot be retrieved.
def get_file_path(self, name: str) -> str:

Undocumented

def read(self, name: str) -> str:

Read the content of the specified file.

Parameters
name:strThe name of the file to read.
Returns
strThe content of the file.
Raises
Unknown exceptionProgramFileException: If the file does not exist or cannot be read.
def remove(self, name: str):

Remove the specified file.

Parameters
name:strThe name of the file to remove.
Raises
Unknown exceptionProgramFileException: If the file cannot be removed.
@contextmanager
def temporary_file(self, code: str) -> Generator[str, None, None]:

Undocumented

def write(self, name: str, code: str, overwrite_allowed: bool = False):

Write the content of code inside a file named name

Parameters
name:strThe name of the file to write to.
code:strThe content of the file.
overwrite_allowed:boolIf True and a file already exist with this name, it will be overwritten
Raises
Unknown exceptionProgramFileException: If the file cannot be created or written.
def _path_from_name(self, name: str, check_exists=True) -> Path:

Get the full file path from the given file name.

Parameters
name:strThe file name without extension.
check_exists:boolif True, check if the generated path is a file
Returns
strThe full file path.
__extension: str =

Undocumented

__programs_dir: Path =

Undocumented