file_path_manager module¶
Services for handling file paths.
Classes:
|
Create new instance of FileDefinition(name, extension) |
|
A factory of file paths for a given type of file and with default settings. |
|
The type of a file, defined by its default name and format. |
- class gemseo.utils.file_path_manager.FileDefinition(name, extension)¶
Bases:
tuple
Create new instance of FileDefinition(name, extension)
Methods:
count
(value, /)Return number of occurrences of value.
index
(value[, start, stop])Return first index of value.
Attributes:
Alias for field number 1
Alias for field number 0
- count(value, /)¶
Return number of occurrences of value.
- extension¶
Alias for field number 1
- index(value, start=0, stop=9223372036854775807, /)¶
Return first index of value.
Raises ValueError if the value is not present.
- name¶
Alias for field number 0
- class gemseo.utils.file_path_manager.FilePathManager(file_type, default_name=None, default_directory=None, default_extension=None)[source]¶
Bases:
object
A factory of file paths for a given type of file and with default settings.
- Parameters
file_type (FileType) – The type of file, defined by its default file name and format; select a file type by iterating over
FileType
.default_name (str) –
The default file name. If None, use the default file name related to the given type of file.
By default it is set to None.
default_directory (Optional[Path]) –
The default directory path. If None, use the current working directory.
By default it is set to None.
default_extension (Optional[str]) –
The default extension. If None, use the default extension related to the given type of file.
By default it is set to None.
- Return type
None
Methods:
add_suffix
(file_path, suffix)Add a suffix to an existing file path between the filename and the extension.
create_file_path
([file_path, ...])Make a file path from a directory path, a file name and a file extension.
to_snake_case
(message)Snake case a string.
- classmethod add_suffix(file_path, suffix)[source]¶
Add a suffix to an existing file path between the filename and the extension.
E.g. directory/filename_suffix.pdf.
- Parameters
file_path (pathlib.Path) – The file path to be suffixed.
suffix (str) – The suffix to be added to the file path.
- Returns
The directory path, the file name and the file extension obtained from the file path.
- Return type
pathlib.Path
- create_file_path(file_path=None, directory_path=None, file_name=None, file_extension=None)[source]¶
Make a file path from a directory path, a file name and a file extension.
- Parameters
file_path (Optional[Union[str, pathlib.Path]]) –
The path of the file to be returned. If None, create a file path from
directory_path
,file_name
andfile_extension
.By default it is set to None.
directory_path (Optional[Union[str, pathlib.Path]]) –
The path of the directory. If None, use the default directory path.
By default it is set to None.
file_name (Optional[str]) –
The file name to be used. If None, use the default file name.
By default it is set to None.
file_extension (Optional[str]) –
A file extension, e.g. ‘png’, ‘pdf’, ‘svg’, … If None, use the default file extension.
By default it is set to None.
- Returns
The file path.
- Return type
pathlib.Path
- class gemseo.utils.file_path_manager.FileType(value)[source]¶
Bases:
enum.Enum
The type of a file, defined by its default name and format.
Attributes:
- FIGURE = FileDefinition(name='figure', extension='png')¶
- SCHEMA = FileDefinition(name='schema', extension='json')¶
- TEXT = FileDefinition(name='document', extension='txt')¶
- WEBPAGE = FileDefinition(name='page', extension='html')¶