mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00

This adds Python 3.9 and 3.10 typing syntax to files that import attributions from __future___. Python 3.9 should be able to cope with the 3.10 syntax, but Python 3.8 will no longer work. On Windows/Mac, install the latest Python 3.9 version from python.org. There are currently no orjson wheels for Python 3.10 on Windows/Mac, which will break the build unless you have Rust installed separately. On Linux, modern distros should have Python 3.9 available already. If you're on an older distro, you'll need to build Python from source first.
48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
# Copyright: Ankitects Pty Ltd and contributors
|
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
from typing import Any, Optional
|
|
|
|
from anki.collection import Collection
|
|
from anki.utils import maxID
|
|
|
|
# Base importer
|
|
##########################################################################
|
|
|
|
|
|
class Importer:
|
|
|
|
needMapper = False
|
|
needDelimiter = False
|
|
dst: Optional[Collection]
|
|
|
|
def __init__(self, col: Collection, file: str) -> None:
|
|
self.file = file
|
|
self.log: list[str] = []
|
|
self.col = col.weakref()
|
|
self.total = 0
|
|
self.dst = None
|
|
|
|
def run(self) -> None:
|
|
pass
|
|
|
|
def open(self) -> None:
|
|
"Open file and ensure it's in the right format."
|
|
return
|
|
|
|
def close(self) -> None:
|
|
"Closes the open file."
|
|
return
|
|
|
|
# Timestamps
|
|
######################################################################
|
|
# It's too inefficient to check for existing ids on every object,
|
|
# and a previous import may have created timestamps in the future, so we
|
|
# need to make sure our starting point is safe.
|
|
|
|
def _prepareTS(self) -> None:
|
|
self._ts = maxID(self.dst.db)
|
|
|
|
def ts(self) -> Any:
|
|
self._ts += 1
|
|
return self._ts
|