Karana.KUtils.FilesystemLikeDatabase
====================================

.. py:module:: Karana.KUtils.FilesystemLikeDatabase

.. autoapi-nested-parse::

   Classes and functions related to Filesystem.



Classes
-------

.. autoapisummary::

   Karana.KUtils.FilesystemLikeDatabase.FilesystemLikeDatabase


Module Contents
---------------

.. py:class:: FilesystemLikeDatabase[T]

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


   .. py:attribute:: graph


   .. py:attribute:: root
      :value: '/'



   .. py:method:: addObject(name: str, obj: T, parent: str, /)
                  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.

      :param name: The name of the object.
      :type name: str
      :param obj: The object itself.
      :type obj: T
      :param parent: The parent as a path in the current database.
      :type parent: str

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

      :param obj: The object itself. The object must implement a name() method that
                  returns a string.
      :type obj: T
      :param parent: The parent as a path in the current database.
      :type parent: str

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

      :param name: The name of the object.
      :type name: str
      :param obj: The object itself.
      :type obj: T
      :param parent: The parent object, which must already be in the database.
      :type parent: T

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

      :param obj: The object itself. The object must implement a name() method that
                  returns a string.
      :type obj: T
      :param parent: The parent object, which must already be in the database.
      :type parent: T



   .. py:method:: getObjects(path: str, parent: T | None = None) -> list[T]

      Get objects in the database.

      :param path: The path to use to find objects.
      :type path: str
      :param parent: The parent to start searching from. If None, then the root is used.
      :type parent: T | None

      :returns: A list of objects found.
      :rtype: list[T]



   .. py:method:: getObject(path: str, parent: T | None = None) -> T

      Get object in the database.

      :param path: The path to use to find the object.
      :type path: str
      :param parent: The parent to start searching from. If None, then the root is used.
      :type parent: T | None

      :returns: The object that matches the path.
      :rtype: T



   .. py:method:: getObjectsAndDists(path: str, parent: T | None = None) -> list[tuple[T, int]]

      Get objects and their distance in the Database.

      :param path: The path used to search for objects.
      :type path: str
      :param parent: The point in the FilesystemLikeDatabase to start searching from.
                     If None, then the root is used.
      :type parent: T | None

      :returns: A list of objects that match the path and their distances.
      :rtype: list[tuple[T, int]]



   .. py:method:: getClosest(name: str, start: T | None = None) -> T

      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.

      :param name: The name of the object to look for. This can use globs and wildcards.
      :type name: str
      :param start: The point in the FilesystemLikeDatabase to start searching from.
                    If None, then the root is used.
      :type start: T

      :returns: The closest object with that name.
      :rtype: T



   .. py:method:: dumpTree(node: int | None = None, prefix: str = '', is_last: bool = True)

      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.

      :param node: The node to dump from.
      :type node: int | None
      :param prefix: The prefix to use when printing this nodes information.
      :type prefix: str
      :param is_last: If this is the last node at the current level.
      :type is_last: bool



