Karana.KUtils.FilesystemLikeDatabase#

Classes and functions related to Filesystem.

Classes#

FilesystemLikeDatabase

Filesystem-like database for storing objects and looking them up by filepath-like names.

Module Contents#

class Karana.KUtils.FilesystemLikeDatabase.FilesystemLikeDatabase[source]#

Filesystem-like database for storing objects and looking them up by filepath-like names.

graph#
root = '/'#
addObject(name: str, obj: T, parent: str, /)[source]#
addObject(obj: T, parent: str, /)
addObject(name: str, obj: T, parent: T, /)
addObject(obj: T, parent: T, /)

Add an object to the database.

  1. Using a name, object, and parent as a path.
    namestr

    The name of the object.

    objT

    The object itself.

    parentstr

    The parent as a path in the current database.

  2. Using an object with a name method and the parent as a path.
    objT

    The object itself. The object must implement a name() method that returns a string.

    parentstr

    The parent as a path in the current database.

  3. Using a name, an object, and the parent as an object.
    namestr

    The name of the object.

    objT

    The object itself.

    parentT

    The parent object, which must already be in the database.

  4. Using an object with a name method and the parent as an object.
    objT

    The object itself. The object must implement a name() method that returns a string.

    parentT

    The parent object, which must already be in the database.

getObjects(path: str, parent: T | None = None) list[T][source]#

Get objects in the database.

Parameters:
  • path (str) – The path to use to find objects.

  • parent (T | None) – The parent to start searching from. If None, then the root is used.

Returns:

A list of objects found.

Return type:

list[T]

getObject(path: str, parent: T | None = None) T[source]#

Get object in the database.

Parameters:
  • path (str) – The path to use to find the object.

  • parent (T | None) – The parent to start searching from. If None, then the root is used.

Returns:

The object that matches the path.

Return type:

T

getClosest(start: T, name: str) T[source]#

Get the closest object with the given name.

If more than one object has this name at the same closest distance, then an error is thrown.

Parameters:
  • start (T) – Where to start searching from.

  • name (str) – The name of the object to look for. This can use globs and wildcards.

Returns:

The closest object with that name.

Return type:

T

dumpTree(node: int | None = None, prefix: str = '', is_last: bool = True)[source]#

Display the database as a tree on the command line.

This is a recursive method that is meant to be called with the keyword arguments as their defaults.

Parameters:
  • node (int | None) – The node to dump from.

  • prefix (str) – The prefix to use when printing this nodes information.

  • is_last (bool) – If this is the last node at the current level.