mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Added __repr__ functions to common objects
This commit is contained in:
parent
9594a3ef9b
commit
1e216e47ed
8 changed files with 48 additions and 0 deletions
|
@ -64,6 +64,12 @@ class Collection:
|
||||||
self.conf = ConfigManager(self)
|
self.conf = ConfigManager(self)
|
||||||
self._loadScheduler()
|
self._loadScheduler()
|
||||||
|
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
d = dict(self.__dict__)
|
||||||
|
del d["models"]
|
||||||
|
del d["backend"]
|
||||||
|
return pprint.pformat(d, width=300)
|
||||||
|
|
||||||
def name(self) -> Any:
|
def name(self) -> Any:
|
||||||
n = os.path.splitext(os.path.basename(self.path))[0]
|
n = os.path.splitext(os.path.basename(self.path))[0]
|
||||||
return n
|
return n
|
||||||
|
|
|
@ -10,6 +10,7 @@ of add-ons rely on it.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import pprint
|
||||||
import time
|
import time
|
||||||
from sqlite3 import Cursor
|
from sqlite3 import Cursor
|
||||||
from sqlite3 import dbapi2 as sqlite
|
from sqlite3 import dbapi2 as sqlite
|
||||||
|
@ -26,6 +27,11 @@ class DB:
|
||||||
self.echo = os.environ.get("DBECHO")
|
self.echo = os.environ.get("DBECHO")
|
||||||
self.mod = False
|
self.mod = False
|
||||||
|
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
d = dict(self.__dict__)
|
||||||
|
del d["_db"]
|
||||||
|
return pprint.pformat(d, width=300)
|
||||||
|
|
||||||
def execute(self, sql: str, *a, **ka) -> Cursor:
|
def execute(self, sql: str, *a, **ka) -> Cursor:
|
||||||
s = sql.strip().lower()
|
s = sql.strip().lower()
|
||||||
# mark modified?
|
# mark modified?
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
import pprint
|
||||||
from typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple, Union
|
from typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple, Union
|
||||||
|
|
||||||
import anki # pylint: disable=unused-import
|
import anki # pylint: disable=unused-import
|
||||||
|
@ -80,6 +81,11 @@ class DeckManager:
|
||||||
def flush(self):
|
def flush(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
d = dict(self.__dict__)
|
||||||
|
del d["col"]
|
||||||
|
return pprint.pformat(d, width=300)
|
||||||
|
|
||||||
# Deck save/load
|
# Deck save/load
|
||||||
#############################################################
|
#############################################################
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import pprint
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
@ -60,6 +61,11 @@ class MediaManager:
|
||||||
except OSError:
|
except OSError:
|
||||||
raise Exception("invalidTempFolder")
|
raise Exception("invalidTempFolder")
|
||||||
|
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
d = dict(self.__dict__)
|
||||||
|
del d["col"]
|
||||||
|
return pprint.pformat(d, width=300)
|
||||||
|
|
||||||
def connect(self) -> None:
|
def connect(self) -> None:
|
||||||
if self.col.server:
|
if self.col.server:
|
||||||
return
|
return
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
import pprint
|
||||||
import time
|
import time
|
||||||
from typing import Any, Dict, List, Optional, Sequence, Tuple, Union
|
from typing import Any, Dict, List, Optional, Sequence, Tuple, Union
|
||||||
|
|
||||||
|
@ -66,6 +67,11 @@ class ModelManager:
|
||||||
# do not access this directly!
|
# do not access this directly!
|
||||||
self._cache = {}
|
self._cache = {}
|
||||||
|
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
d = dict(self.__dict__)
|
||||||
|
del d["col"]
|
||||||
|
return pprint.pformat(d, width=300)
|
||||||
|
|
||||||
def save(
|
def save(
|
||||||
self,
|
self,
|
||||||
m: NoteType = None,
|
m: NoteType = None,
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import pprint
|
||||||
from typing import Any, List, Optional, Sequence, Tuple
|
from typing import Any, List, Optional, Sequence, Tuple
|
||||||
|
|
||||||
import anki # pylint: disable=unused-import
|
import anki # pylint: disable=unused-import
|
||||||
|
@ -66,6 +67,11 @@ class Note:
|
||||||
assert self.id != 0
|
assert self.id != 0
|
||||||
self.col.backend.update_note(self.to_backend_note())
|
self.col.backend.update_note(self.to_backend_note())
|
||||||
|
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
d = dict(self.__dict__)
|
||||||
|
del d["col"]
|
||||||
|
return pprint.pformat(d, width=300)
|
||||||
|
|
||||||
def joinedFields(self) -> str:
|
def joinedFields(self) -> str:
|
||||||
return joinFields(self.fields)
|
return joinFields(self.fields)
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import pprint
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
from heapq import *
|
from heapq import *
|
||||||
|
@ -42,6 +43,11 @@ class Scheduler:
|
||||||
self._lrnCutoff = 0
|
self._lrnCutoff = 0
|
||||||
self._updateCutoff()
|
self._updateCutoff()
|
||||||
|
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
d = dict(self.__dict__)
|
||||||
|
del d["col"]
|
||||||
|
return pprint.pformat(d, width=300)
|
||||||
|
|
||||||
def getCard(self) -> Optional[Card]:
|
def getCard(self) -> Optional[Card]:
|
||||||
"""Pop the next card from the queue. None if finished."""
|
"""Pop the next card from the queue. None if finished."""
|
||||||
self._checkDay()
|
self._checkDay()
|
||||||
|
|
|
@ -11,6 +11,7 @@ This module manages the tag cache and tags for notes.
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import pprint
|
||||||
import re
|
import re
|
||||||
from typing import Collection, List, Optional, Tuple
|
from typing import Collection, List, Optional, Tuple
|
||||||
|
|
||||||
|
@ -26,6 +27,11 @@ class TagManager:
|
||||||
def all(self) -> List[str]:
|
def all(self) -> List[str]:
|
||||||
return [t.tag for t in self.col.backend.all_tags()]
|
return [t.tag for t in self.col.backend.all_tags()]
|
||||||
|
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
d = dict(self.__dict__)
|
||||||
|
del d["col"]
|
||||||
|
return pprint.pformat(d, width=300)
|
||||||
|
|
||||||
# # List of (tag, usn)
|
# # List of (tag, usn)
|
||||||
def allItems(self) -> List[Tuple[str, int]]:
|
def allItems(self) -> List[Tuple[str, int]]:
|
||||||
return [(t.tag, t.usn) for t in self.col.backend.all_tags()]
|
return [(t.tag, t.usn) for t in self.col.backend.all_tags()]
|
||||||
|
|
Loading…
Reference in a new issue