Add get_all_cmdsets` helper inspired by work by user trhr in unmerged PR

This commit is contained in:
Griatch 2021-05-21 15:22:35 +02:00
parent 12a251cdcc
commit 73f73f2473
4 changed files with 73 additions and 8 deletions

View file

@ -2338,16 +2338,16 @@ def get_all_typeclasses(parent=None):
List available typeclasses from all available modules.
Args:
parent (str, optional): If given, only return typeclasses inheriting (at any distance)
from this parent.
parent (str, optional): If given, only return typeclasses inheriting
(at any distance) from this parent.
Returns:
dict: On the form `{"typeclass.path": typeclass, ...}`
Notes:
This will dynamically retrieve all abstract django models inheriting at any distance
from the TypedObject base (aka a Typeclass) so it will work fine with any custom
classes being added.
This will dynamically retrieve all abstract django models inheriting at
any distance from the TypedObject base (aka a Typeclass) so it will
work fine with any custom classes being added.
"""
from evennia.typeclasses.models import TypedObject
@ -2366,6 +2366,34 @@ def get_all_typeclasses(parent=None):
return typeclasses
def get_all_cmdsets(parent=None):
"""
List available cmdsets from all available modules.
Args:
parent (str, optional): If given, only return cmdsets inheriting (at
any distance) from this parent.
Returns:
dict: On the form {"cmdset.path": cmdset, ...}
Notes:
This will dynamically retrieve all abstract django models inheriting at
any distance from the CmdSet base so it will work fine with any custom
classes being added.
"""
from evennia.commands.cmdset import CmdSet
base_cmdset = class_from_module(parent) if parent else CmdSet
cmdsets = {
"{}.{}".format(subclass.__module__, subclass.__name__): subclass
for subclass in base_cmdset.__subclasses__()
}
return cmdsets
def interactive(func):
"""
Decorator to make a method pausable with `yield(seconds)`