opihiexarata.library.path module
This module is just functions to deal with different common pathname manipulations. As Exarata is going to be cross platform, this is a nice abstraction.
- opihiexarata.library.path.get_directory(pathname: str) str [source]
Get the directory from the pathname without the file or the extension.
- Parameters:
pathname (string) – The pathname which the directory will be extracted.
- Returns:
directory – The directory which belongs to the pathname.
- Return type:
string
- opihiexarata.library.path.get_file_extension(pathname: str) str [source]
Get the file extension only from the pathname.
- Parameters:
pathname (string) – The pathname which the file extension will be extracted.
- Returns:
extension – The file extension only.
- Return type:
string
- opihiexarata.library.path.get_filename_with_extension(pathname: str) str [source]
Get the filename from the pathname with the file extension.
- Parameters:
pathname (string) – The pathname which the filename will be extracted.
- Returns:
filename – The filename with the file extension.
- Return type:
string
- opihiexarata.library.path.get_filename_without_extension(pathname: str) str [source]
Get the filename from the pathname without the file extension.
- Parameters:
pathname (string) – The pathname which the filename will be extracted.
- Returns:
filename – The filename without the file extension.
- Return type:
string
- opihiexarata.library.path.get_most_recent_filename_in_directory(directory: str, extension: str | list = None, recursive: bool = False, recency_function: Callable[[str], float] = None, exclude_opihiexarata_output_files: bool = False) str [source]
This gets the most recent filename from a directory.
Because of issues with different operating systems having differing issues with storing the creation time of a file, this function sorts based off of modification time.
- Parameters:
directory (string) – The directory by which the most recent file will be derived from.
extension (string or list, default = None) – The extension by which to filter for. It is often the case that some files are created but the most recent file of some type is desired. Only files which match the included extensions will be considered.
recursive (bool, default = False) – If True, the directory is searched recursively for the most recent file based on the recency function.
recency_function (callable, default = None) – A function which, when provided, provides a sorting index for a given filename. This is used when the default sorting method (modification time) is not desired and a custom function can be provided here. The larger the value returned by this function, the more “recent” a given file will be considered to be.
exclude_opihiexarata_output_files (boolean, default = False) – If True, files which have been marked as being outputs of OpihiExarata (via the file suffixes as per the configuration file) will not be included.
- Returns:
recent_filename – The filename of the most recent file, by modification time, in the directory.
- Return type:
string
- opihiexarata.library.path.merge_pathname(directory: str | list = None, filename: str = None, extension: str = None) str [source]
Joins directories, filenames, and file extensions into one pathname.
- Parameters:
directory (string or list, default = None) – The directory(s) which is going to be used. If it is a list, then the paths within it are combined.
filename (string, default = None) – The filename that is going to be used for path construction.
extension (string, default = None) – The filename extension that is going to be used.
- Returns:
pathname – The combined pathname.
- Return type:
string
- opihiexarata.library.path.split_pathname(pathname: str) tuple[str, str, str] [source]
Splits a path into a directory, filename, and file extension.
This is a wrapper function around the more elementry functions get_directory, get_filename_without_extension, and get_file_extension.
- Parameters:
pathname (string) – The combined pathname which to be split.
- Returns:
directory (string) – The directory which was split from the pathname.
filename (string) – The filename which was split from the pathname.
extension (string) – The filename extension which was split from the pathname.