mypy pass
This commit is contained in:
parent
5872fdcc64
commit
ca98afb66d
|
@ -126,10 +126,10 @@ def content_constraint_analysis(
|
||||||
infos: list = []
|
infos: list = []
|
||||||
warnings: list = []
|
warnings: list = []
|
||||||
errors: list = []
|
errors: list = []
|
||||||
character = lexicon.cfg.character.get(cid)
|
character = lexicon.cfg.character.get(cid)# noqa
|
||||||
content_analysis: ConstraintAnalysis = (
|
content_analysis: ConstraintAnalysis = (
|
||||||
parsed.render(ConstraintAnalysis(lexicon)))
|
parsed.render(ConstraintAnalysis(lexicon)))
|
||||||
with lexicon.ctx.read('info') as info:
|
with lexicon.ctx.read('info') as info:# noqa
|
||||||
# I: Word count
|
# I: Word count
|
||||||
infos.append(f'Word count: {content_analysis.word_count}')
|
infos.append(f'Word count: {content_analysis.word_count}')
|
||||||
# Self-citation when forbidden
|
# Self-citation when forbidden
|
||||||
|
|
|
@ -1,99 +1,99 @@
|
||||||
"""
|
# """
|
||||||
Functions for managing lexicons, primarily within the context of the
|
# Functions for managing lexicons, primarily within the context of the
|
||||||
Amanuensis config directory.
|
# Amanuensis config directory.
|
||||||
"""
|
# """
|
||||||
import json
|
# import json
|
||||||
import os
|
# import os
|
||||||
import re
|
# import re
|
||||||
import shutil
|
# import shutil
|
||||||
import time
|
# import time
|
||||||
import uuid
|
# import uuid
|
||||||
|
|
||||||
from amanuensis.config import prepend, json_rw, json_ro, logger
|
# from amanuensis.config import prepend, json_rw, json_ro, logger
|
||||||
from amanuensis.config.loader import AttrOrderedDict
|
# from amanuensis.config.loader import AttrOrderedDict
|
||||||
from amanuensis.errors import ArgumentError
|
# from amanuensis.errors import ArgumentError
|
||||||
from amanuensis.lexicon import LexiconModel
|
# from amanuensis.lexicon import LexiconModel
|
||||||
from amanuensis.parser import parse_raw_markdown, GetCitations, HtmlRenderer, filesafe_title, titlesort
|
# from amanuensis.parser import parse_raw_markdown, GetCitations, HtmlRenderer, filesafe_title, titlesort
|
||||||
from amanuensis.resources import get_stream
|
# from amanuensis.resources import get_stream
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def delete_lexicon(lex, purge=False):
|
# def delete_lexicon(lex, purge=False):
|
||||||
"""
|
# """
|
||||||
Deletes the given lexicon from the internal configuration
|
# Deletes the given lexicon from the internal configuration
|
||||||
|
|
||||||
Does not delete the lexicon from the data folder unless purge=True.
|
# Does not delete the lexicon from the data folder unless purge=True.
|
||||||
"""
|
# """
|
||||||
# Verify arguments
|
# # Verify arguments
|
||||||
if lex is None:
|
# if lex is None:
|
||||||
raise ArgumentError("Invalid lexicon: '{}'".format(lex))
|
# raise ArgumentError("Invalid lexicon: '{}'".format(lex))
|
||||||
|
|
||||||
# Delete the lexicon from the index
|
# # Delete the lexicon from the index
|
||||||
with json_rw('lexicon', 'index.json') as index:
|
# with json_rw('lexicon', 'index.json') as index:
|
||||||
if lex.name in index:
|
# if lex.name in index:
|
||||||
del index[lex.name]
|
# del index[lex.name]
|
||||||
|
|
||||||
# Delete the lexicon data folder if purging
|
# # Delete the lexicon data folder if purging
|
||||||
if purge:
|
# if purge:
|
||||||
raise NotImplementedError()
|
# raise NotImplementedError()
|
||||||
|
|
||||||
# Delete the lexicon config
|
# # Delete the lexicon config
|
||||||
lex_path = prepend('lexicon', lex.id)
|
# lex_path = prepend('lexicon', lex.id)
|
||||||
shutil.rmtree(lex_path)
|
# shutil.rmtree(lex_path)
|
||||||
|
|
||||||
|
|
||||||
def get_user_lexicons(user):
|
# def get_user_lexicons(user):
|
||||||
"""
|
# """
|
||||||
Loads each lexicon that the given user is a player in
|
# Loads each lexicon that the given user is a player in
|
||||||
"""
|
# """
|
||||||
return [
|
# return [
|
||||||
lexicon
|
# lexicon
|
||||||
for lexicon in get_all_lexicons()
|
# for lexicon in get_all_lexicons()
|
||||||
if user.in_lexicon(lexicon)]
|
# if user.in_lexicon(lexicon)]
|
||||||
|
|
||||||
|
|
||||||
def remove_player(lex, player):
|
# def remove_player(lex, player):
|
||||||
"""
|
# """
|
||||||
Remove a player from a lexicon
|
# Remove a player from a lexicon
|
||||||
"""
|
# """
|
||||||
# Verify arguments
|
# # Verify arguments
|
||||||
if lex is None:
|
# if lex is None:
|
||||||
raise ArgumentError("Invalid lexicon: '{}'".format(lex))
|
# raise ArgumentError("Invalid lexicon: '{}'".format(lex))
|
||||||
if player is None:
|
# if player is None:
|
||||||
raise ArgumentError("Invalid player: '{}'".format(player))
|
# raise ArgumentError("Invalid player: '{}'".format(player))
|
||||||
if lex.editor == player.id:
|
# if lex.editor == player.id:
|
||||||
raise ArgumentError(
|
# raise ArgumentError(
|
||||||
"Can't remove the editor '{}' from lexicon '{}'".format(
|
# "Can't remove the editor '{}' from lexicon '{}'".format(
|
||||||
player.username, lex.name))
|
# player.username, lex.name))
|
||||||
|
|
||||||
# Idempotently remove player
|
# # Idempotently remove player
|
||||||
with json_rw(lex.config_path) as cfg:
|
# with json_rw(lex.config_path) as cfg:
|
||||||
if player.id in cfg.join.joined:
|
# if player.id in cfg.join.joined:
|
||||||
cfg.join.joined.remove(player.id)
|
# cfg.join.joined.remove(player.id)
|
||||||
|
|
||||||
# TODO Reassign the player's characters to the editor
|
# # TODO Reassign the player's characters to the editor
|
||||||
|
|
||||||
|
|
||||||
def delete_character(lex, charname):
|
# def delete_character(lex, charname):
|
||||||
"""
|
# """
|
||||||
Delete a character from a lexicon
|
# Delete a character from a lexicon
|
||||||
"""
|
# """
|
||||||
# Verify arguments
|
# # Verify arguments
|
||||||
if lex is None:
|
# if lex is None:
|
||||||
raise ArgumentError("Invalid lexicon: '{}'".format(lex))
|
# raise ArgumentError("Invalid lexicon: '{}'".format(lex))
|
||||||
if charname is None:
|
# if charname is None:
|
||||||
raise ArgumentError("Invalid character name: '{}'".format(charname))
|
# raise ArgumentError("Invalid character name: '{}'".format(charname))
|
||||||
|
|
||||||
# Find character in this lexicon
|
# # Find character in this lexicon
|
||||||
matches = [
|
# matches = [
|
||||||
char for cid, char in lex.character.items()
|
# char for cid, char in lex.character.items()
|
||||||
if char.name == charname]
|
# if char.name == charname]
|
||||||
if len(matches) != 1:
|
# if len(matches) != 1:
|
||||||
raise ArgumentError(matches)
|
# raise ArgumentError(matches)
|
||||||
char = matches[0]
|
# char = matches[0]
|
||||||
|
|
||||||
# Remove character from character list
|
# # Remove character from character list
|
||||||
with json_rw(lex.config_path) as cfg:
|
# with json_rw(lex.config_path) as cfg:
|
||||||
del cfg.character[char.cid]
|
# del cfg.character[char.cid]
|
||||||
|
|
Loading…
Reference in New Issue