Add get_all_lexicons

This commit is contained in:
Tim Van Baak 2020-04-24 10:40:14 -07:00
parent 081a54c9c3
commit 46f7b54556
3 changed files with 18 additions and 16 deletions

View File

@ -1,4 +1,7 @@
from amanuensis.lexicon.admin import valid_name, create_lexicon
from amanuensis.lexicon.admin import (
valid_name,
create_lexicon,
load_all_lexicons)
from amanuensis.lexicon.gameloop import attempt_publish
from amanuensis.lexicon.setup import (
player_can_join_lexicon,
@ -8,6 +11,7 @@ from amanuensis.lexicon.setup import (
__all__ = [member.__name__ for member in [
valid_name,
create_lexicon,
load_all_lexicons,
attempt_publish,
player_can_join_lexicon,
add_player_to_lexicon,

View File

@ -7,6 +7,7 @@ import logging
import os
import re
import time
from typing import Iterable
import uuid
from amanuensis.config import RootConfigDirectoryContext, AttrOrderedDict
@ -89,3 +90,15 @@ def create_lexicon(
logger.info(message)
return lexicon
def load_all_lexicons(
root: RootConfigDirectoryContext) -> Iterable[LexiconModel]:
"""
Iterably loads every lexicon in the config store
"""
model_factory: ModelFactory = ModelFactory(root)
with root.lexicon.read_index() as index:
for lid in index.values():
lexicon: LexiconModel = model_factory.lexicon(lid)
yield lexicon

View File

@ -44,20 +44,6 @@ def delete_lexicon(lex, purge=False):
shutil.rmtree(lex_path)
def get_all_lexicons():
"""
Loads each lexicon in the lexicon index
"""
# Get all the lexicon ids in the index
with json_ro('lexicon', 'index.json') as index:
lids = list(index.values())
# Load all of the lexicons
lexes = list(map(lambda id: LexiconModel.by(lid=id), lids))
return lexes
def get_user_lexicons(user):
"""
Loads each lexicon that the given user is a player in
@ -111,4 +97,3 @@ def delete_character(lex, charname):
# Remove character from character list
with json_rw(lex.config_path) as cfg:
del cfg.character[char.cid]