lezargus.library.path module#

Functions to deal with different common pathname manipulations.

As Lezargus is going to be cross platform, this is a nice abstraction.

lezargus.library.path.get_directory(pathname: str) str[source]#

Get the directory from the pathname without the file or the extension.

Parameters:

pathname (str) – The pathname which the directory will be extracted.

Returns:

directory – The directory which belongs to the pathname.

Return type:

str

lezargus.library.path.get_file_extension(pathname: str) str[source]#

Get the file extension only from the pathname.

Parameters:

pathname (str) – The pathname which the file extension will be extracted.

Returns:

extension – The file extension only.

Return type:

str

lezargus.library.path.get_filename_with_extension(pathname: str) str[source]#

Get the filename from the pathname with the file extension.

Parameters:

pathname (str) – The pathname which the filename will be extracted.

Returns:

filename – The filename with the file extension.

Return type:

str

lezargus.library.path.get_filename_without_extension(pathname: str) str[source]#

Get the filename from the pathname without the file extension.

Parameters:

pathname (str) – The pathname which the filename will be extracted.

Returns:

filename – The filename without the file extension.

Return type:

str

lezargus.library.path.get_most_recent_filename_in_directory(directory: str, basename: str | list | None = None, extension: str | list | None = None, recursive: bool = False, recency_function: Callable[[str], float] = None) str | None[source]#

Get 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 unless a custom function is provided.

Parameters:
  • directory (str or list) – The directory by which the most recent file will be derived from.

  • basename (str or list, default = None) – The basename filter which we will use to weed out the files. Wildcard expansion is supported. A list may be provided to cover multiple cases to include. If not provided, we default to all files.

  • extension (str 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.

Returns:

recent_filename – The filename of the most recent file, by modification time, in the directory. If no recent file is found, we return None.

Return type:

str

lezargus.library.path.merge_pathname(directory: str | list = None, filename: str | None = None, extension: str | None = None) str[source]#

Join the directories, filenames, and file extensions into one pathname.

Parameters:
  • directory (str 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 (str, default = None) – The filename that is going to be used for path construction.

  • extension (str, default = None) – The filename extension that is going to be used.

Returns:

pathname – The combined pathname.

Return type:

str

lezargus.library.path.split_pathname(pathname: str) tuple[str, str, str][source]#

Return a pathname split into its components.

This is a wrapper function around the more elementary functions get_directory, get_filename_without_extension, and get_file_extension.

Parameters:

pathname (str) – The combined pathname which to be split.

Returns:

  • directory (str) – The directory which was split from the pathname.

  • filename (str) – The filename which was split from the pathname.

  • extension (str) – The filename extension which was split from the pathname.