From 46f7b545562dbe43c50200ca1b1836ba54644c1d Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Fri, 24 Apr 2020 10:40:14 -0700 Subject: [PATCH] Add get_all_lexicons --- amanuensis/lexicon/__init__.py | 6 +++++- amanuensis/lexicon/admin.py | 13 +++++++++++++ amanuensis/lexicon/manage.py | 15 --------------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/amanuensis/lexicon/__init__.py b/amanuensis/lexicon/__init__.py index d8a790e..a2e9f01 100644 --- a/amanuensis/lexicon/__init__.py +++ b/amanuensis/lexicon/__init__.py @@ -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, diff --git a/amanuensis/lexicon/admin.py b/amanuensis/lexicon/admin.py index 420733b..6ace199 100644 --- a/amanuensis/lexicon/admin.py +++ b/amanuensis/lexicon/admin.py @@ -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 diff --git a/amanuensis/lexicon/manage.py b/amanuensis/lexicon/manage.py index 6394838..b8673fa 100644 --- a/amanuensis/lexicon/manage.py +++ b/amanuensis/lexicon/manage.py @@ -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] -