Anki/pylib/anki/importing/base.py
Abdo f94d05bcbe
Switch to Ruff (#4119)
* Add check:ruff build action

* Add fix:ruff action

* Add Ruff config

Mostly generated by Cursor

* Handle rest of lints

* Fix formatting

* Replace black and isort with ruff-format

* Run ruff-format

* Fix lint errors

* Remove pylint disables

* Remove .pylintrc

* Update docs

* Fix check:format not just checking

* Fix isort rule being ignored

* Sort imports

* Ensure ./ninja format also handles import sorting

* Remove unused isort cfg

* Enable unsafe fixes in fix:ruff, and enable unused var warning

* Re-run on config change; enable unnecessary ARG ignores

* Use all pycodestyle errors, and add some more commented-out ones

Latter logged on https://github.com/ankitects/anki/issues/4135
2025-06-29 14:38:35 +07:00

50 lines
1.3 KiB
Python

# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
from __future__ import annotations
from typing import Any
from anki.collection import Collection
from anki.utils import max_id
# Base importer
##########################################################################
class Importer:
needMapper = False
needDelimiter = False
dst: Collection | None
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 = max_id(self.dst.db)
def ts(self) -> Any:
self._ts += 1
return self._ts