update importer
This commit is contained in:
parent
3fe6baeeba
commit
5b673bdace
|
@ -3,7 +3,7 @@
|
|||
# License: GNU GPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
import json
|
||||
from typing import Any
|
||||
from typing import Any, Collection, Iterable
|
||||
|
||||
from .ankiconnect import invoke, request_model_names
|
||||
from .common import select, get_used_fonts, NoteType, CardTemplate
|
||||
|
@ -20,8 +20,8 @@ def read_card_templates(model_dir_name: str, template_names: list[str]) -> list[
|
|||
for template_name in template_names:
|
||||
dir_path = os.path.join(NOTE_TYPES_DIR, model_dir_name, template_name)
|
||||
with (
|
||||
open(os.path.join(dir_path, FRONT_FILENAME), encoding='utf8') as front,
|
||||
open(os.path.join(dir_path, BACK_FILENAME), encoding='utf8') as back
|
||||
open(os.path.join(dir_path, FRONT_FILENAME), encoding='utf8') as front,
|
||||
open(os.path.join(dir_path, BACK_FILENAME), encoding='utf8') as back
|
||||
):
|
||||
templates.append(CardTemplate(template_name, front.read(), back.read()))
|
||||
return templates
|
||||
|
@ -65,10 +65,16 @@ def send_note_type(model: NoteType):
|
|||
invoke("createModel", **template_json)
|
||||
|
||||
|
||||
def store_fonts(fonts: list[str]):
|
||||
def available_fonts(required_fonts: Collection[str]) -> Iterable[str]:
|
||||
""" Filter required fonts and leave only those available on disk. """
|
||||
for file in os.listdir(FONTS_DIR):
|
||||
if file in fonts:
|
||||
invoke("storeMediaFile", filename=file, path=os.path.join(FONTS_DIR, file))
|
||||
if file in required_fonts:
|
||||
yield file
|
||||
|
||||
|
||||
def store_fonts(fonts: list[str]):
|
||||
for file in available_fonts(fonts):
|
||||
invoke("storeMediaFile", filename=file, path=os.path.join(FONTS_DIR, file))
|
||||
|
||||
|
||||
def import_note_type():
|
||||
|
|
Loading…
Reference in a new issue