Karana.KUtils.FilesystemLikeDatabase#
Classes and functions related to Filesystem.
Classes#
Filesystem-like database for storing objects and looking them up by filepath-like names. |
Module Contents#
- class Karana.KUtils.FilesystemLikeDatabase.FilesystemLikeDatabase[T][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.
Using a name, object, and parent as a path.
- Parameters:
Using an object with a name method and the parent as a path.
- Parameters:
obj (T) – The object itself. The object must implement a name() method that returns a string.
parent (str) – The parent as a path in the current database.
Using a name, an object, and the parent as an object.
- Parameters:
name (str) – The name of the object.
obj (T) – The object itself.
parent (T) – The parent object, which must already be in the database.
Using an object with a name method and the parent as an object.
- Parameters:
obj (T) – The object itself. The object must implement a name() method that returns a string.
parent (T) – The parent object, which must already be in the database.
- 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
- getObjectsAndDists(path: str, parent: T | None = None) list[tuple[T, int]][source]#
Get objects and their distance in the Database.
- getClosest(name: str, start: T | None = None) 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:
name (str) – The name of the object to look for. This can use globs and wildcards.
start (T) – The point in the FilesystemLikeDatabase to start searching from. If None, then the root is used.
- Returns:
The closest object with that name.
- Return type:
T